self_msgproto 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/self_msgproto/acl.cpp +21 -10
- data/ext/self_msgproto/auth.cpp +2 -2
- data/ext/self_msgproto/header.cpp +1 -1
- data/ext/self_msgproto/message.cpp +2 -2
- data/ext/self_msgproto/notification.cpp +5 -3
- data/lib/self_msgproto.rb +11 -0
- data/lib/self_msgproto/version.rb +1 -1
- data/test/spec/test_message.rb +4 -4
- data/test/unit/test_acl.rb +20 -0
- data/test/unit/test_auth.rb +18 -0
- data/test/unit/test_notification.rb +18 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0b31d30e9104bcdb37adfe3c1ac5cafc5ab8db54cd40b2424e34b047e0296db
|
4
|
+
data.tar.gz: 820acdeff754f6c9f7961591c7c4b138cb2ad1337957a20072c8ddbb597c76bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 314c1fcecdb84da0aeba491ebda587d95724d20a2a286d2dc6d1f4cabf346d810af26b0962cec448cc98515fe016e311fd1e80fcf342be5c0925ac25c8c12e53
|
7
|
+
data.tar.gz: 9fe32a3c8f76b1d052c13ee9812de38ba5873e686d28d5fa55d779fface5e9622e6c52a0eb5584915332855cf9026d2826c89c89d30c1de130c9067f9fd3e3bd
|
data/ext/self_msgproto/acl.cpp
CHANGED
@@ -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
|
-
|
49
|
-
|
48
|
+
if (payload != NULL) {
|
49
|
+
const u_char *payloaddata = payload->data();
|
50
|
+
long payloadsize = payload->size();
|
50
51
|
|
51
|
-
|
52
|
-
|
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,19 @@ VALUE acl_to_fb(VALUE self)
|
|
65
67
|
|
66
68
|
ACLCommand command;
|
67
69
|
|
68
|
-
if (commandint
|
70
|
+
if (commandint > ACLCommand_MAX) {
|
69
71
|
rb_raise(rb_eStandardError, "acl command is invalid");
|
70
72
|
}
|
71
73
|
|
72
74
|
VALUE payloadv = rb_ivar_get(self, rb_intern("@payload"));
|
73
|
-
|
74
|
-
|
75
|
+
|
76
|
+
u_char *payloadstr;
|
77
|
+
long payloadlen;
|
78
|
+
|
79
|
+
if (payloadv != Qnil) {
|
80
|
+
payloadstr = (u_char *)RSTRING_PTR(payloadv);
|
81
|
+
payloadlen = RSTRING_LEN(payloadv);
|
82
|
+
}
|
75
83
|
|
76
84
|
flatbuffers::FlatBufferBuilder builder(1024);
|
77
85
|
|
@@ -83,7 +91,10 @@ VALUE acl_to_fb(VALUE self)
|
|
83
91
|
acl_builder.add_id(id);
|
84
92
|
acl_builder.add_msgtype(MsgType_ACL);
|
85
93
|
acl_builder.add_command(command);
|
86
|
-
|
94
|
+
|
95
|
+
if (payloadv != Qnil) {
|
96
|
+
acl_builder.add_payload(payload);
|
97
|
+
}
|
87
98
|
|
88
99
|
auto acl = acl_builder.Finish();
|
89
100
|
builder.Finish(acl);
|
@@ -102,7 +113,7 @@ void acl_init() {
|
|
102
113
|
VALUE cRubySelfMsg = rb_define_module("SelfMsg");
|
103
114
|
VALUE cAcl = rb_define_class_under(cRubySelfMsg, "Acl", rb_cObject);
|
104
115
|
|
105
|
-
rb_define_method(cAcl, "initialize", acl_initialize, -1);
|
106
|
-
rb_define_method(cAcl, "to_fb", acl_to_fb, 0);
|
116
|
+
rb_define_method(cAcl, "initialize", reinterpret_cast< VALUE ( * ) ( ... ) >(acl_initialize), -1);
|
117
|
+
rb_define_method(cAcl, "to_fb", reinterpret_cast< VALUE ( * ) ( ... ) >(acl_to_fb), 0);
|
107
118
|
}
|
108
119
|
|
data/ext/self_msgproto/auth.cpp
CHANGED
@@ -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
|
-
|
45
|
-
|
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
|
|
data/lib/self_msgproto.rb
CHANGED
@@ -9,4 +9,15 @@ require 'self_msgproto/notification'
|
|
9
9
|
require 'self_msgproto/self_msgproto'
|
10
10
|
|
11
11
|
module SelfMsg
|
12
|
+
|
13
|
+
MsgTypeMSG = 0
|
14
|
+
MsgTypeACK = 1
|
15
|
+
MsgTypeERR = 2
|
16
|
+
MsgTypeAUTH = 3
|
17
|
+
MsgTypeACL = 4
|
18
|
+
|
19
|
+
AclCommandLIST = 0
|
20
|
+
AclCommandPERMIT = 1
|
21
|
+
AclCommandREVOKE = 2
|
22
|
+
|
12
23
|
end
|
data/test/spec/test_message.rb
CHANGED
@@ -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.
|
4
|
+
version: 0.0.5
|
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-
|
11
|
+
date: 2021-07-22 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: :
|
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
|