All Projects → devsisters → go-caplit

devsisters / go-caplit

Licence: MIT License
Go caplit message deserializer

Programming Languages

go
31211 projects - #10 most used programming language
Cap'n Proto
48 projects
Makefile
30231 projects

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.

  1. Compile your .capnp files
 $ capnp compile -ogo --src-prefix=import {path}/*.capnp
  1. 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/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].