Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
WASM
Zig
Javascript
GIMPLE
Ygen
zig source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
zig 0.10.0
zig 0.11.0
zig 0.12.0
zig 0.12.1
zig 0.13.0
zig 0.2.0
zig 0.3.0
zig 0.4.0
zig 0.5.0
zig 0.6.0
zig 0.7.0
zig 0.7.1
zig 0.8.0
zig 0.9.0
zig trunk
Options
Source code
const std = @import("std"); const Allocator = std.mem.Allocator; const AMP_KEY_LIMIT: usize = 0xff; const ParseState = enum { KeyLenRead, KeyDataRead, ValueLenRead, ValueDataRead }; const ParseError = enum { KeyTooLong, EmptyKey, ValueTooLong, Unsupported, }; const AmpBox = struct { //items: map }; const AmpDecoder = struct { pub var state: ParseState; pub var box_buffer: std.fifo.LinearFifo(AmpBox, .Dynamic); pub fn new(allocator: *Allocator) AmpDecoder { return AmpDecoder { .box_buffer = std.fifo.LinearFifo(AmpBox, .Dynamic).init(allocator), .state = ParseState.KeyLenRead}; } // pipe data in chunks, and receive boxes. pipe empty array in to // flush final boxes out, if any. pub fn decode_box(self: AmpDecoder, bytes: [*]u8, size: usize) !AmpBox { if (size == 0) { if (self.box_buffer) { return self.box_buffer.pop(); } } const slice: []u8 = ptr[0..size]; switch (self.state) { } return AmpBox {}; //return ParseError.KeyTooLong } }; pub fn main() void { const alloc = std.heap.page_allocator; var a = AmpDecoder.new(alloc); try a.decode_box(@intToPtr([*]u8, 1), 0); //a.decode_box(); //a.decode_box(); }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree