capn_proto-rpc 0.1.1.alpha.rpc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +19 -0
- data/Gemfile +2 -0
- data/LICENSE +19 -0
- data/README.md +249 -0
- data/Rakefile +44 -0
- data/capn_proto.gemspec +37 -0
- data/examples/addressbook.bin +0 -0
- data/examples/addressbook.capnp +31 -0
- data/examples/create_test_data.py +39 -0
- data/examples/example.rb +38 -0
- data/ext/capn_proto/.ycm_extra_conf.py +65 -0
- data/ext/capn_proto/EzRpc_client.cc +52 -0
- data/ext/capn_proto/EzRpc_client.h +21 -0
- data/ext/capn_proto/EzRpc_server.cc +79 -0
- data/ext/capn_proto/EzRpc_server.h +32 -0
- data/ext/capn_proto/call_context.cc +67 -0
- data/ext/capn_proto/call_context.h +25 -0
- data/ext/capn_proto/capability_client.cc +47 -0
- data/ext/capn_proto/capability_client.h +21 -0
- data/ext/capn_proto/class_builder.cc +80 -0
- data/ext/capn_proto/class_builder.h +72 -0
- data/ext/capn_proto/cxx_compiler.rb +126 -0
- data/ext/capn_proto/dynamic_capability_client.cc +73 -0
- data/ext/capn_proto/dynamic_capability_client.h +22 -0
- data/ext/capn_proto/dynamic_list_builder.cc +123 -0
- data/ext/capn_proto/dynamic_list_builder.h +27 -0
- data/ext/capn_proto/dynamic_list_reader.cc +63 -0
- data/ext/capn_proto/dynamic_list_reader.h +25 -0
- data/ext/capn_proto/dynamic_object_builder.cc +57 -0
- data/ext/capn_proto/dynamic_object_builder.h +22 -0
- data/ext/capn_proto/dynamic_object_reader.cc +56 -0
- data/ext/capn_proto/dynamic_object_reader.h +22 -0
- data/ext/capn_proto/dynamic_struct_builder.cc +180 -0
- data/ext/capn_proto/dynamic_struct_builder.h +34 -0
- data/ext/capn_proto/dynamic_struct_reader.cc +69 -0
- data/ext/capn_proto/dynamic_struct_reader.h +25 -0
- data/ext/capn_proto/dynamic_value_builder.cc +53 -0
- data/ext/capn_proto/dynamic_value_builder.h +13 -0
- data/ext/capn_proto/dynamic_value_reader.cc +55 -0
- data/ext/capn_proto/dynamic_value_reader.h +13 -0
- data/ext/capn_proto/exception.cc +34 -0
- data/ext/capn_proto/exception.h +20 -0
- data/ext/capn_proto/extconf.rb +32 -0
- data/ext/capn_proto/field_list.cc +51 -0
- data/ext/capn_proto/field_list.h +23 -0
- data/ext/capn_proto/flat_array_message_reader.cc +61 -0
- data/ext/capn_proto/flat_array_message_reader.h +21 -0
- data/ext/capn_proto/init.cc +71 -0
- data/ext/capn_proto/interface_method.cc +38 -0
- data/ext/capn_proto/interface_method.h +21 -0
- data/ext/capn_proto/interface_schema.cc +51 -0
- data/ext/capn_proto/interface_schema.h +26 -0
- data/ext/capn_proto/list_nested_node_reader.cc +53 -0
- data/ext/capn_proto/list_nested_node_reader.h +24 -0
- data/ext/capn_proto/malloc_message_builder.cc +51 -0
- data/ext/capn_proto/malloc_message_builder.h +21 -0
- data/ext/capn_proto/message_builder.cc +22 -0
- data/ext/capn_proto/message_builder.h +17 -0
- data/ext/capn_proto/message_reader.cc +30 -0
- data/ext/capn_proto/message_reader.h +17 -0
- data/ext/capn_proto/nested_node_reader.cc +42 -0
- data/ext/capn_proto/nested_node_reader.h +21 -0
- data/ext/capn_proto/parsed_schema.cc +65 -0
- data/ext/capn_proto/parsed_schema.h +24 -0
- data/ext/capn_proto/rb.cc +0 -0
- data/ext/capn_proto/rb.h +0 -0
- data/ext/capn_proto/remote_promise.cc +116 -0
- data/ext/capn_proto/remote_promise.h +30 -0
- data/ext/capn_proto/ruby_capability_server.cc +23 -0
- data/ext/capn_proto/ruby_capability_server.h +21 -0
- data/ext/capn_proto/ruby_capn_proto.cc +4 -0
- data/ext/capn_proto/ruby_capn_proto.h +42 -0
- data/ext/capn_proto/schema_node_reader.cc +59 -0
- data/ext/capn_proto/schema_node_reader.h +23 -0
- data/ext/capn_proto/schema_parser.cc +61 -0
- data/ext/capn_proto/schema_parser.h +20 -0
- data/ext/capn_proto/stream_fd_message_reader.cc +59 -0
- data/ext/capn_proto/stream_fd_message_reader.h +21 -0
- data/ext/capn_proto/struct_schema.cc +59 -0
- data/ext/capn_proto/struct_schema.h +23 -0
- data/ext/capn_proto/util.cc +30 -0
- data/ext/capn_proto/util.h +17 -0
- data/lib/capn_proto.rb +231 -0
- data/lib/capn_proto/version.rb +3 -0
- data/media/captain_proto.png +0 -0
- data/media/captain_proto_small.png +0 -0
- data/spec/addressbook.bin +0 -0
- data/spec/addressbook.capnp +31 -0
- data/spec/capn_proto_spec.rb +80 -0
- data/spec/create_test_data.py +38 -0
- data/spec/spec_helper.rb +8 -0
- data/tests/hidraCordatus.capnp +16 -0
- data/tests/hidraCordatusEmployer.rb +33 -0
- data/tests/hidraCordatusMaster.rb +51 -0
- metadata +216 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
#ifndef FLAT_ARRAY_MESSAGE_READER_H
|
2
|
+
#define FLAT_ARRAY_MESSAGE_READER_H
|
3
|
+
|
4
|
+
#include "ruby_capn_proto.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
class FlatArrayMessageReader {
|
8
|
+
public:
|
9
|
+
using WrappedType = capnp::FlatArrayMessageReader;
|
10
|
+
static void Init();
|
11
|
+
static VALUE alloc(VALUE klass);
|
12
|
+
static VALUE initialize(VALUE klass, VALUE io);
|
13
|
+
static void free(WrappedType* p);
|
14
|
+
static WrappedType* unwrap(VALUE self);
|
15
|
+
static VALUE get_root(VALUE self, VALUE schema);
|
16
|
+
|
17
|
+
static VALUE Class;
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
#endif /* FLAT_ARRAY_MESSAGE_READER_H */
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#include "ruby_capn_proto.h"
|
2
|
+
|
3
|
+
#include "exception.h"
|
4
|
+
|
5
|
+
#include "schema_parser.h"
|
6
|
+
#include "parsed_schema.h"
|
7
|
+
#include "struct_schema.h"
|
8
|
+
#include "interface_schema.h"
|
9
|
+
#include "interface_method.h"
|
10
|
+
|
11
|
+
#include "capability_client.h"
|
12
|
+
#include "remote_promise.h"
|
13
|
+
#include "call_context.h"
|
14
|
+
#include "EzRpc_server.h"
|
15
|
+
#include "EzRpc_client.h"
|
16
|
+
#include "dynamic_capability_client.h"
|
17
|
+
#include "schema_node_reader.h"
|
18
|
+
#include "nested_node_reader.h"
|
19
|
+
#include "list_nested_node_reader.h"
|
20
|
+
#include "field_list.h"
|
21
|
+
|
22
|
+
#include "message_reader.h"
|
23
|
+
#include "message_builder.h"
|
24
|
+
#include "stream_fd_message_reader.h"
|
25
|
+
#include "malloc_message_builder.h"
|
26
|
+
#include "flat_array_message_reader.h"
|
27
|
+
|
28
|
+
#include "dynamic_struct_reader.h"
|
29
|
+
#include "dynamic_struct_builder.h"
|
30
|
+
#include "dynamic_list_reader.h"
|
31
|
+
#include "dynamic_list_builder.h"
|
32
|
+
#include "dynamic_object_reader.h"
|
33
|
+
#include "dynamic_object_builder.h"
|
34
|
+
|
35
|
+
using namespace ruby_capn_proto;
|
36
|
+
|
37
|
+
extern "C" {
|
38
|
+
void Init_capn_proto() {
|
39
|
+
Exception::Init();
|
40
|
+
|
41
|
+
SchemaParser::Init();
|
42
|
+
ParsedSchema::Init();
|
43
|
+
StructSchema::Init();
|
44
|
+
InterfaceSchema::Init();
|
45
|
+
InterfaceMethod::Init();
|
46
|
+
|
47
|
+
CapabilityClient::Init();
|
48
|
+
RemotePromise::Init();
|
49
|
+
CallContext::Init();
|
50
|
+
EzRpcCapabilityServer::Init();
|
51
|
+
EzRpcCapabilityClient::Init();
|
52
|
+
DynamicCapabilityClient::Init();
|
53
|
+
SchemaNodeReader::Init();
|
54
|
+
NestedNodeReader::Init();
|
55
|
+
ListNestedNodeReader::Init();
|
56
|
+
FieldList::Init();
|
57
|
+
|
58
|
+
MessageReader::Init();
|
59
|
+
MessageBuilder::Init();
|
60
|
+
StreamFdMessageReader::Init();
|
61
|
+
MallocMessageBuilder::Init();
|
62
|
+
FlatArrayMessageReader::Init();
|
63
|
+
|
64
|
+
DynamicStructReader::Init();
|
65
|
+
DynamicStructBuilder::Init();
|
66
|
+
DynamicListReader::Init();
|
67
|
+
DynamicListBuilder::Init();
|
68
|
+
DynamicObjectReader::Init();
|
69
|
+
DynamicObjectBuilder::Init();
|
70
|
+
}
|
71
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#include "ruby_capn_proto.h"
|
2
|
+
#include "interface_method.h"
|
3
|
+
#include "class_builder.h"
|
4
|
+
#include "util.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
using WrappedType = capnp::InterfaceSchema::Method;
|
8
|
+
VALUE InterfaceMethod::Class;
|
9
|
+
|
10
|
+
void InterfaceMethod::Init() {
|
11
|
+
ClassBuilder("InterfaceMethod", rb_cObject).
|
12
|
+
defineAlloc(&alloc).
|
13
|
+
// no methods...
|
14
|
+
store(&Class);
|
15
|
+
}
|
16
|
+
|
17
|
+
void InterfaceMethod::free(WrappedType* p) {
|
18
|
+
p->~Method();
|
19
|
+
ruby_xfree(p);
|
20
|
+
}
|
21
|
+
|
22
|
+
VALUE InterfaceMethod::alloc(VALUE klass) {
|
23
|
+
return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
|
24
|
+
}
|
25
|
+
|
26
|
+
WrappedType* InterfaceMethod::unwrap(VALUE self) {
|
27
|
+
WrappedType* p;
|
28
|
+
Data_Get_Struct(self, WrappedType, p);
|
29
|
+
return p;
|
30
|
+
}
|
31
|
+
|
32
|
+
VALUE InterfaceMethod::create(WrappedType method) {
|
33
|
+
VALUE rb_obj = alloc(Class);
|
34
|
+
WrappedType* wrapped_method = unwrap(rb_obj);
|
35
|
+
*wrapped_method = kj::mv(method);
|
36
|
+
return rb_obj;
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#ifndef INTERFACE_METHOD_SCHEMA_H
|
2
|
+
#define INTERFACE_METHOD_SCHEMA_H
|
3
|
+
|
4
|
+
#include "ruby_capn_proto.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
class InterfaceMethod {
|
8
|
+
public:
|
9
|
+
using WrappedType = capnp::InterfaceSchema::Method;
|
10
|
+
static void Init();
|
11
|
+
static VALUE alloc(VALUE klass);
|
12
|
+
static VALUE create(WrappedType method);
|
13
|
+
static void free(WrappedType* p);
|
14
|
+
static WrappedType* unwrap(VALUE self);
|
15
|
+
// no methods...
|
16
|
+
static VALUE Class;
|
17
|
+
};
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
#endif /* INTERFACE_METHOD_SCHEMA_H */
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#include "ruby_capn_proto.h"
|
2
|
+
#include "interface_schema.h"
|
3
|
+
#include "interface_method.h"
|
4
|
+
#include "class_builder.h"
|
5
|
+
#include "util.h"
|
6
|
+
|
7
|
+
namespace ruby_capn_proto {
|
8
|
+
using WrappedType = capnp::InterfaceSchema;
|
9
|
+
VALUE InterfaceSchema::Class;
|
10
|
+
|
11
|
+
void InterfaceSchema::Init() {
|
12
|
+
ClassBuilder("InterfaceSchema", rb_cObject).
|
13
|
+
defineAlloc(&alloc).
|
14
|
+
defineMethod("find_method_by_name" , &find_method_by_name).
|
15
|
+
store(&Class);
|
16
|
+
}
|
17
|
+
|
18
|
+
void InterfaceSchema::free(WrappedType* p) {
|
19
|
+
p->~InterfaceSchema();
|
20
|
+
ruby_xfree(p);
|
21
|
+
}
|
22
|
+
|
23
|
+
VALUE InterfaceSchema::alloc(VALUE klass) {
|
24
|
+
return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
|
25
|
+
}
|
26
|
+
|
27
|
+
WrappedType* InterfaceSchema::unwrap(VALUE self) {
|
28
|
+
WrappedType* p;
|
29
|
+
Data_Get_Struct(self, WrappedType, p);
|
30
|
+
return p;
|
31
|
+
}
|
32
|
+
|
33
|
+
VALUE InterfaceSchema::create(WrappedType schema, VALUE parent) {
|
34
|
+
VALUE rb_obj = alloc(Class);
|
35
|
+
WrappedType* wrapped_schema = unwrap(rb_obj);
|
36
|
+
*wrapped_schema = kj::mv(schema);
|
37
|
+
|
38
|
+
rb_iv_set(rb_obj, "parent", parent);
|
39
|
+
|
40
|
+
return rb_obj;
|
41
|
+
}
|
42
|
+
|
43
|
+
VALUE InterfaceSchema::find_method_by_name(VALUE self, VALUE name){
|
44
|
+
capnp::InterfaceSchema::Method value;
|
45
|
+
KJ_IF_MAYBE(value, unwrap(self)->findMethodByName(Util::toString(name))) {
|
46
|
+
return InterfaceMethod::create(*value);
|
47
|
+
} else {
|
48
|
+
return Qfalse;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#ifndef INTERFACE_SCHEMA_H
|
2
|
+
#define INTERFACE_SCHEMA_H
|
3
|
+
|
4
|
+
#include "ruby_capn_proto.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
class InterfaceSchema {
|
8
|
+
public:
|
9
|
+
using WrappedType = capnp::InterfaceSchema;
|
10
|
+
static void Init();
|
11
|
+
static VALUE alloc(VALUE klass);
|
12
|
+
static VALUE create(WrappedType schema, VALUE parent);
|
13
|
+
static void free(WrappedType* p);
|
14
|
+
static WrappedType* unwrap(VALUE self);
|
15
|
+
// commented methods below don't are strictly needed.
|
16
|
+
//static VALUE getMethodByName(VALUE self, VALUE name);
|
17
|
+
//static VALUE getMethods(VALUE self);
|
18
|
+
static VALUE find_method_by_name(VALUE self, VALUE name);
|
19
|
+
|
20
|
+
|
21
|
+
static VALUE Class;
|
22
|
+
};
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
#endif /* INTERFACE_SCHEMA_H */
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#include "ruby_capn_proto.h"
|
2
|
+
#include "list_nested_node_reader.h"
|
3
|
+
#include "nested_node_reader.h"
|
4
|
+
#include "class_builder.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
using NodeList = ::capnp::List< ::capnp::schema::Node::NestedNode>::Reader;
|
8
|
+
|
9
|
+
VALUE ListNestedNodeReader::Class;
|
10
|
+
|
11
|
+
void ListNestedNodeReader::Init() {
|
12
|
+
ClassBuilder("ListNestedNodeReader", rb_cObject).
|
13
|
+
defineAlloc(&alloc).
|
14
|
+
defineMethod("size", &size).
|
15
|
+
defineMethod("[]", &get).
|
16
|
+
store(&Class);
|
17
|
+
}
|
18
|
+
|
19
|
+
void ListNestedNodeReader::free(NodeList* p) {
|
20
|
+
p->~NodeList();
|
21
|
+
ruby_xfree(p);
|
22
|
+
}
|
23
|
+
|
24
|
+
VALUE ListNestedNodeReader::alloc(VALUE klass) {
|
25
|
+
return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(NodeList)));
|
26
|
+
}
|
27
|
+
|
28
|
+
NodeList* ListNestedNodeReader::unwrap(VALUE self) {
|
29
|
+
NodeList* p;
|
30
|
+
Data_Get_Struct(self, NodeList, p);
|
31
|
+
return p;
|
32
|
+
}
|
33
|
+
|
34
|
+
VALUE ListNestedNodeReader::create(NodeList schema, VALUE parent) {
|
35
|
+
VALUE rb_obj = alloc(Class);
|
36
|
+
NodeList* wrapped_schema = unwrap(rb_obj);
|
37
|
+
*wrapped_schema = kj::mv(schema);
|
38
|
+
|
39
|
+
rb_iv_set(rb_obj, "parent", parent);
|
40
|
+
|
41
|
+
return rb_obj;
|
42
|
+
}
|
43
|
+
|
44
|
+
VALUE ListNestedNodeReader::size(VALUE self) {
|
45
|
+
return INT2FIX(unwrap(self)->size());
|
46
|
+
}
|
47
|
+
|
48
|
+
VALUE ListNestedNodeReader::get(VALUE self, VALUE index) {
|
49
|
+
auto idx = FIX2INT(index);
|
50
|
+
auto list = *unwrap(self);
|
51
|
+
return NestedNodeReader::create(list[idx]);
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#ifndef LIST_NESTED_NODE_READER_H
|
2
|
+
#define LIST_NESTED_NODE_READER_H
|
3
|
+
|
4
|
+
#include "ruby_capn_proto.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
class ListNestedNodeReader {
|
8
|
+
public:
|
9
|
+
using NodeList = ::capnp::List< ::capnp::schema::Node::NestedNode>::Reader;
|
10
|
+
|
11
|
+
static void Init();
|
12
|
+
static VALUE initialize(VALUE klass);
|
13
|
+
static VALUE alloc(VALUE klass);
|
14
|
+
static void free(NodeList* p);
|
15
|
+
static NodeList* unwrap(VALUE self);
|
16
|
+
static VALUE create(NodeList reader, VALUE parent);
|
17
|
+
static VALUE size(VALUE self);
|
18
|
+
static VALUE get(VALUE self, VALUE index);
|
19
|
+
|
20
|
+
static VALUE Class;
|
21
|
+
};
|
22
|
+
}
|
23
|
+
|
24
|
+
#endif /* LIST_NESTED_NODE_READER_H */
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#include "ruby_capn_proto.h"
|
2
|
+
#include "malloc_message_builder.h"
|
3
|
+
#include "message_builder.h"
|
4
|
+
#include "struct_schema.h"
|
5
|
+
#include "dynamic_struct_builder.h"
|
6
|
+
#include "class_builder.h"
|
7
|
+
|
8
|
+
namespace ruby_capn_proto {
|
9
|
+
using WrappedType = capnp::MallocMessageBuilder;
|
10
|
+
VALUE MallocMessageBuilder::Class;
|
11
|
+
|
12
|
+
void MallocMessageBuilder::Init() {
|
13
|
+
ClassBuilder("MallocMessageBuilder", MessageBuilder::Class).
|
14
|
+
defineAlloc(&alloc).
|
15
|
+
defineMethod("initialize", &initialize).
|
16
|
+
defineMethod("init_root", &init_root).
|
17
|
+
// defineMethod("get_root", &get_root).
|
18
|
+
store(&Class);
|
19
|
+
}
|
20
|
+
|
21
|
+
VALUE MallocMessageBuilder::alloc(VALUE klass) {
|
22
|
+
return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
|
23
|
+
}
|
24
|
+
|
25
|
+
VALUE MallocMessageBuilder::initialize(VALUE self) {
|
26
|
+
WrappedType* p = unwrap(self);
|
27
|
+
new (p) WrappedType();
|
28
|
+
return Qnil;
|
29
|
+
}
|
30
|
+
|
31
|
+
void MallocMessageBuilder::free(WrappedType* p) {
|
32
|
+
p->~MallocMessageBuilder();
|
33
|
+
ruby_xfree(p);
|
34
|
+
}
|
35
|
+
|
36
|
+
WrappedType* MallocMessageBuilder::unwrap(VALUE self) {
|
37
|
+
WrappedType* p;
|
38
|
+
Data_Get_Struct(self, WrappedType, p);
|
39
|
+
return p;
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE MallocMessageBuilder::init_root(VALUE self, VALUE rb_schema) {
|
43
|
+
if (rb_respond_to(rb_schema, rb_intern("schema"))) {
|
44
|
+
rb_schema = rb_funcall(rb_schema, rb_intern("schema"), 0);
|
45
|
+
}
|
46
|
+
|
47
|
+
auto schema = *StructSchema::unwrap(rb_schema);
|
48
|
+
auto builder = unwrap(self)->initRoot<capnp::DynamicStruct>(schema);
|
49
|
+
return DynamicStructBuilder::create(builder, self, true);
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#ifndef MALLOC_MESSAGE_BUILDER_H
|
2
|
+
#define MALLOC_MESSAGE_BUILDER_H
|
3
|
+
|
4
|
+
#include "ruby_capn_proto.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
class MallocMessageBuilder {
|
8
|
+
public:
|
9
|
+
using WrappedType = capnp::MallocMessageBuilder;
|
10
|
+
static void Init();
|
11
|
+
static VALUE alloc(VALUE klass);
|
12
|
+
static VALUE initialize(VALUE klass);
|
13
|
+
static void free(WrappedType* p);
|
14
|
+
static WrappedType* unwrap(VALUE self);
|
15
|
+
static VALUE init_root(VALUE name, VALUE schema);
|
16
|
+
|
17
|
+
static VALUE Class;
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
#endif
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#include "ruby_capn_proto.h"
|
2
|
+
#include "message_builder.h"
|
3
|
+
#include "class_builder.h"
|
4
|
+
#include "struct_schema.h"
|
5
|
+
#include "dynamic_struct_reader.h"
|
6
|
+
#include "util.h"
|
7
|
+
|
8
|
+
namespace ruby_capn_proto {
|
9
|
+
using WrappedType = capnp::MessageBuilder;
|
10
|
+
VALUE MessageBuilder::Class;
|
11
|
+
|
12
|
+
void MessageBuilder::Init() {
|
13
|
+
ClassBuilder("MessageBuilder", rb_cObject).
|
14
|
+
store(&Class);
|
15
|
+
}
|
16
|
+
|
17
|
+
WrappedType* MessageBuilder::unwrap(VALUE self) {
|
18
|
+
WrappedType* p;
|
19
|
+
Data_Get_Struct(self, WrappedType, p);
|
20
|
+
return p;
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#ifndef MESSAGE_BUILDER_H
|
2
|
+
#define MESSAGE_BUILDER_H
|
3
|
+
|
4
|
+
#include "ruby_capn_proto.h"
|
5
|
+
|
6
|
+
namespace ruby_capn_proto {
|
7
|
+
class MessageBuilder {
|
8
|
+
public:
|
9
|
+
using WrappedType = capnp::MessageBuilder;
|
10
|
+
static void Init();
|
11
|
+
static WrappedType* unwrap(VALUE self);
|
12
|
+
|
13
|
+
static VALUE Class;
|
14
|
+
};
|
15
|
+
}
|
16
|
+
|
17
|
+
#endif /* MESSAGE_BUILDER_H */
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#include "ruby_capn_proto.h"
|
2
|
+
#include "message_reader.h"
|
3
|
+
#include "class_builder.h"
|
4
|
+
#include "struct_schema.h"
|
5
|
+
#include "dynamic_struct_reader.h"
|
6
|
+
#include "util.h"
|
7
|
+
|
8
|
+
namespace ruby_capn_proto {
|
9
|
+
using WrappedType = capnp::MessageReader;
|
10
|
+
VALUE MessageReader::Class;
|
11
|
+
|
12
|
+
void MessageReader::Init() {
|
13
|
+
ClassBuilder("MessageReader", rb_cObject).
|
14
|
+
store(&Class);
|
15
|
+
}
|
16
|
+
|
17
|
+
// XXX
|
18
|
+
// I wanted to use inheritance here for #get_root,
|
19
|
+
// but this segfaults unless I reinterpret_cast to the right
|
20
|
+
// subclass of capnp::MessageReader. Whish I know more about
|
21
|
+
// the C++ object model :(...
|
22
|
+
// Worst case scenario, I could probably use tempalates...
|
23
|
+
// If only I had experience with them.
|
24
|
+
|
25
|
+
WrappedType* MessageReader::unwrap(VALUE self) {
|
26
|
+
WrappedType* p;
|
27
|
+
Data_Get_Struct(self, WrappedType, p);
|
28
|
+
return p;
|
29
|
+
}
|
30
|
+
}
|