go-caplit
It is CapLit message deserializer for Go. CapLit stands for 'capnproto literal'. So, this library converts a text(CapLit format) to a Go Object.
For instance, if you have 'Person' Struct with 2 attributes(name, age), you can make a Person object from string '(name="gopher", age=10)' using this library.
Install
go get -u github.com/devsisters/go-caplit
There are no dependencies for this library.
Usage
Since Go does not support Generic Type, we have to generate 'ReadCapLit' method for each capnp structs.
To generate ReadCapLit function, we need the go codes generated by 'capnp compile'
You can use ReadCapLit function with follwing 3 steps.
- Compile your .capnp files
$ capnp compile -ogo --src-prefix=import {path}/*.capnp
- Generate ReadCapLit functions with 'GenCapnpReadCapLit' function
GenCapnpReadCapLit function generates ReadCapLit functions. It takes 5 parameters :
- Path of Input capnp.go files
- Output file name
- Output file package
- List of enums
- You can make 'EnumList' with 'GetEnumList'. If your capnp struct includes other capnp package's enums, you have to give them.
- Extra imports in generated go file
- If your capnp struct includes other capnp package's structs or enums, you have to give them.
It is recommended to use this function with go generate
command. There are 2 example code that works with 'go generate' - example/singlepackage/gen/generate.go, example/multipackage/gen/generate.go.
3. Use ReadCapLit function with your own caplit string
Examples
You can get 2 examples in example
folder - the examples work with make
command.
License
MIT License. see LICENSE file.
What is Cap'n Proto?
"Cap’n Proto is an insanely fast data interchange format and capability-based RPC system."
See details : http://kentonv.github.io/capnproto/