You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package pogs // import "zombiezen.com/go/capnproto2/pogs"// GeneratedStruct is the interface implemented by a struct generated by capnpc-go.typeGeneratedStructinterface {
GeneratedStruct() (iduint64, schemaData []byte, s capnp.Struct)
}
// Unmarshal copies from a Cap'n Proto struct to a plain Go struct.funcUnmarshal(valinterface{}, sGeneratedStruct) error {
// ...
}
// Marshal copies from a plain Go struct into a Cap'n Proto struct.funcMarshal(sGeneratedStruct, valinterface{}) error {
// ...
}
Usage:
// Assuming you have a capnp schema foo.capnp:// struct Foo {// bar @0 :UInt64;// }typeFoostruct {
Baruint64
}
funcmain() {
msg, err:=capnp.Unmarshal(myByteSource)
iferr!=nil {
panic(err)
}
foo, err:=fooschema.ReadRootFoo(msg)
iferr!=nil {
panic(err)
}
// New API:varfooStructFooiferr:=pogs.Unmarshal(&fooStruct, foo); err!=nil {
panic(err)
}
fmt.Println(fooStruct.Bar)
// And new API for writing back out:iferr:=pogs.Marshal(foo, &fooStruct); err!=nil {
panic(err)
}
fmt.Print(msg.Marshal())
}
capnpc-go could be optionally extended to generate the structs automatically, but much like the json package, users could also define narrow Go structs if they only need certain fields.
Similar to the support planned for C++: https://groups.google.com/d/topic/capnproto/Reg0wInHBdY/discussion
Design sketch:
Usage:
capnpc-go
could be optionally extended to generate the structs automatically, but much like thejson
package, users could also define narrow Go structs if they only need certain fields.cc @lvdlvd
The text was updated successfully, but these errors were encountered: