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,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
|
+
}
|