Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/devsisters/go-caplit
Go caplit message deserializer
https://github.com/devsisters/go-caplit
Last synced: about 2 months ago
JSON representation
Go caplit message deserializer
- Host: GitHub
- URL: https://github.com/devsisters/go-caplit
- Owner: devsisters
- License: mit
- Created: 2016-04-06T11:35:17.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-29T12:43:19.000Z (about 6 years ago)
- Last Synced: 2024-06-20T10:18:17.737Z (7 months ago)
- Language: Go
- Size: 37.1 KB
- Stars: 17
- Watchers: 47
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```
2. 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/