self_msgproto 0.0.2 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40a52c6ccc476d31426315e0f5705366c8db1d26e1e6a1d1fcc94cee97248c44
4
- data.tar.gz: 0ed9b446cee2957b194f7269f7b4c8bf30479c0f52e283c677608518ef4a7ea5
3
+ metadata.gz: 7c24a0b872315d54cdd2c50e64492d9d8a6f528d76313d2f8de78a9576900210
4
+ data.tar.gz: 4fb4b6b2a2c6117434679d192d09d366ffc7a51b84cb8fcbfc85896519b68fbd
5
5
  SHA512:
6
- metadata.gz: e13d417e920cd568b5204d75048ff712d5a1b5bc35c0963bbb28a4361ec08e1dbbe9f3d1ed5506b283804340d75bd95465e4e28bc87196a5dbb843175fbdcc1b
7
- data.tar.gz: 7d168962441448ea61727f282dc502d7f92589a9cfdaa281bd43a80a0df7c2f486c7776059898300a0b8eb0698b4f389241a02718959772ca356038406881fe1
6
+ metadata.gz: 1d3808277b22b7383a16b1927b76ba55df6df0478d376856d0491f048295fd0a50eaad574c1384f8052019ffd124444d93040c7618244c272c231977396b3d57
7
+ data.tar.gz: 1c8919d5bb096524d892d3d0b34c23f301b59e46e0c1e014871f3724c4264a31aae38b26dfd117d418b919da4cc10852a7b26a61819faaee75c5293cd3168034
@@ -45,11 +45,13 @@ VALUE acl_initialize(int argc, VALUE *argv, VALUE self)
45
45
  VALUE commandint = rb_int2inum(command);
46
46
  rb_ivar_set(self, rb_intern("@command"), commandint);
47
47
 
48
- const u_char *payloaddata = payload->data();
49
- long payloadsize = payload->size();
48
+ if (payload != NULL) {
49
+ const u_char *payloaddata = payload->data();
50
+ long payloadsize = payload->size();
50
51
 
51
- VALUE payloadstr = rb_str_new((const char *)payloaddata, payloadsize);
52
- rb_ivar_set(self, rb_intern("@payload"), payloadstr);
52
+ VALUE payloadstr = rb_str_new((const char *)payloaddata, payloadsize);
53
+ rb_ivar_set(self, rb_intern("@payload"), payloadstr);
54
+ }
53
55
  }
54
56
 
55
57
  return self;
@@ -65,13 +67,26 @@ VALUE acl_to_fb(VALUE self)
65
67
 
66
68
  ACLCommand command;
67
69
 
68
- if (commandint < ACLCommand_MIN || commandint > ACLCommand_MAX) {
70
+ switch(commandint) {
71
+ case 0:
72
+ command = ACLCommand_LIST;
73
+ case 1:
74
+ command = ACLCommand_PERMIT;
75
+ case 2:
76
+ command = ACLCommand_REVOKE;
77
+ default:
69
78
  rb_raise(rb_eStandardError, "acl command is invalid");
70
79
  }
71
80
 
72
81
  VALUE payloadv = rb_ivar_get(self, rb_intern("@payload"));
73
- u_char *payloadstr = (u_char *)RSTRING_PTR(payloadv);
74
- long payloadlen = RSTRING_LEN(payloadv);
82
+
83
+ u_char *payloadstr;
84
+ long payloadlen;
85
+
86
+ if (payloadv != Qnil) {
87
+ payloadstr = (u_char *)RSTRING_PTR(payloadv);
88
+ payloadlen = RSTRING_LEN(payloadv);
89
+ }
75
90
 
76
91
  flatbuffers::FlatBufferBuilder builder(1024);
77
92
 
@@ -83,7 +98,10 @@ VALUE acl_to_fb(VALUE self)
83
98
  acl_builder.add_id(id);
84
99
  acl_builder.add_msgtype(MsgType_ACL);
85
100
  acl_builder.add_command(command);
86
- acl_builder.add_payload(payload);
101
+
102
+ if (payloadv != Qnil) {
103
+ acl_builder.add_payload(payload);
104
+ }
87
105
 
88
106
  auto acl = acl_builder.Finish();
89
107
  builder.Finish(acl);
@@ -102,7 +120,7 @@ void acl_init() {
102
120
  VALUE cRubySelfMsg = rb_define_module("SelfMsg");
103
121
  VALUE cAcl = rb_define_class_under(cRubySelfMsg, "Acl", rb_cObject);
104
122
 
105
- rb_define_method(cAcl, "initialize", acl_initialize, -1);
106
- rb_define_method(cAcl, "to_fb", acl_to_fb, 0);
123
+ rb_define_method(cAcl, "initialize", reinterpret_cast< VALUE ( * ) ( ... ) >(acl_initialize), -1);
124
+ rb_define_method(cAcl, "to_fb", reinterpret_cast< VALUE ( * ) ( ... ) >(acl_to_fb), 0);
107
125
  }
108
126
 
@@ -101,7 +101,7 @@ void auth_init() {
101
101
  VALUE cRubySelfMsg = rb_define_module("SelfMsg");
102
102
  VALUE cAuth = rb_define_class_under(cRubySelfMsg, "Auth", rb_cObject);
103
103
 
104
- rb_define_method(cAuth, "initialize", auth_initialize, -1);
105
- rb_define_method(cAuth, "to_fb", auth_to_fb, 0);
104
+ rb_define_method(cAuth, "initialize", reinterpret_cast< VALUE ( * ) ( ... ) >(auth_initialize), -1);
105
+ rb_define_method(cAuth, "to_fb", reinterpret_cast< VALUE ( * ) ( ... ) >(auth_to_fb), 0);
106
106
  }
107
107
 
@@ -48,6 +48,6 @@ void header_init() {
48
48
  VALUE cRubySelfMsg = rb_define_module("SelfMsg");
49
49
  VALUE cHeader = rb_define_class_under(cRubySelfMsg, "Header", rb_cObject);
50
50
 
51
- rb_define_method(cHeader, "initialize", header_initialize, -1);
51
+ rb_define_method(cHeader, "initialize", reinterpret_cast< VALUE ( * ) ( ... ) >(header_initialize), -1);
52
52
  }
53
53
 
@@ -125,7 +125,7 @@ void message_init() {
125
125
  VALUE cRubySelfMsg = rb_define_module("SelfMsg");
126
126
  VALUE cMessage = rb_define_class_under(cRubySelfMsg, "Message", rb_cObject);
127
127
 
128
- rb_define_method(cMessage, "initialize", message_initialize, -1);
129
- rb_define_method(cMessage, "to_fb", message_to_fb, 0);
128
+ rb_define_method(cMessage, "initialize", reinterpret_cast< VALUE ( * ) ( ... ) >(message_initialize), -1);
129
+ rb_define_method(cMessage, "to_fb", reinterpret_cast< VALUE ( * ) ( ... ) >(message_to_fb), 0);
130
130
  }
131
131
 
@@ -41,8 +41,10 @@ VALUE notification_initialize(int argc, VALUE *argv, VALUE self)
41
41
  VALUE mtypeint = rb_int2inum(mtype);
42
42
  rb_ivar_set(self, rb_intern("@type"), mtypeint);
43
43
 
44
- VALUE errorstr = rb_str_new(error, std::strlen(error));
45
- rb_ivar_set(self, rb_intern("@error"), errorstr);
44
+ if (ntf->error() != NULL) {
45
+ VALUE errorstr = rb_str_new(error, std::strlen(error));
46
+ rb_ivar_set(self, rb_intern("@error"), errorstr);
47
+ }
46
48
  }
47
49
 
48
50
  return self;
@@ -52,6 +54,6 @@ void notification_init() {
52
54
  VALUE cRubySelfMsg = rb_define_module("SelfMsg");
53
55
  VALUE cHeader = rb_define_class_under(cRubySelfMsg, "Notification", rb_cObject);
54
56
 
55
- rb_define_method(cHeader, "initialize", notification_initialize, -1);
57
+ rb_define_method(cHeader, "initialize", reinterpret_cast< VALUE ( * ) ( ... ) >(notification_initialize), -1);
56
58
  }
57
59
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SelfMsg
4
4
 
5
- VERSION="0.0.2"
5
+ VERSION="0.0.6"
6
6
 
7
7
  end
@@ -9,12 +9,12 @@ describe "SelfMsg" do
9
9
 
10
10
  describe "Message" do
11
11
 
12
- let(:msg){ SelfMsg::Message.new(data: "test") }
12
+ #let(:msg){ SelfMsg::Message.new(data: "test") }
13
13
 
14
- describe "#methods" do
14
+ #describe "#methods" do
15
15
 
16
- it("returns a Array"){ _(msg.methods).must_be_kind_of Array }
16
+ #it("returns a Array"){ _(msg.methods).must_be_kind_of Array }
17
17
 
18
- end
18
+ #end
19
19
  end
20
20
  end
@@ -0,0 +1,20 @@
1
+ require 'minitest/autorun'
2
+ require 'base64'
3
+ require 'self_msgproto'
4
+
5
+ class TestMessage < Minitest::Test
6
+
7
+ include SelfMsg
8
+
9
+ def test_new_acl
10
+ d = Base64.decode64('EAAAAAwAFAAMABMACwAEAAwAAAAQAAAAAAAAARQAAAAAAAAEBwAAAHBheWxvYWQAJAAAADk5NDliMWEzLWRhN2QtNGQzYy05OTMxLTlkYzkzMTJhZWI4YQAAAAA')
11
+ h = SelfMsg::Acl.new(data: d)
12
+ p h.id
13
+ p h.type
14
+ p h.command
15
+ p h.payload
16
+ end
17
+
18
+ end
19
+
20
+ #EAAAAAwAFAAMABMACwAEAAwAAAAQAAAAAAAAAQwAAAAAAAAEAAAAACQAAAA4M2I1Zjg3Zi0yYTYxLTRiM2YtOWU2Zi0yOTk5OTk3ZDdhNDgAAAAA
@@ -0,0 +1,18 @@
1
+ require 'minitest/autorun'
2
+ require 'base64'
3
+ require 'self_msgproto'
4
+
5
+ class TestMessage < Minitest::Test
6
+
7
+ include SelfMsg
8
+
9
+ def test_new_auth
10
+ d = Base64.decode64('EAAAAAwAFAAQAA8ABAAIAAwAAAAYAAAADAAAAAAAAANsAQAAAQAAADEAAABbAQAAZXlKaGJHY2lPaUpGWkVSVFFTSXNJbXRwWkNJNklpSjkuZXlKamFXUWlPaUk1TjJVM1pXUmhZeTAyWW1WaUxUUXpNalV0WVRRNE9DMWxZakkzWm1NNVkyVTBOV1VpTENKbGVIQWlPakUyTWpZNE9UY3lNRElzSW1saGRDSTZNVFl5TmpnNU56RXpOeXdpYVhOeklqb2lkR1Z6ZENJc0ltcDBhU0k2SWpKak9HRmxZalJtTFRreE9EUXROR0ZtWWkxaFpXWXlMVFZqTW1NM01qZzRabUkxWkNJc0luTjFZaUk2SW5SbGMzUWlMQ0owZVhBaU9pSmhkWFJvTG5SdmEyVnVJbjAuM0FlSXRPRzBPMWd1cTVmbjF6TGxZV3ZHelZyTmNSV2djekRFTnk4a05MLXE3NktPRDF4VVJQV2NYSFd1cDlGY3l5Z3k3dHo5cVQ1TjV4SGl0MnlWQ3cAJAAAADdkZmM0MjIzLWU2NzgtNDI1NC1iZmM5LTlkOWQxOGNlYmZjOAAAAAA')
11
+ h = SelfMsg::Auth.new(data: d)
12
+ p h.id
13
+ p h.type
14
+ p h.device
15
+ p h.token
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'minitest/autorun'
2
+ require 'base64'
3
+ require 'self_msgproto'
4
+
5
+ class TestMessage < Minitest::Test
6
+
7
+ include SelfMsg
8
+
9
+ def test_new_notification
10
+ d = Base64.decode64('DAAAAAgADAAEAAsACAAAAAgAAAAAAAABJAAAADg0Y2M1M2YwLWQ1NDUtNDk5OC1iOWIxLWRmOTdmZjNkYjRjOQAAAAA')
11
+ h = SelfMsg::Notification.new(data: d)
12
+ p h.id
13
+ p h.type
14
+ end
15
+
16
+ end
17
+
18
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: self_msgproto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Bevan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-21 00:00:00.000000000 Z
11
+ date: 2021-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rice
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- type: :development
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -109,8 +109,11 @@ files:
109
109
  - lib/self_msgproto/notification.rb
110
110
  - lib/self_msgproto/version.rb
111
111
  - test/spec/test_message.rb
112
+ - test/unit/test_acl.rb
113
+ - test/unit/test_auth.rb
112
114
  - test/unit/test_header.rb
113
115
  - test/unit/test_message.rb
116
+ - test/unit/test_notification.rb
114
117
  homepage: https://github.com/joinself/self-msgproto-ruby
115
118
  licenses:
116
119
  - MIT
@@ -136,5 +139,8 @@ specification_version: 4
136
139
  summary: Bindings for Self's Flatbuffer messaging protocol
137
140
  test_files:
138
141
  - test/unit/test_header.rb
142
+ - test/unit/test_auth.rb
143
+ - test/unit/test_acl.rb
144
+ - test/unit/test_notification.rb
139
145
  - test/unit/test_message.rb
140
146
  - test/spec/test_message.rb