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.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +19 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE +19 -0
  6. data/README.md +249 -0
  7. data/Rakefile +44 -0
  8. data/capn_proto.gemspec +37 -0
  9. data/examples/addressbook.bin +0 -0
  10. data/examples/addressbook.capnp +31 -0
  11. data/examples/create_test_data.py +39 -0
  12. data/examples/example.rb +38 -0
  13. data/ext/capn_proto/.ycm_extra_conf.py +65 -0
  14. data/ext/capn_proto/EzRpc_client.cc +52 -0
  15. data/ext/capn_proto/EzRpc_client.h +21 -0
  16. data/ext/capn_proto/EzRpc_server.cc +79 -0
  17. data/ext/capn_proto/EzRpc_server.h +32 -0
  18. data/ext/capn_proto/call_context.cc +67 -0
  19. data/ext/capn_proto/call_context.h +25 -0
  20. data/ext/capn_proto/capability_client.cc +47 -0
  21. data/ext/capn_proto/capability_client.h +21 -0
  22. data/ext/capn_proto/class_builder.cc +80 -0
  23. data/ext/capn_proto/class_builder.h +72 -0
  24. data/ext/capn_proto/cxx_compiler.rb +126 -0
  25. data/ext/capn_proto/dynamic_capability_client.cc +73 -0
  26. data/ext/capn_proto/dynamic_capability_client.h +22 -0
  27. data/ext/capn_proto/dynamic_list_builder.cc +123 -0
  28. data/ext/capn_proto/dynamic_list_builder.h +27 -0
  29. data/ext/capn_proto/dynamic_list_reader.cc +63 -0
  30. data/ext/capn_proto/dynamic_list_reader.h +25 -0
  31. data/ext/capn_proto/dynamic_object_builder.cc +57 -0
  32. data/ext/capn_proto/dynamic_object_builder.h +22 -0
  33. data/ext/capn_proto/dynamic_object_reader.cc +56 -0
  34. data/ext/capn_proto/dynamic_object_reader.h +22 -0
  35. data/ext/capn_proto/dynamic_struct_builder.cc +180 -0
  36. data/ext/capn_proto/dynamic_struct_builder.h +34 -0
  37. data/ext/capn_proto/dynamic_struct_reader.cc +69 -0
  38. data/ext/capn_proto/dynamic_struct_reader.h +25 -0
  39. data/ext/capn_proto/dynamic_value_builder.cc +53 -0
  40. data/ext/capn_proto/dynamic_value_builder.h +13 -0
  41. data/ext/capn_proto/dynamic_value_reader.cc +55 -0
  42. data/ext/capn_proto/dynamic_value_reader.h +13 -0
  43. data/ext/capn_proto/exception.cc +34 -0
  44. data/ext/capn_proto/exception.h +20 -0
  45. data/ext/capn_proto/extconf.rb +32 -0
  46. data/ext/capn_proto/field_list.cc +51 -0
  47. data/ext/capn_proto/field_list.h +23 -0
  48. data/ext/capn_proto/flat_array_message_reader.cc +61 -0
  49. data/ext/capn_proto/flat_array_message_reader.h +21 -0
  50. data/ext/capn_proto/init.cc +71 -0
  51. data/ext/capn_proto/interface_method.cc +38 -0
  52. data/ext/capn_proto/interface_method.h +21 -0
  53. data/ext/capn_proto/interface_schema.cc +51 -0
  54. data/ext/capn_proto/interface_schema.h +26 -0
  55. data/ext/capn_proto/list_nested_node_reader.cc +53 -0
  56. data/ext/capn_proto/list_nested_node_reader.h +24 -0
  57. data/ext/capn_proto/malloc_message_builder.cc +51 -0
  58. data/ext/capn_proto/malloc_message_builder.h +21 -0
  59. data/ext/capn_proto/message_builder.cc +22 -0
  60. data/ext/capn_proto/message_builder.h +17 -0
  61. data/ext/capn_proto/message_reader.cc +30 -0
  62. data/ext/capn_proto/message_reader.h +17 -0
  63. data/ext/capn_proto/nested_node_reader.cc +42 -0
  64. data/ext/capn_proto/nested_node_reader.h +21 -0
  65. data/ext/capn_proto/parsed_schema.cc +65 -0
  66. data/ext/capn_proto/parsed_schema.h +24 -0
  67. data/ext/capn_proto/rb.cc +0 -0
  68. data/ext/capn_proto/rb.h +0 -0
  69. data/ext/capn_proto/remote_promise.cc +116 -0
  70. data/ext/capn_proto/remote_promise.h +30 -0
  71. data/ext/capn_proto/ruby_capability_server.cc +23 -0
  72. data/ext/capn_proto/ruby_capability_server.h +21 -0
  73. data/ext/capn_proto/ruby_capn_proto.cc +4 -0
  74. data/ext/capn_proto/ruby_capn_proto.h +42 -0
  75. data/ext/capn_proto/schema_node_reader.cc +59 -0
  76. data/ext/capn_proto/schema_node_reader.h +23 -0
  77. data/ext/capn_proto/schema_parser.cc +61 -0
  78. data/ext/capn_proto/schema_parser.h +20 -0
  79. data/ext/capn_proto/stream_fd_message_reader.cc +59 -0
  80. data/ext/capn_proto/stream_fd_message_reader.h +21 -0
  81. data/ext/capn_proto/struct_schema.cc +59 -0
  82. data/ext/capn_proto/struct_schema.h +23 -0
  83. data/ext/capn_proto/util.cc +30 -0
  84. data/ext/capn_proto/util.h +17 -0
  85. data/lib/capn_proto.rb +231 -0
  86. data/lib/capn_proto/version.rb +3 -0
  87. data/media/captain_proto.png +0 -0
  88. data/media/captain_proto_small.png +0 -0
  89. data/spec/addressbook.bin +0 -0
  90. data/spec/addressbook.capnp +31 -0
  91. data/spec/capn_proto_spec.rb +80 -0
  92. data/spec/create_test_data.py +38 -0
  93. data/spec/spec_helper.rb +8 -0
  94. data/tests/hidraCordatus.capnp +16 -0
  95. data/tests/hidraCordatusEmployer.rb +33 -0
  96. data/tests/hidraCordatusMaster.rb +51 -0
  97. metadata +216 -0
@@ -0,0 +1,34 @@
1
+ #ifndef DYNAMIC_STRUCT_BUILDER_H
2
+ #define DYNAMIC_STRUCT_BUILDER_H
3
+
4
+ #include "ruby_capn_proto.h"
5
+
6
+ namespace ruby_capn_proto {
7
+ class DynamicStructBuilder {
8
+ public:
9
+ using WrappedType = capnp::DynamicStruct::Builder;
10
+ static void Init();
11
+ static VALUE alloc(VALUE klass);
12
+ static VALUE create(WrappedType reader, VALUE parent, bool is_root);
13
+ static void free(WrappedType* p);
14
+ static WrappedType* unwrap(VALUE self);
15
+ static VALUE which(VALUE self);
16
+ static VALUE get(VALUE self, VALUE rb_name);
17
+ static VALUE set(VALUE self, VALUE rb_name, VALUE rb_obj);
18
+
19
+ static VALUE init(VALUE self, VALUE rb_name, VALUE rb_obj);
20
+ static VALUE init(int argc, VALUE* argv, VALUE self);
21
+
22
+ static VALUE write(VALUE self, VALUE file);
23
+ static VALUE to_bytes(VALUE self);
24
+
25
+ static VALUE Class;
26
+ private:
27
+ static VALUE _get(VALUE self, VALUE name);
28
+ static VALUE _set(VALUE self, VALUE rb_name, VALUE rb_obj);
29
+
30
+ static VALUE _init(VALUE self, VALUE rb_name, VALUE rb_count, int argc);
31
+ };
32
+ }
33
+
34
+ #endif
@@ -0,0 +1,69 @@
1
+ #include "ruby_capn_proto.h"
2
+ #include "dynamic_struct_reader.h"
3
+ #include "dynamic_value_reader.h"
4
+ #include "class_builder.h"
5
+ #include "exception.h"
6
+ #include "util.h"
7
+
8
+ namespace ruby_capn_proto {
9
+ using WrappedType = capnp::DynamicStruct::Reader;
10
+ VALUE DynamicStructReader::Class;
11
+
12
+ void DynamicStructReader::Init() {
13
+ ClassBuilder("DynamicStructReader", rb_cObject).
14
+ defineAlloc(&alloc).
15
+ defineMethod("which", &which).
16
+ defineMethod("[]", &get).
17
+ store(&Class);
18
+ }
19
+
20
+ void DynamicStructReader::free(WrappedType* p) {
21
+ p->~Reader();
22
+ ruby_xfree(p);
23
+ }
24
+
25
+ VALUE DynamicStructReader::alloc(VALUE klass) {
26
+ return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
27
+ }
28
+
29
+ WrappedType* DynamicStructReader::unwrap(VALUE self) {
30
+ WrappedType* p;
31
+ Data_Get_Struct(self, WrappedType, p);
32
+ return p;
33
+ }
34
+
35
+ VALUE DynamicStructReader::create(WrappedType reader, VALUE parent) {
36
+ VALUE rb_obj = alloc(Class);
37
+ WrappedType* wrapped = unwrap(rb_obj);
38
+ *wrapped = kj::mv(reader);
39
+
40
+ rb_iv_set(rb_obj, "parent", parent);
41
+
42
+ return rb_obj;
43
+ }
44
+
45
+ VALUE DynamicStructReader::get(VALUE self, VALUE rb_name) {
46
+ try {
47
+ return _get(self, rb_name);
48
+ } catch (kj::Exception ex) {
49
+ return Exception::raise(ex);
50
+ }
51
+ }
52
+
53
+ VALUE DynamicStructReader::_get(VALUE self, VALUE rb_name) {
54
+ auto reader = *unwrap(self);
55
+ auto name = Util::toString(rb_name);
56
+ return DynamicValueReader::to_ruby(reader.get(name), self);
57
+ }
58
+
59
+ VALUE DynamicStructReader::which(VALUE self) {
60
+ auto schema_maybe = unwrap(self)->which();
61
+ KJ_IF_MAYBE(schema, schema_maybe) {
62
+ auto name = schema->getProto().getName();
63
+ return rb_str_new(name.begin(), name.size());
64
+ } else {
65
+ // throw std::invalid_argument("member was null");
66
+ return Qnil;
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,25 @@
1
+ #ifndef DYNAMIC_STRUCT_READER_H
2
+ #define DYNAMIC_STRUCT_READER_H
3
+
4
+ #include "ruby_capn_proto.h"
5
+
6
+ namespace ruby_capn_proto {
7
+ class DynamicStructReader {
8
+ public:
9
+ using WrappedType = capnp::DynamicStruct::Reader;
10
+ static void Init();
11
+ static VALUE alloc(VALUE klass);
12
+ static VALUE create(WrappedType reader, VALUE parent);
13
+ static void free(WrappedType* p);
14
+ static WrappedType* unwrap(VALUE self);
15
+ static VALUE which(VALUE self);
16
+ static VALUE get(VALUE self, VALUE name);
17
+
18
+ static VALUE Class;
19
+ private:
20
+ static VALUE _get(VALUE self, VALUE name);
21
+ };
22
+ }
23
+
24
+
25
+ #endif /* DYNAMIC_STRUCT_READER_H */
@@ -0,0 +1,53 @@
1
+ #include "ruby_capn_proto.h"
2
+ #include "dynamic_value_builder.h"
3
+ #include "dynamic_list_builder.h"
4
+ #include "dynamic_struct_builder.h"
5
+ #include "dynamic_object_builder.h"
6
+
7
+ namespace ruby_capn_proto {
8
+
9
+ VALUE DynamicValueBuilder::to_ruby(capnp::DynamicValue::Builder value, VALUE parent) {
10
+ switch (value.getType())
11
+ {
12
+ case capnp::DynamicValue::BOOL:
13
+ return value.as<bool>() ? Qtrue : Qfalse;
14
+ case capnp::DynamicValue::INT:
15
+ return INT2NUM(value.as<int64_t>());
16
+ case capnp::DynamicValue::UINT:
17
+ return UINT2NUM(value.as<uint64_t>());
18
+ case capnp::DynamicValue::FLOAT:
19
+ return rb_float_new(value.as<double>());
20
+ case capnp::DynamicValue::TEXT:
21
+ {
22
+ auto text = value.as<capnp::Text>();
23
+ return rb_str_new(text.begin(), text.size());
24
+ }
25
+ case capnp::DynamicValue::DATA:
26
+ {
27
+ auto data = value.as<capnp::Data>();
28
+ return rb_str_new((const char*)data.begin(), data.size());
29
+ }
30
+ case capnp::DynamicValue::LIST:
31
+ return DynamicListBuilder::create(value.as<capnp::DynamicList>(), parent);
32
+ case capnp::DynamicValue::STRUCT:
33
+ return DynamicStructBuilder::create(value.as<capnp::DynamicStruct>(), parent, false);
34
+ case capnp::DynamicValue::ENUM:
35
+ {
36
+ auto enumerant_maybe = value.as<capnp::DynamicEnum>().getEnumerant();
37
+ KJ_IF_MAYBE(enumerant, enumerant_maybe) {
38
+ auto name = enumerant->getProto().getName();
39
+ return rb_str_new(name.begin(), name.size());
40
+ } else {
41
+ return Qnil;
42
+ }
43
+ }
44
+ case capnp::DynamicValue::ANY_POINTER:
45
+ return DynamicObjectBuilder::create(value.as<capnp::AnyPointer>(), parent);
46
+ case capnp::DynamicValue::VOID:
47
+ return Qnil;
48
+ case capnp::DynamicValue::UNKNOWN:
49
+ default:
50
+ return Qnil;
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,13 @@
1
+ #ifndef DYNAMIC_VALUE_BUILDER_H
2
+ #define DYNAMIC_VALUE_BUILDER_H
3
+
4
+ #include "ruby_capn_proto.h"
5
+
6
+ namespace ruby_capn_proto {
7
+ class DynamicValueBuilder {
8
+ public:
9
+ static VALUE to_ruby(capnp::DynamicValue::Builder value, VALUE parent);
10
+ };
11
+ }
12
+
13
+ #endif /* DYNAMIC_VALUE_BUILDER_H */
@@ -0,0 +1,55 @@
1
+ #include "ruby_capn_proto.h"
2
+ #include "dynamic_value_reader.h"
3
+ #include "dynamic_list_reader.h"
4
+ #include "dynamic_struct_reader.h"
5
+ #include "dynamic_object_reader.h"
6
+ #include "dynamic_capability_client.h"
7
+
8
+ namespace ruby_capn_proto {
9
+ VALUE DynamicValueReader::to_ruby(capnp::DynamicValue::Reader value, VALUE parent) {
10
+ switch (value.getType())
11
+ {
12
+ case capnp::DynamicValue::CAPABILITY:
13
+ return DynamicCapabilityClient::create(value.as<capnp::DynamicCapability>());
14
+ case capnp::DynamicValue::BOOL:
15
+ return value.as<bool>() ? Qtrue : Qfalse;
16
+ case capnp::DynamicValue::INT:
17
+ return INT2NUM(value.as<int64_t>());
18
+ case capnp::DynamicValue::UINT:
19
+ return UINT2NUM(value.as<uint64_t>());
20
+ case capnp::DynamicValue::FLOAT:
21
+ return rb_float_new(value.as<double>());
22
+ case capnp::DynamicValue::TEXT:
23
+ {
24
+ auto text = value.as<capnp::Text>();
25
+ return rb_str_new(text.begin(), text.size());
26
+ }
27
+ case capnp::DynamicValue::DATA:
28
+ {
29
+ auto data = value.as<capnp::Data>();
30
+ return rb_str_new((const char*)data.begin(), data.size());
31
+ }
32
+ case capnp::DynamicValue::LIST:
33
+ return DynamicListReader::create(value.as<capnp::DynamicList>(), parent);
34
+ case capnp::DynamicValue::STRUCT:
35
+ return DynamicStructReader::create(value.as<capnp::DynamicStruct>(), parent);
36
+ case capnp::DynamicValue::ENUM:
37
+ {
38
+ auto enumerant_maybe = value.as<capnp::DynamicEnum>().getEnumerant();
39
+ KJ_IF_MAYBE(enumerant, enumerant_maybe) {
40
+ auto name = enumerant->getProto().getName();
41
+ return rb_str_new(name.begin(), name.size());
42
+ } else {
43
+ return Qnil;
44
+ }
45
+ }
46
+ case capnp::DynamicValue::ANY_POINTER:
47
+ return DynamicObjectReader::create(value.as<capnp::AnyPointer>(), parent);
48
+ case capnp::DynamicValue::VOID:
49
+ return Qnil;
50
+ case capnp::DynamicValue::UNKNOWN:
51
+ default:
52
+ return Qnil;
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,13 @@
1
+ #ifndef DYNAMIC_VALUE_READER_H
2
+ #define DYNAMIC_VALUE_READER_H
3
+
4
+ #include "ruby_capn_proto.h"
5
+
6
+ namespace ruby_capn_proto {
7
+ class DynamicValueReader {
8
+ public:
9
+ static VALUE to_ruby(capnp::DynamicValue::Reader value, VALUE parent);
10
+ };
11
+ }
12
+
13
+ #endif /* DYNAMIC_VALUE_READER_H */
@@ -0,0 +1,34 @@
1
+ #include "ruby_capn_proto.h"
2
+ #include "exception.h"
3
+ #include "class_builder.h"
4
+ #include "util.h"
5
+
6
+ // VALUE rb_eException;
7
+ // VALUE rb_eStandardError;
8
+ // VALUE rb_eRuntimeError;
9
+
10
+ namespace ruby_capn_proto {
11
+ using WrappedType = kj::Exception;
12
+ VALUE Exception::Class;
13
+
14
+ void Exception::Init() {
15
+ ClassBuilder("Exception", rb_eException).
16
+ store(&Class);
17
+ }
18
+
19
+ VALUE Exception::create(WrappedType exception) {
20
+ VALUE msg = Util::toRubyString(exception.getDescription());
21
+ VALUE rb_exception = rb_funcall(Class, rb_intern("new"), 1, msg);
22
+
23
+ return rb_exception;
24
+ }
25
+
26
+ VALUE Exception::raise(WrappedType exception) {
27
+ rb_exc_raise(create(exception));
28
+ return Qnil;
29
+ }
30
+
31
+ void * Exception::raise(void * exception) {
32
+ rb_exc_raise(create(*((kj::Exception*)exception)));
33
+ }
34
+ }
@@ -0,0 +1,20 @@
1
+ #ifndef EXCEPTION_H
2
+ #define EXCEPTION_H
3
+
4
+ #include "ruby_capn_proto.h"
5
+
6
+ namespace ruby_capn_proto {
7
+ class Exception {
8
+ public:
9
+ using WrappedType = kj::Exception;
10
+ static void Init();
11
+ static VALUE create(WrappedType exception);
12
+ static VALUE raise(WrappedType exception);
13
+ static void * raise(void * exception);
14
+
15
+ static VALUE Class;
16
+ };
17
+ }
18
+
19
+
20
+ #endif /* EXCEPTION_H */
@@ -0,0 +1,32 @@
1
+ require 'mkmf'
2
+ require File.expand_path("../cxx_compiler", __FILE__)
3
+
4
+ compiler = CXXCompiler.new({'CXX' => CONFIG['CXX']}.merge(ENV.to_hash))
5
+ unless compiler.has_cxx11_compiler_support?
6
+ abort "*** A compiler with support for C++11 language features is required."
7
+ end
8
+ unless compiler.has_cxx11_library_support?
9
+ abort "*** A C++ library with support for C++11 features is required."
10
+ end
11
+
12
+ $CXXFLAGS = ' -std=c++11 '
13
+
14
+ CONFIG['CXX'] = ENV['CXX'] || CONFIG['CXX']
15
+ CONFIG['CXXFLAGS'] = [(ENV['CXXFLAGS'] || CONFIG['CXXFLAGS']),
16
+ compiler.std_flag,
17
+ compiler.stdlib_flag].join(' ')
18
+
19
+ if enable_config('debug')
20
+ CONFIG['CFLAGS'] += " -O0 -ggdb3"
21
+ else
22
+ $CPPFLAGS += " -DNDEBUG"
23
+ end
24
+
25
+ $LDFLAGS += " -lcapnpc"
26
+ $LDFLAGS += " -lcapnp"
27
+ $LDFLAGS += " -lkj"
28
+ $LDFLAGS += " -lcapnp-rpc"
29
+ $LDFLAGS += " -lkj-async"
30
+
31
+
32
+ create_makefile('capn_proto/capn_proto')
@@ -0,0 +1,51 @@
1
+ #include "ruby_capn_proto.h"
2
+ #include "field_list.h"
3
+ #include "class_builder.h"
4
+ #include "util.h"
5
+
6
+ namespace ruby_capn_proto {
7
+ using WrappedType = capnp::StructSchema::FieldList;
8
+ VALUE FieldList::Class;
9
+
10
+ void FieldList::Init() {
11
+ ClassBuilder("FieldList", rb_cObject).
12
+ defineAlloc(&alloc).
13
+ defineMethod("size", &size).
14
+ defineMethod("[]", &get).
15
+ store(&Class);
16
+ }
17
+
18
+ void FieldList::free(WrappedType* p) {
19
+ p->~FieldList();
20
+ ruby_xfree(p);
21
+ }
22
+
23
+ VALUE FieldList::alloc(VALUE klass) {
24
+ return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
25
+ }
26
+
27
+ WrappedType* FieldList::unwrap(VALUE self) {
28
+ WrappedType* p;
29
+ Data_Get_Struct(self, WrappedType, p);
30
+ return p;
31
+ }
32
+
33
+ VALUE FieldList::create(WrappedType schema) {
34
+ VALUE rb_obj = alloc(Class);
35
+ WrappedType* wrapped_schema = unwrap(rb_obj);
36
+ *wrapped_schema = kj::mv(schema);
37
+
38
+ return rb_obj;
39
+ }
40
+
41
+ VALUE FieldList::get(VALUE self, VALUE index) {
42
+ auto idx = FIX2INT(index);
43
+ auto list = *unwrap(self);
44
+ return Qnil;
45
+ // return Field::create(list[idx]);
46
+ }
47
+
48
+ VALUE FieldList::size(VALUE self) {
49
+ return INT2FIX(unwrap(self)->size());
50
+ }
51
+ }
@@ -0,0 +1,23 @@
1
+ #ifndef FIELD_LIST_H
2
+ #define FIELD_LIST_H
3
+
4
+ #include "ruby_capn_proto.h"
5
+
6
+ namespace ruby_capn_proto {
7
+ class FieldList {
8
+ public:
9
+ using WrappedType = capnp::StructSchema::FieldList;
10
+ static void Init();
11
+ static VALUE alloc(VALUE klass);
12
+ static VALUE create(WrappedType schema);
13
+ static void free(WrappedType* p);
14
+ static WrappedType* unwrap(VALUE self);
15
+ static VALUE get(VALUE self, VALUE name);
16
+ static VALUE size(VALUE self);
17
+
18
+ static VALUE Class;
19
+ };
20
+ }
21
+
22
+
23
+ #endif /* FIELD_LIST_H */
@@ -0,0 +1,61 @@
1
+ #include "ruby_capn_proto.h"
2
+ #include "message_reader.h"
3
+ #include "flat_array_message_reader.h"
4
+ #include "struct_schema.h"
5
+ #include "dynamic_struct_reader.h"
6
+ #include "class_builder.h"
7
+ #include "exception.h"
8
+
9
+ namespace ruby_capn_proto {
10
+ using WrappedType = capnp::FlatArrayMessageReader;
11
+ VALUE FlatArrayMessageReader::Class;
12
+
13
+ void FlatArrayMessageReader::Init() {
14
+ ClassBuilder("FlatArrayMessageReader", MessageReader::Class).
15
+ defineAlloc(&alloc).
16
+ defineMethod("initialize", &initialize).
17
+ defineMethod("get_root", &get_root).
18
+ store(&Class);
19
+ }
20
+
21
+ VALUE FlatArrayMessageReader::alloc(VALUE klass) {
22
+ return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
23
+ }
24
+
25
+ VALUE FlatArrayMessageReader::initialize(VALUE self, VALUE rb_buff) {
26
+ rb_iv_set(self, "buff", rb_buff);
27
+ auto str = RSTRING_PTR(rb_buff);
28
+ auto len = RSTRING_LEN(rb_buff);
29
+ kj::ArrayPtr<const capnp::word> buff((const capnp::word*)str, len/sizeof(capnp::word));
30
+
31
+ try {
32
+ WrappedType* p = unwrap(self);
33
+ new (p) WrappedType(buff);
34
+ } catch (kj::Exception ex) {
35
+ return Exception::raise(ex);
36
+ }
37
+
38
+ return Qnil;
39
+ }
40
+
41
+ void FlatArrayMessageReader::free(WrappedType* p) {
42
+ p->~FlatArrayMessageReader();
43
+ ruby_xfree(p);
44
+ }
45
+
46
+ WrappedType* FlatArrayMessageReader::unwrap(VALUE self) {
47
+ WrappedType* p;
48
+ Data_Get_Struct(self, WrappedType, p);
49
+ return p;
50
+ }
51
+
52
+ VALUE FlatArrayMessageReader::get_root(VALUE self, VALUE rb_schema) {
53
+ if (rb_respond_to(rb_schema, rb_intern("schema"))) {
54
+ rb_schema = rb_funcall(rb_schema, rb_intern("schema"), 0);
55
+ }
56
+
57
+ auto schema = *StructSchema::unwrap(rb_schema);
58
+ auto reader = unwrap(self)->getRoot<capnp::DynamicStruct>(schema);
59
+ return DynamicStructReader::create(reader, self);
60
+ }
61
+ }