jmckaskill / go-capnproto Goto Github PK
View Code? Open in Web Editor NEWCap'n Proto library and parser for go
License: Other
Cap'n Proto library and parser for go
License: Other
switch b[0] {
case 0xFF:
io.ReadFull(c.r, c.buf[:])
case 0x00:
I think you need to read a byte and set c.raw after io.ReadFull. :-)
Not sure if this would be better on the main Cap'n Proto discussion, but I'll try here. How does one set a pointer in a list? I have a struct that looks like:
struct Map {
map @0 :List(Item);
struct Item {
name @0 :Text;
value :union {
int @1 :Int32;
string @2 :Text;
map @3 :Map;
}
}
}
I can create a Map. Then I create a MapItemList with the segment from the Map and the length that I want, and I set the MapItemList to the Map using SetMap(). I then use that segment to start creating MapItems, but I don't know how to set the pointers to my newly created MapItem's to their indexes in the MapItemList. If I print out the resulting bytes, I can see the data is there, but I can't get the data out of the list using the provided read functions, likely because I am not setting pointers to the data in the list. Here is the function I'm messing around with:
func WriteMap(mm map[string]interface{}) bytes.Buffer {
ns := capn.NewBuffer(nil)
m := NewRootMap(ns)
mil := NewMapItemList(ns, len(mm))
m.SetMap(mil)
counter := 0
for k, v := range mm {
mi := NewMapItem(ns)
mi.SetName(k)
switch v.(type) {
case string:
mi.Value().SetString(v.(string))
case int:
mi.Value().SetInt(int32(v.(int)))
default:
panic("OH SNAP")
}
counter++
}
buf := bytes.Buffer{}
ns.WriteTo(&buf)
return buf
}
Anyone see what I'm doing wrong? Or how I can do this?
Unions are only handled for struct union members. We should fix it so it handles all cases and also switch to using a switch statement.
I'm using a List(List(Signature))
where
struct Signature {
key @0: Data;
signature @1: Data;
}
and the generated code cannot compile
capnp compile -ogo src/libnode/message.capnp
go install libnode
# libnode
src/libnode/message.capnp.go:1033: cannot range over s.ToArray() (type *[]capn.Object)
Makefile:21: recipe for target 'pkg/linux_amd64/libnode.a' failed
Can you write a sample for using packed streams?
I'm not sure if I'm missing something here but the union API seems to have changed since the documentation was written. Specifically the lines
f.SetA() // Set that we are using group A
f.A().SetV(true) // then we can use the group A getter to set the inner values
http://godoc.org/github.com/jmckaskill/go-capnproto#hdr-Unions
Instead it seems to generate the following which can make the api harder to use
a := NewA((*C.Segment)s)
f.SetA(a A)
a.SetV(true)
Would it be worth generating a NewA() & NewB() on the containing Foo struct given it already has a reference to the segment and by definition they would never be a RootStruct.
This file should be removed from your repo:
https://github.com/jmckaskill/go-capnproto/blob/master/go_capnp_test/.test.go.swo
Is that possible to automatic prepend contents of go.capnp when generating go files?
As i see i need to have this file in all my projects and update when new version comes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.