caplit

package module
v0.0.0-...-8d2a667 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2018 License: MIT Imports: 10 Imported by: 0

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
  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/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncDeclInList

func FuncDeclInList(elem CapnpFuncDecl, l []CapnpFuncDecl) bool

func GenCapnpReadCapLit

func GenCapnpReadCapLit(inputPath, outputPath string, packageName string, enumList []string, importList []string)

func GetEnumList

func GetEnumList(targetDir string) []string

return list of name of Enums in targetDir

Types

type CapnpFuncDecl

type CapnpFuncDecl struct {
	FuncDecl *ast.FuncDecl
	Path     string
}

type CapnpStruct

type CapnpStruct struct {
	Name   string
	Path   string
	Keys   []CapnpStructParams
	Parent string
}

func CapnpEnums

func CapnpEnums(capnpDir string) []CapnpStruct

func CapnpStructs

func CapnpStructs(capnpDir string) []CapnpStruct

type CapnpStructParams

type CapnpStructParams struct {
	Name     string
	Template string
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL