acrostic
A pure Gleam implementation of Google Protobuf.
Note:
-
only support proto3
-
only support enum, message, repeated
-
each message must have an annotation before it start
// @gleam record
is mean a embedded struct (record)// @gleam msgid = 1
is mean a api, msgid is a big-end 2 bytes number (max is 65535) -
when you generated the
game.gleam
, thegame.encode(msg)
orgame.decode(binary)
all Assuming that the msgid is packaged in the head of binary (This will help with communication between the client and server) -
see
game.proto
Useage:
- use
acrostic.gen
gen gleam file (eg:src/game.gleam
) from proto files
gleam add acrostic
import acrostic
pub fn main() {
acrostic.gen(["game.proto"], to: "src/game.gleam", flags: acrostic.Flags(False, False))
}
- test encode/decode
import game
let binary = game.encode(
game.Test(
hello: "hi",
world: 1.0,
item: game.Item(id:1, num:1),
pet: game.Cat,
nums: []
)
)
let assert Ok(test_msg) = game.decode(binary)
Further documentation can be found at https://hexdocs.pm/acrostic.
Development
gleam test # Run the tests