Decode the protobuf wire format in Gleam! protobin.hexdocs.pm/
gleam protobuf
3

Configure Feed

Select the types of activity you want to include in your feed.

Test decoding fixed packed fields

Gavin Morrow (Sep 29, 2025, 6:47 AM EDT) 76b32cea efa36941

+23 -5
test/packed-fields.pb

This is a binary file and will not be displayed.

+6
test/packed-fields.protoscope.txt
··· 4 4 4: 4 5 5 4: 5 6 6 4: 6 7 + 8 + 11: 256i32 9 + 11: { 22i32 42i32 101i32 } 10 + 11: 4294967295i32 11 + 11: 0i32 12 + 11: 1i32
+17 -5
test/protobuf_decode_gleam_test.gleam
··· 4 4 import simplifile as file 5 5 6 6 import decoders 7 - import protobuf_decode_gleam.{Parsed, read_varint, parse} 7 + import protobuf_decode_gleam.{Parsed, parse, read_fixed, read_varint} 8 8 9 9 pub fn main() -> Nil { 10 10 gleeunit.main() ··· 191 191 } 192 192 193 193 type PackedFields { 194 - PackedFields(packed: List(Int), expanded: List(Int)) 194 + PackedFields( 195 + packed: List(Int), 196 + expanded: List(Int), 197 + mixed_packed_and_expanded: List(Int), 198 + ) 195 199 } 196 200 197 201 fn packed_fields_decoder() -> Decoder(PackedFields) { ··· 203 207 4, 204 208 decoders.multiple(of: decoders.uint(), using: read_varint), 205 209 ) 206 - PackedFields(packed:, expanded:) |> decode.success 210 + use mixed_packed_and_expanded <- decode.field( 211 + 11, 212 + decoders.multiple(of: decoders.fixed(32), using: read_fixed(32)), 213 + ) 214 + PackedFields(packed:, expanded:, mixed_packed_and_expanded:) |> decode.success 207 215 } 208 216 209 217 pub fn packed_fields_test() { ··· 214 222 215 223 assert packed_fields 216 224 == Parsed( 217 - value: PackedFields(packed: [0, 1, 2, 3], expanded: [4, 5, 6]), 225 + value: PackedFields( 226 + packed: [0, 1, 2, 3], 227 + expanded: [4, 5, 6], 228 + mixed_packed_and_expanded: [256, 22, 42, 101, 4_294_967_295, 0, 1], 229 + ), 218 230 rest: <<>>, 219 - pos: 14, 231 + pos: 48, 220 232 ) 221 233 }