self_msgproto 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cab7cc6b6f6a48df982c1ee3d9b170e85cfd55178f79bdab9e6ced5676f52199
4
- data.tar.gz: 88f152ebe1b13969258c96be8d1fb98036a51509957e236bdf2ece2a15c18389
3
+ metadata.gz: 48e361d23d4dcd09aca2e053666f340703bc99c345991700203acc0a7135cc4f
4
+ data.tar.gz: 8c8320a08ee30316c4d82d64b8b480bc4afba8758ae596f3de374d3f4dde8965
5
5
  SHA512:
6
- metadata.gz: 7903916cb4d14f524c312b582b92b19d18094a582df509ae8e2cb3df8621d2b852dae659d6faf306b6402a4335c96faed5309495e997ee80cb93095baedc1255
7
- data.tar.gz: 84fa5070a8d235c1e42ca4b8a93407861288b3ccb62ac307dadebb62482055afbdeca52907aaa3bae85341d29a04bc397e1f5de82694715ddc48deb78d50a370
6
+ metadata.gz: acab917323d1f4f8c3c614230f6e9b22b476d6a1931fd1b53fb1b0e1700ab2462b32e01d888397b231ab3dc30e32ebfffc2dd80149a0e58a07fb4cca4f5de985
7
+ data.tar.gz: 19fd66580d5afad7ef089b3dfd4f6dd32c5dde613d51e24ca0072312e7fc75979273b7d17022edbfdcee2e942dd9fcf2530a5ef69519ee6e8fde07aed26dc0b5
@@ -35,41 +35,50 @@ VALUE message_initialize(int argc, VALUE *argv, VALUE self)
35
35
 
36
36
  auto id = msg->id()->c_str();
37
37
  auto mtype = msg->msgtype();
38
- auto stype = msg->subtype();
39
38
  auto sender = msg->sender()->c_str();
40
39
  auto recipient = msg->recipient()->c_str();
41
40
  auto ciphertext = msg->ciphertext();
42
41
  auto metadata = msg->metadata();
42
+ auto message_type = msg->message_type();
43
+ auto priority = msg->priority();
43
44
 
44
45
  auto offset = metadata->offset();
45
46
  auto timestamp = metadata->timestamp();
46
47
 
47
- VALUE idstr = rb_str_new(id, std::strlen(id));
48
- rb_ivar_set(self, rb_intern("@id"), idstr);
48
+ VALUE id_str = rb_str_new(id, std::strlen(id));
49
+ rb_ivar_set(self, rb_intern("@id"), id_str);
49
50
 
50
- VALUE mtypeint = rb_int2inum(mtype);
51
- rb_ivar_set(self, rb_intern("@type"), mtypeint);
51
+ VALUE mtype_int = rb_int2inum(mtype);
52
+ rb_ivar_set(self, rb_intern("@type"), mtype_int);
52
53
 
53
- VALUE stypeint = rb_int2inum(stype);
54
- rb_ivar_set(self, rb_intern("@subtype"), stypeint);
54
+ VALUE offset_int = rb_int2inum(offset);
55
+ rb_ivar_set(self, rb_intern("@offset"), offset_int);
55
56
 
56
- VALUE offsetint = rb_int2inum(offset);
57
- rb_ivar_set(self, rb_intern("@offset"), offsetint);
57
+ VALUE priority_int = rb_int2inum(priority);
58
+ rb_ivar_set(self, rb_intern("@priority"), priority_int);
58
59
 
59
- VALUE timestampint = rb_int2inum(timestamp);
60
- rb_ivar_set(self, rb_intern("@timestamp"), timestampint);
60
+ VALUE timestamp_int = rb_int2inum(timestamp);
61
+ rb_ivar_set(self, rb_intern("@timestamp"), timestamp_int);
61
62
 
62
- VALUE senderstr = rb_str_new(sender, std::strlen(sender));
63
- rb_ivar_set(self, rb_intern("@sender"), senderstr);
63
+ VALUE sender_str = rb_str_new(sender, std::strlen(sender));
64
+ rb_ivar_set(self, rb_intern("@sender"), sender_str);
64
65
 
65
- VALUE recipientstr = rb_str_new(recipient, std::strlen(recipient));
66
- rb_ivar_set(self, rb_intern("@recipient"), recipientstr);
66
+ VALUE recipient_str = rb_str_new(recipient, std::strlen(recipient));
67
+ rb_ivar_set(self, rb_intern("@recipient"), recipient_str);
67
68
 
68
- const u_char *ciphertextdata = ciphertext->data();
69
- long ciphertextsize = ciphertext->size();
69
+ if (message_type != NULL) {
70
+ const u_char *message_type_data = message_type->data();
71
+ long message_type_size = message_type->size();
70
72
 
71
- VALUE ciphertextstr = rb_str_new((const char *)ciphertextdata, ciphertextsize);
72
- rb_ivar_set(self, rb_intern("@ciphertext"), ciphertextstr);
73
+ VALUE message_type_str = rb_str_new((const char *)message_type_data, message_type_size);
74
+ rb_ivar_set(self, rb_intern("@message_type"), message_type_str);
75
+ }
76
+
77
+ const u_char *ciphertext_data = ciphertext->data();
78
+ long ciphertext_size = ciphertext->size();
79
+
80
+ VALUE ciphertext_str = rb_str_new((const char *)ciphertext_data, ciphertext_size);
81
+ rb_ivar_set(self, rb_intern("@ciphertext"), ciphertext_str);
73
82
  }
74
83
 
75
84
  return self;
@@ -77,25 +86,43 @@ VALUE message_initialize(int argc, VALUE *argv, VALUE self)
77
86
 
78
87
  VALUE message_to_fb(VALUE self)
79
88
  {
80
- VALUE idv = rb_ivar_get(self, rb_intern("@id"));
81
- char *idstr = RSTRING_PTR(idv);
89
+ flatbuffers::Offset<flatbuffers::Vector<uint8_t>> message_type;
90
+ u_char *message_type_str;
91
+ long message_type_len;
92
+
93
+ VALUE id_v = rb_ivar_get(self, rb_intern("@id"));
94
+ char *id_str = RSTRING_PTR(id_v);
95
+
96
+ VALUE sender_v = rb_ivar_get(self, rb_intern("@sender"));
97
+ char *sender_str = RSTRING_PTR(sender_v);
98
+
99
+ VALUE recipient_v = rb_ivar_get(self, rb_intern("@recipient"));
100
+ char *recipient_str = RSTRING_PTR(recipient_v);
82
101
 
83
- VALUE senderv = rb_ivar_get(self, rb_intern("@sender"));
84
- char *senderstr = RSTRING_PTR(senderv);
102
+ VALUE priority_v = rb_ivar_get(self, rb_intern("@priority"));
103
+ uint32_t priority = NUM2ULL(priority_v);
85
104
 
86
- VALUE recipientv = rb_ivar_get(self, rb_intern("@recipient"));
87
- char *recipientstr = RSTRING_PTR(recipientv);
105
+ VALUE message_type_v = rb_ivar_get(self, rb_intern("@message_type"));
88
106
 
89
- VALUE ciphertextv = rb_ivar_get(self, rb_intern("@ciphertext"));
90
- u_char *ciphertextstr = (u_char *)RSTRING_PTR(ciphertextv);
91
- long ciphertextlen = RSTRING_LEN(ciphertextv);
107
+ if (message_type_v != Qnil) {
108
+ u_char *message_type_str = (u_char *)RSTRING_PTR(message_type_v);
109
+ long message_type_len = RSTRING_LEN(message_type_v);
110
+ }
111
+
112
+ VALUE ciphertext_v = rb_ivar_get(self, rb_intern("@ciphertext"));
113
+ u_char *ciphertext_str = (u_char *)RSTRING_PTR(ciphertext_v);
114
+ long ciphertext_len = RSTRING_LEN(ciphertext_v);
92
115
 
93
116
  flatbuffers::FlatBufferBuilder builder(1024);
94
117
 
95
- auto id = builder.CreateString(idstr);
96
- auto sender = builder.CreateString(senderstr);
97
- auto recipient = builder.CreateString(recipientstr);
98
- auto ciphertext = builder.CreateVector(ciphertextstr, ciphertextlen);
118
+ auto id = builder.CreateString(id_str);
119
+ auto sender = builder.CreateString(sender_str);
120
+ auto recipient = builder.CreateString(recipient_str);
121
+ auto ciphertext = builder.CreateVector(ciphertext_str, ciphertext_len);
122
+
123
+ if (message_type_v != Qnil) {
124
+ message_type = builder.CreateVector(message_type_str, message_type_len);
125
+ }
99
126
 
100
127
  SelfMessaging::Metadata metadata(0, 0);
101
128
 
@@ -107,6 +134,11 @@ VALUE message_to_fb(VALUE self)
107
134
  msg_builder.add_recipient(recipient);
108
135
  msg_builder.add_ciphertext(ciphertext);
109
136
  msg_builder.add_metadata(&metadata);
137
+ msg_builder.add_priority(priority);
138
+
139
+ if (message_type_v != Qnil) {
140
+ msg_builder.add_message_type(message_type);
141
+ }
110
142
 
111
143
  auto msg = msg_builder.Finish();
112
144
  builder.Finish(msg);
@@ -32,15 +32,9 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Metadata FLATBUFFERS_FINAL_CLASS {
32
32
  int64_t timestamp() const {
33
33
  return flatbuffers::EndianScalar(timestamp_);
34
34
  }
35
- void mutate_timestamp(int64_t _timestamp) {
36
- flatbuffers::WriteScalar(&timestamp_, _timestamp);
37
- }
38
35
  int64_t offset() const {
39
36
  return flatbuffers::EndianScalar(offset_);
40
37
  }
41
- void mutate_offset(int64_t _offset) {
42
- flatbuffers::WriteScalar(&offset_, _offset);
43
- }
44
38
  };
45
39
  FLATBUFFERS_STRUCT_END(Metadata, 16);
46
40
 
@@ -53,49 +47,44 @@ struct Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
53
47
  VT_SENDER = 10,
54
48
  VT_RECIPIENT = 12,
55
49
  VT_METADATA = 14,
56
- VT_CIPHERTEXT = 16
50
+ VT_CIPHERTEXT = 16,
51
+ VT_PRIORITY = 20,
52
+ VT_MESSAGE_TYPE = 22,
53
+ VT_COLLAPSE_KEY = 24,
54
+ VT_NOTIFICATION_PAYLOAD = 26
57
55
  };
58
56
  const flatbuffers::String *id() const {
59
57
  return GetPointer<const flatbuffers::String *>(VT_ID);
60
58
  }
61
- flatbuffers::String *mutable_id() {
62
- return GetPointer<flatbuffers::String *>(VT_ID);
63
- }
64
59
  SelfMessaging::MsgType msgtype() const {
65
60
  return static_cast<SelfMessaging::MsgType>(GetField<int8_t>(VT_MSGTYPE, 0));
66
61
  }
67
- bool mutate_msgtype(SelfMessaging::MsgType _msgtype) {
68
- return SetField<int8_t>(VT_MSGTYPE, static_cast<int8_t>(_msgtype), 0);
69
- }
70
62
  SelfMessaging::MsgSubType subtype() const {
71
63
  return static_cast<SelfMessaging::MsgSubType>(GetField<uint16_t>(VT_SUBTYPE, 0));
72
64
  }
73
- bool mutate_subtype(SelfMessaging::MsgSubType _subtype) {
74
- return SetField<uint16_t>(VT_SUBTYPE, static_cast<uint16_t>(_subtype), 0);
75
- }
76
65
  const flatbuffers::String *sender() const {
77
66
  return GetPointer<const flatbuffers::String *>(VT_SENDER);
78
67
  }
79
- flatbuffers::String *mutable_sender() {
80
- return GetPointer<flatbuffers::String *>(VT_SENDER);
81
- }
82
68
  const flatbuffers::String *recipient() const {
83
69
  return GetPointer<const flatbuffers::String *>(VT_RECIPIENT);
84
70
  }
85
- flatbuffers::String *mutable_recipient() {
86
- return GetPointer<flatbuffers::String *>(VT_RECIPIENT);
87
- }
88
71
  const SelfMessaging::Metadata *metadata() const {
89
72
  return GetStruct<const SelfMessaging::Metadata *>(VT_METADATA);
90
73
  }
91
- SelfMessaging::Metadata *mutable_metadata() {
92
- return GetStruct<SelfMessaging::Metadata *>(VT_METADATA);
93
- }
94
74
  const flatbuffers::Vector<uint8_t> *ciphertext() const {
95
75
  return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_CIPHERTEXT);
96
76
  }
97
- flatbuffers::Vector<uint8_t> *mutable_ciphertext() {
98
- return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_CIPHERTEXT);
77
+ uint32_t priority() const {
78
+ return GetField<uint32_t>(VT_PRIORITY, 0);
79
+ }
80
+ const flatbuffers::Vector<uint8_t> *message_type() const {
81
+ return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_MESSAGE_TYPE);
82
+ }
83
+ const flatbuffers::Vector<uint8_t> *collapse_key() const {
84
+ return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_COLLAPSE_KEY);
85
+ }
86
+ const flatbuffers::Vector<uint8_t> *notification_payload() const {
87
+ return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_NOTIFICATION_PAYLOAD);
99
88
  }
100
89
  bool Verify(flatbuffers::Verifier &verifier) const {
101
90
  return VerifyTableStart(verifier) &&
@@ -110,6 +99,13 @@ struct Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
110
99
  VerifyFieldRequired<SelfMessaging::Metadata>(verifier, VT_METADATA) &&
111
100
  VerifyOffset(verifier, VT_CIPHERTEXT) &&
112
101
  verifier.VerifyVector(ciphertext()) &&
102
+ VerifyField<uint32_t>(verifier, VT_PRIORITY) &&
103
+ VerifyOffset(verifier, VT_MESSAGE_TYPE) &&
104
+ verifier.VerifyVector(message_type()) &&
105
+ VerifyOffset(verifier, VT_COLLAPSE_KEY) &&
106
+ verifier.VerifyVector(collapse_key()) &&
107
+ VerifyOffset(verifier, VT_NOTIFICATION_PAYLOAD) &&
108
+ verifier.VerifyVector(notification_payload()) &&
113
109
  verifier.EndTable();
114
110
  }
115
111
  };
@@ -139,6 +135,18 @@ struct MessageBuilder {
139
135
  void add_ciphertext(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> ciphertext) {
140
136
  fbb_.AddOffset(Message::VT_CIPHERTEXT, ciphertext);
141
137
  }
138
+ void add_priority(uint32_t priority) {
139
+ fbb_.AddElement<uint32_t>(Message::VT_PRIORITY, priority, 0);
140
+ }
141
+ void add_message_type(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> message_type) {
142
+ fbb_.AddOffset(Message::VT_MESSAGE_TYPE, message_type);
143
+ }
144
+ void add_collapse_key(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> collapse_key) {
145
+ fbb_.AddOffset(Message::VT_COLLAPSE_KEY, collapse_key);
146
+ }
147
+ void add_notification_payload(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> notification_payload) {
148
+ fbb_.AddOffset(Message::VT_NOTIFICATION_PAYLOAD, notification_payload);
149
+ }
142
150
  explicit MessageBuilder(flatbuffers::FlatBufferBuilder &_fbb)
143
151
  : fbb_(_fbb) {
144
152
  start_ = fbb_.StartTable();
@@ -159,8 +167,16 @@ inline flatbuffers::Offset<Message> CreateMessage(
159
167
  flatbuffers::Offset<flatbuffers::String> sender = 0,
160
168
  flatbuffers::Offset<flatbuffers::String> recipient = 0,
161
169
  const SelfMessaging::Metadata *metadata = 0,
162
- flatbuffers::Offset<flatbuffers::Vector<uint8_t>> ciphertext = 0) {
170
+ flatbuffers::Offset<flatbuffers::Vector<uint8_t>> ciphertext = 0,
171
+ uint32_t priority = 0,
172
+ flatbuffers::Offset<flatbuffers::Vector<uint8_t>> message_type = 0,
173
+ flatbuffers::Offset<flatbuffers::Vector<uint8_t>> collapse_key = 0,
174
+ flatbuffers::Offset<flatbuffers::Vector<uint8_t>> notification_payload = 0) {
163
175
  MessageBuilder builder_(_fbb);
176
+ builder_.add_notification_payload(notification_payload);
177
+ builder_.add_collapse_key(collapse_key);
178
+ builder_.add_message_type(message_type);
179
+ builder_.add_priority(priority);
164
180
  builder_.add_ciphertext(ciphertext);
165
181
  builder_.add_metadata(metadata);
166
182
  builder_.add_recipient(recipient);
@@ -179,11 +195,18 @@ inline flatbuffers::Offset<Message> CreateMessageDirect(
179
195
  const char *sender = nullptr,
180
196
  const char *recipient = nullptr,
181
197
  const SelfMessaging::Metadata *metadata = 0,
182
- const std::vector<uint8_t> *ciphertext = nullptr) {
198
+ const std::vector<uint8_t> *ciphertext = nullptr,
199
+ uint32_t priority = 0,
200
+ const std::vector<uint8_t> *message_type = nullptr,
201
+ const std::vector<uint8_t> *collapse_key = nullptr,
202
+ const std::vector<uint8_t> *notification_payload = nullptr) {
183
203
  auto id__ = id ? _fbb.CreateString(id) : 0;
184
204
  auto sender__ = sender ? _fbb.CreateString(sender) : 0;
185
205
  auto recipient__ = recipient ? _fbb.CreateString(recipient) : 0;
186
206
  auto ciphertext__ = ciphertext ? _fbb.CreateVector<uint8_t>(*ciphertext) : 0;
207
+ auto message_type__ = message_type ? _fbb.CreateVector<uint8_t>(*message_type) : 0;
208
+ auto collapse_key__ = collapse_key ? _fbb.CreateVector<uint8_t>(*collapse_key) : 0;
209
+ auto notification_payload__ = notification_payload ? _fbb.CreateVector<uint8_t>(*notification_payload) : 0;
187
210
  return SelfMessaging::CreateMessage(
188
211
  _fbb,
189
212
  id__,
@@ -192,7 +215,11 @@ inline flatbuffers::Offset<Message> CreateMessageDirect(
192
215
  sender__,
193
216
  recipient__,
194
217
  metadata,
195
- ciphertext__);
218
+ ciphertext__,
219
+ priority,
220
+ message_type__,
221
+ collapse_key__,
222
+ notification_payload__);
196
223
  }
197
224
 
198
225
  inline const SelfMessaging::Message *GetMessage(const void *buf) {
@@ -203,10 +230,6 @@ inline const SelfMessaging::Message *GetSizePrefixedMessage(const void *buf) {
203
230
  return flatbuffers::GetSizePrefixedRoot<SelfMessaging::Message>(buf);
204
231
  }
205
232
 
206
- inline Message *GetMutableMessage(void *buf) {
207
- return flatbuffers::GetMutableRoot<Message>(buf);
208
- }
209
-
210
233
  inline bool VerifyMessageBuffer(
211
234
  flatbuffers::Verifier &verifier) {
212
235
  return verifier.VerifyBuffer<SelfMessaging::Message>(nullptr);
@@ -3,7 +3,7 @@
3
3
  module SelfMsg
4
4
 
5
5
  class Message
6
- attr_accessor :id, :type, :subtype, :sender, :recipient, :ciphertext
6
+ attr_accessor :id, :type, :sender, :recipient, :ciphertext, :message_type, :priority
7
7
  attr_reader :timestamp, :offset
8
8
  end
9
9
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SelfMsg
4
4
 
5
- VERSION="0.0.8"
5
+ VERSION="0.0.9"
6
6
 
7
7
  end
@@ -7,16 +7,18 @@ class TestMessage < Minitest::Test
7
7
  include SelfMsg
8
8
 
9
9
  def test_new_message
10
- d = Base64.decode64('GAAAAAAAEgAkACAAAAAAABwAGAAIAAQAEgAAACAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAABwAAAAkAAAABAAAAHRlc3QHAAAAYWxpY2U6MQAGAAAAdGVzdDoxAAAkAAAAOWEwZjZjNjktMmI2ZS00YjA2LTg3MWUtMGM1YmFhOTJiYzk2AAAAAA')
10
+ d = Base64.decode64('HAAAABgALAAoAAAAAAAkACAADAAcAAAACAAEABgAAAAoAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAGAAAACAAAAAoAAAAAAAAAAQAAAB0ZXN0BwAAAGFsaWNlOjEABgAAAHRlc3Q6MQAAJAAAADlhMGY2YzY5LTJiNmUtNGIwNi04NzFlLTBjNWJhYTkyYmM5NgAAAAA')
11
11
  m = SelfMsg::Message.new(data: d)
12
+
12
13
  p m.id
13
14
  p m.type
14
- p m.subtype
15
15
  p m.offset
16
16
  p m.timestamp
17
17
  p m.sender
18
18
  p m.recipient
19
19
  p m.ciphertext
20
+ p m.message_type
21
+ p m.priority
20
22
 
21
23
  p m.to_fb
22
24
  end
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.8
4
+ version: 0.0.9
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-09-16 00:00:00.000000000 Z
11
+ date: 2022-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rice
@@ -133,14 +133,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  requirements: []
136
- rubygems_version: 3.2.5
136
+ rubygems_version: 3.3.5
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: Bindings for Self's Flatbuffer messaging protocol
140
140
  test_files:
141
- - test/unit/test_header.rb
142
- - test/unit/test_auth.rb
141
+ - test/spec/test_message.rb
143
142
  - test/unit/test_acl.rb
144
- - test/unit/test_notification.rb
143
+ - test/unit/test_auth.rb
144
+ - test/unit/test_header.rb
145
145
  - test/unit/test_message.rb
146
- - test/spec/test_message.rb
146
+ - test/unit/test_notification.rb