Decode the protobuf wire format in Gleam!
3

Configure Feed

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

Update example in readme

authored by

Gavin Morrow and committed by
GitHub
(Sep 29, 2025, 6:58 AM EDT) 4fcda1e3 ab12dad7

+16 -6
+16 -6
README.md
··· 18 18 ``` 19 19 --> 20 20 ```gleam 21 - import protobuf_decode_gleam 22 - import option 21 + import protobuf_decode_gleam.{parse, read_varint} 22 + import protobuf_decode_gleam/decoders 23 + 24 + import gleam/option 23 25 24 26 type Person { 25 - Person(id: Int, age: option.Option(Int), score: Int) 27 + Person( 28 + id: Int, 29 + age: option.Option(Int), 30 + score: Int, 31 + fav_nums: List(Int), 32 + ) 26 33 } 27 34 28 35 fn person_decoder() -> Decoder(Person) { ··· 33 40 decode.optional(decoders.uint()), 34 41 ) 35 42 use score <- decode.field(2, decoders.uint()) 43 + use fav_nums <- decode.field( 44 + 42, 45 + decoders.multiple(of: decoders.uint(), using: read_varint), 46 + ) 36 47 37 48 Person(id:, age:, score:) |> decode.success 38 49 } 39 50 40 51 pub fn main() -> Nil { 41 - // See the tests as well, they have decent examples. 42 52 let path = "./path/to/person.pb" 43 53 44 54 let assert Ok(bits) = file.read_bits(from: path) ··· 48 58 assert person 49 59 == Person( 50 60 id: 42, 51 - age: 150, 52 - score: option.Some(81_050), 61 + age: option.Some(150), 62 + score: 81_050, 53 63 ) 54 64 } 55 65 ```