opensourcerouting / c-capnproto

C library/compiler for the Cap'n Proto serialization/RPC protocol
MIT License
118 stars 40 forks source link

Can't retrieve list length of native field type #33

Open dpedu opened 5 years ago

dpedu commented 5 years ago

I have a struct like this:

struct Event {
    args        @0  :List(Text);
}

Which generates a struct like this:

struct Event {
    capn_ptr args;
};

Which seems wrong because if I try to get the length of the list using capn_len I cannot compile my program because capn_len tries to access a member named p and struct capn_ptr doesn't have a member named p:

In file included from bufs/main.capnp.h:4:0,
                 from event.c:3:
event.c: In function 'event_tocapn':
../deps/build/usr/local/include/capnp_c.h:182:31: error: 'capn_ptr {aka struct capn_ptr}' has no member named 'p'
 #define capn_len(list) ((list).p.type == CAPN_FAR_POINTER ? (capn_resolve(&(list).p), (list).p.len) : (list).p.len)
                               ^
event.c:173:27: note: in expansion of macro 'capn_len'
     printf("Len is %d\n", capn_len(ie->args));
                           ^~~~~~~~

...

If I use a custom defined type as the list members (such as a struct containing only a Text field) everything is fine.

From looking at other examples, it looks like this field should be a capn_data struct or one of the capn_list structs?