Comments (3)
@0xed2b3b98b3eb515b;
struct Msg {
data @0: Data;
}
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include "data.capnp.h"
int main(int argc, char **argv)
{
uint8_t data[] = { 0x12, 0x34, 0x00, 0x56, 0x78 };
/* create capn + capn segment */
struct capn c;
capn_init_malloc(&c);
capn_ptr cr = capn_root(&c);
struct capn_segment *cs = cr.seg;
struct Msg msg;
/* capn_list8 & capn_data are essentially the same (they both just contain a single capn_ptr)
* usage is slightly convoluted sadly */
capn_list8 list8 = capn_new_list8(cs, sizeof(data));
capn_setv8(list8, 0, data, sizeof(data));
msg.data.p = list8.p;
/* encode & set as root */
Msg_ptr pp = new_Msg(cs);
write_Msg(&msg, pp);
assert(capn_setp(capn_root(&c), 0, pp.p) == 0);
uint8_t obuf[4096];
size_t sz = capn_write_mem(&c, obuf, sizeof(obuf), 0);
capn_free(&c);
write(1, obuf, sz);
return 0;
}
$ ./datatest | capnp decode data.capnp Msg
(data = "\x124\x00Vx")
from c-capnproto.
Thanks a lot equinox. The "capn_list8" part is the one I totally missed. I will make modifications and post the results.
from c-capnproto.
Added note in header, don't have a better place for documentation currently. -- closing
from c-capnproto.
Related Issues (20)
- Get expected size before writing in memory HOT 2
- Trying to write a NULL struct HOT 1
- Documentation / Security Warning HOT 2
- Small-size data serialization problem HOT 1
- Deserialization returns all 0's HOT 1
- Can't retrieve list length of native field type
- Won't compile
- Incorrect assumption that a C enum is always 2 octets wipes enum values sometimes.
- capn_write_mem() return value is int HOT 9
- Nested unions generate incorrect code HOT 1
- capn_size() return value should be int64_t
- packed header is not 32 bit aligned->can cause memory fault
- capn_get64() always returns zero HOT 1
- Project is UNMAINTAINED HOT 14
- Support Meson buildsystem
- compiler/test.capnp.c:3159:42: warning: bitwise comparison always evaluates to true
- ../tests/example-test.cpp:89: Failure Expected: (f) != ((void*)0), actual: NULL vs NULL HOT 1
- ASAN and UBSAN warnings
- Add CI for Windows and macOS
- Build C source issue with Ubuntu
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from c-capnproto.