Decode the protobuf wire format in Gleam!
3

Configure Feed

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

Update readme for new api

Gavin Morrow (Sep 29, 2025, 3:22 PM EDT) 98b13131 5dda1121

+11 -11
+11 -11
README.md
··· 8 8 email is on my github profile). 9 9 10 10 Also, there is currently no support for encoding the protobuf wire format. 11 - <!-- 11 + 12 + 12 13 [![Package Version](https://img.shields.io/hexpm/v/protobin)](https://hex.pm/packages/protobin) 13 14 [![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/protobin/) 14 15 ··· 16 17 ```sh 17 18 gleam add protobin@1 18 19 ``` 19 - --> 20 + 20 21 ```gleam 21 - import protobin.{parse, read_varint} 22 - import protobin/decoders 22 + import protobin 23 23 24 24 import gleam/option 25 25 26 26 type Person { 27 27 Person( 28 28 id: Int, 29 + name: String, 29 30 age: option.Option(Int), 30 31 score: Int, 31 32 fav_nums: List(Int), ··· 33 34 } 34 35 35 36 fn person_decoder() -> Decoder(Person) { 36 - use id <- decode.field(3, decoders.fixed(64)) 37 + use id <- decode.field(3, protobin.decode_fixed(64)) 37 38 use age <- decode.optional_field( 38 39 1, 39 40 option.None, 40 - decode.optional(decoders.uint()), 41 + decode.optional(protobin.decode_uint()), 41 42 ) 42 - use score <- decode.field(2, decoders.uint()) 43 + use score <- decode.field(2, protobin.decode_uint()) 43 44 use fav_nums <- decode.field( 44 45 42, 45 - decoders.multiple(of: decoders.uint(), using: read_varint), 46 + decoders.multiple(of: protobin.decode_uint(), using: protobin.read_varint), 46 47 ) 47 48 48 49 Person(id:, age:, score:) |> decode.success ··· 53 54 54 55 let assert Ok(bits) = file.read_bits(from: path) 55 56 let assert Ok(Parsed(value: person, rest: <<>>, pos: _)) = 56 - parse(from: bits, using: person_decoder()) 57 + protobin.parse(from: bits, using: person_decoder()) 57 58 58 59 assert person 59 60 == Person( 60 61 id: 42, 62 + name: "Aria", 61 63 age: option.Some(150), 62 64 score: 81_050, 63 65 ) 64 66 } 65 67 ``` 66 68 67 - <!-- 68 69 Further documentation can be found at <https://hexdocs.pm/protobin>. 69 - --> 70 70 71 71 ## Development 72 72