self_msgproto 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +19 -0
- data/ext/self_msgproto/acl.cpp +108 -0
- data/ext/self_msgproto/auth.cpp +107 -0
- data/ext/self_msgproto/extconf.rb +11 -0
- data/ext/self_msgproto/header.cpp +53 -0
- data/ext/self_msgproto/message.cpp +131 -0
- data/ext/self_msgproto/msgproto/acl_generated.h +137 -0
- data/ext/self_msgproto/msgproto/auth_generated.h +151 -0
- data/ext/self_msgproto/msgproto/header_generated.h +111 -0
- data/ext/self_msgproto/msgproto/message_generated.h +234 -0
- data/ext/self_msgproto/msgproto/notification_generated.h +137 -0
- data/ext/self_msgproto/msgproto/types_generated.h +208 -0
- data/ext/self_msgproto/notification.cpp +57 -0
- data/ext/self_msgproto/self_msgproto.cpp +21 -0
- data/lib/self_msgproto.rb +12 -0
- data/lib/self_msgproto/acl.rb +9 -0
- data/lib/self_msgproto/auth.rb +9 -0
- data/lib/self_msgproto/header.rb +9 -0
- data/lib/self_msgproto/message.rb +10 -0
- data/lib/self_msgproto/notification.rb +9 -0
- data/lib/self_msgproto/version.rb +7 -0
- data/test/spec/test_message.rb +20 -0
- data/test/unit/test_header.rb +16 -0
- data/test/unit/test_message.rb +24 -0
- metadata +140 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
// automatically generated by the FlatBuffers compiler, do not modify
|
2
|
+
|
3
|
+
|
4
|
+
#ifndef FLATBUFFERS_GENERATED_NOTIFICATION_SELFMESSAGING_H_
|
5
|
+
#define FLATBUFFERS_GENERATED_NOTIFICATION_SELFMESSAGING_H_
|
6
|
+
|
7
|
+
#include "flatbuffers/flatbuffers.h"
|
8
|
+
|
9
|
+
#include "types_generated.h"
|
10
|
+
|
11
|
+
namespace SelfMessaging {
|
12
|
+
|
13
|
+
struct Notification;
|
14
|
+
struct NotificationBuilder;
|
15
|
+
|
16
|
+
struct Notification FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
17
|
+
typedef NotificationBuilder Builder;
|
18
|
+
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
19
|
+
VT_ID = 4,
|
20
|
+
VT_MSGTYPE = 6,
|
21
|
+
VT_ERROR = 8,
|
22
|
+
VT_ERRTYPE = 10
|
23
|
+
};
|
24
|
+
const flatbuffers::String *id() const {
|
25
|
+
return GetPointer<const flatbuffers::String *>(VT_ID);
|
26
|
+
}
|
27
|
+
SelfMessaging::MsgType msgtype() const {
|
28
|
+
return static_cast<SelfMessaging::MsgType>(GetField<int8_t>(VT_MSGTYPE, 0));
|
29
|
+
}
|
30
|
+
const flatbuffers::String *error() const {
|
31
|
+
return GetPointer<const flatbuffers::String *>(VT_ERROR);
|
32
|
+
}
|
33
|
+
SelfMessaging::ErrType errtype() const {
|
34
|
+
return static_cast<SelfMessaging::ErrType>(GetField<int8_t>(VT_ERRTYPE, 0));
|
35
|
+
}
|
36
|
+
bool Verify(flatbuffers::Verifier &verifier) const {
|
37
|
+
return VerifyTableStart(verifier) &&
|
38
|
+
VerifyOffset(verifier, VT_ID) &&
|
39
|
+
verifier.VerifyString(id()) &&
|
40
|
+
VerifyField<int8_t>(verifier, VT_MSGTYPE) &&
|
41
|
+
VerifyOffset(verifier, VT_ERROR) &&
|
42
|
+
verifier.VerifyString(error()) &&
|
43
|
+
VerifyField<int8_t>(verifier, VT_ERRTYPE) &&
|
44
|
+
verifier.EndTable();
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
48
|
+
struct NotificationBuilder {
|
49
|
+
typedef Notification Table;
|
50
|
+
flatbuffers::FlatBufferBuilder &fbb_;
|
51
|
+
flatbuffers::uoffset_t start_;
|
52
|
+
void add_id(flatbuffers::Offset<flatbuffers::String> id) {
|
53
|
+
fbb_.AddOffset(Notification::VT_ID, id);
|
54
|
+
}
|
55
|
+
void add_msgtype(SelfMessaging::MsgType msgtype) {
|
56
|
+
fbb_.AddElement<int8_t>(Notification::VT_MSGTYPE, static_cast<int8_t>(msgtype), 0);
|
57
|
+
}
|
58
|
+
void add_error(flatbuffers::Offset<flatbuffers::String> error) {
|
59
|
+
fbb_.AddOffset(Notification::VT_ERROR, error);
|
60
|
+
}
|
61
|
+
void add_errtype(SelfMessaging::ErrType errtype) {
|
62
|
+
fbb_.AddElement<int8_t>(Notification::VT_ERRTYPE, static_cast<int8_t>(errtype), 0);
|
63
|
+
}
|
64
|
+
explicit NotificationBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
65
|
+
: fbb_(_fbb) {
|
66
|
+
start_ = fbb_.StartTable();
|
67
|
+
}
|
68
|
+
flatbuffers::Offset<Notification> Finish() {
|
69
|
+
const auto end = fbb_.EndTable(start_);
|
70
|
+
auto o = flatbuffers::Offset<Notification>(end);
|
71
|
+
return o;
|
72
|
+
}
|
73
|
+
};
|
74
|
+
|
75
|
+
inline flatbuffers::Offset<Notification> CreateNotification(
|
76
|
+
flatbuffers::FlatBufferBuilder &_fbb,
|
77
|
+
flatbuffers::Offset<flatbuffers::String> id = 0,
|
78
|
+
SelfMessaging::MsgType msgtype = SelfMessaging::MsgType_MSG,
|
79
|
+
flatbuffers::Offset<flatbuffers::String> error = 0,
|
80
|
+
SelfMessaging::ErrType errtype = SelfMessaging::ErrType_ErrConnection) {
|
81
|
+
NotificationBuilder builder_(_fbb);
|
82
|
+
builder_.add_error(error);
|
83
|
+
builder_.add_id(id);
|
84
|
+
builder_.add_errtype(errtype);
|
85
|
+
builder_.add_msgtype(msgtype);
|
86
|
+
return builder_.Finish();
|
87
|
+
}
|
88
|
+
|
89
|
+
inline flatbuffers::Offset<Notification> CreateNotificationDirect(
|
90
|
+
flatbuffers::FlatBufferBuilder &_fbb,
|
91
|
+
const char *id = nullptr,
|
92
|
+
SelfMessaging::MsgType msgtype = SelfMessaging::MsgType_MSG,
|
93
|
+
const char *error = nullptr,
|
94
|
+
SelfMessaging::ErrType errtype = SelfMessaging::ErrType_ErrConnection) {
|
95
|
+
auto id__ = id ? _fbb.CreateString(id) : 0;
|
96
|
+
auto error__ = error ? _fbb.CreateString(error) : 0;
|
97
|
+
return SelfMessaging::CreateNotification(
|
98
|
+
_fbb,
|
99
|
+
id__,
|
100
|
+
msgtype,
|
101
|
+
error__,
|
102
|
+
errtype);
|
103
|
+
}
|
104
|
+
|
105
|
+
inline const SelfMessaging::Notification *GetNotification(const void *buf) {
|
106
|
+
return flatbuffers::GetRoot<SelfMessaging::Notification>(buf);
|
107
|
+
}
|
108
|
+
|
109
|
+
inline const SelfMessaging::Notification *GetSizePrefixedNotification(const void *buf) {
|
110
|
+
return flatbuffers::GetSizePrefixedRoot<SelfMessaging::Notification>(buf);
|
111
|
+
}
|
112
|
+
|
113
|
+
inline bool VerifyNotificationBuffer(
|
114
|
+
flatbuffers::Verifier &verifier) {
|
115
|
+
return verifier.VerifyBuffer<SelfMessaging::Notification>(nullptr);
|
116
|
+
}
|
117
|
+
|
118
|
+
inline bool VerifySizePrefixedNotificationBuffer(
|
119
|
+
flatbuffers::Verifier &verifier) {
|
120
|
+
return verifier.VerifySizePrefixedBuffer<SelfMessaging::Notification>(nullptr);
|
121
|
+
}
|
122
|
+
|
123
|
+
inline void FinishNotificationBuffer(
|
124
|
+
flatbuffers::FlatBufferBuilder &fbb,
|
125
|
+
flatbuffers::Offset<SelfMessaging::Notification> root) {
|
126
|
+
fbb.Finish(root);
|
127
|
+
}
|
128
|
+
|
129
|
+
inline void FinishSizePrefixedNotificationBuffer(
|
130
|
+
flatbuffers::FlatBufferBuilder &fbb,
|
131
|
+
flatbuffers::Offset<SelfMessaging::Notification> root) {
|
132
|
+
fbb.FinishSizePrefixed(root);
|
133
|
+
}
|
134
|
+
|
135
|
+
} // namespace SelfMessaging
|
136
|
+
|
137
|
+
#endif // FLATBUFFERS_GENERATED_NOTIFICATION_SELFMESSAGING_H_
|
@@ -0,0 +1,208 @@
|
|
1
|
+
// automatically generated by the FlatBuffers compiler, do not modify
|
2
|
+
|
3
|
+
|
4
|
+
#ifndef FLATBUFFERS_GENERATED_TYPES_SELFMESSAGING_H_
|
5
|
+
#define FLATBUFFERS_GENERATED_TYPES_SELFMESSAGING_H_
|
6
|
+
|
7
|
+
#include "flatbuffers/flatbuffers.h"
|
8
|
+
|
9
|
+
namespace SelfMessaging {
|
10
|
+
|
11
|
+
enum ACLCommand {
|
12
|
+
ACLCommand_LIST = 0,
|
13
|
+
ACLCommand_PERMIT = 1,
|
14
|
+
ACLCommand_REVOKE = 2,
|
15
|
+
ACLCommand_MIN = ACLCommand_LIST,
|
16
|
+
ACLCommand_MAX = ACLCommand_REVOKE
|
17
|
+
};
|
18
|
+
|
19
|
+
inline const ACLCommand (&EnumValuesACLCommand())[3] {
|
20
|
+
static const ACLCommand values[] = {
|
21
|
+
ACLCommand_LIST,
|
22
|
+
ACLCommand_PERMIT,
|
23
|
+
ACLCommand_REVOKE
|
24
|
+
};
|
25
|
+
return values;
|
26
|
+
}
|
27
|
+
|
28
|
+
inline const char * const *EnumNamesACLCommand() {
|
29
|
+
static const char * const names[4] = {
|
30
|
+
"LIST",
|
31
|
+
"PERMIT",
|
32
|
+
"REVOKE",
|
33
|
+
nullptr
|
34
|
+
};
|
35
|
+
return names;
|
36
|
+
}
|
37
|
+
|
38
|
+
inline const char *EnumNameACLCommand(ACLCommand e) {
|
39
|
+
if (flatbuffers::IsOutRange(e, ACLCommand_LIST, ACLCommand_REVOKE)) return "";
|
40
|
+
const size_t index = static_cast<size_t>(e);
|
41
|
+
return EnumNamesACLCommand()[index];
|
42
|
+
}
|
43
|
+
|
44
|
+
enum ErrType {
|
45
|
+
ErrType_ErrConnection = 0,
|
46
|
+
ErrType_ErrBadRequest = 1,
|
47
|
+
ErrType_ErrInternal = 2,
|
48
|
+
ErrType_ErrMessage = 3,
|
49
|
+
ErrType_ErrAuth = 4,
|
50
|
+
ErrType_ErrACL = 5,
|
51
|
+
ErrType_MIN = ErrType_ErrConnection,
|
52
|
+
ErrType_MAX = ErrType_ErrACL
|
53
|
+
};
|
54
|
+
|
55
|
+
inline const ErrType (&EnumValuesErrType())[6] {
|
56
|
+
static const ErrType values[] = {
|
57
|
+
ErrType_ErrConnection,
|
58
|
+
ErrType_ErrBadRequest,
|
59
|
+
ErrType_ErrInternal,
|
60
|
+
ErrType_ErrMessage,
|
61
|
+
ErrType_ErrAuth,
|
62
|
+
ErrType_ErrACL
|
63
|
+
};
|
64
|
+
return values;
|
65
|
+
}
|
66
|
+
|
67
|
+
inline const char * const *EnumNamesErrType() {
|
68
|
+
static const char * const names[7] = {
|
69
|
+
"ErrConnection",
|
70
|
+
"ErrBadRequest",
|
71
|
+
"ErrInternal",
|
72
|
+
"ErrMessage",
|
73
|
+
"ErrAuth",
|
74
|
+
"ErrACL",
|
75
|
+
nullptr
|
76
|
+
};
|
77
|
+
return names;
|
78
|
+
}
|
79
|
+
|
80
|
+
inline const char *EnumNameErrType(ErrType e) {
|
81
|
+
if (flatbuffers::IsOutRange(e, ErrType_ErrConnection, ErrType_ErrACL)) return "";
|
82
|
+
const size_t index = static_cast<size_t>(e);
|
83
|
+
return EnumNamesErrType()[index];
|
84
|
+
}
|
85
|
+
|
86
|
+
enum MsgType {
|
87
|
+
MsgType_MSG = 0,
|
88
|
+
MsgType_ACK = 1,
|
89
|
+
MsgType_ERR = 2,
|
90
|
+
MsgType_AUTH = 3,
|
91
|
+
MsgType_ACL = 4,
|
92
|
+
MsgType_MIN = MsgType_MSG,
|
93
|
+
MsgType_MAX = MsgType_ACL
|
94
|
+
};
|
95
|
+
|
96
|
+
inline const MsgType (&EnumValuesMsgType())[5] {
|
97
|
+
static const MsgType values[] = {
|
98
|
+
MsgType_MSG,
|
99
|
+
MsgType_ACK,
|
100
|
+
MsgType_ERR,
|
101
|
+
MsgType_AUTH,
|
102
|
+
MsgType_ACL
|
103
|
+
};
|
104
|
+
return values;
|
105
|
+
}
|
106
|
+
|
107
|
+
inline const char * const *EnumNamesMsgType() {
|
108
|
+
static const char * const names[6] = {
|
109
|
+
"MSG",
|
110
|
+
"ACK",
|
111
|
+
"ERR",
|
112
|
+
"AUTH",
|
113
|
+
"ACL",
|
114
|
+
nullptr
|
115
|
+
};
|
116
|
+
return names;
|
117
|
+
}
|
118
|
+
|
119
|
+
inline const char *EnumNameMsgType(MsgType e) {
|
120
|
+
if (flatbuffers::IsOutRange(e, MsgType_MSG, MsgType_ACL)) return "";
|
121
|
+
const size_t index = static_cast<size_t>(e);
|
122
|
+
return EnumNamesMsgType()[index];
|
123
|
+
}
|
124
|
+
|
125
|
+
enum MsgSubType {
|
126
|
+
MsgSubType_Unknown = 0,
|
127
|
+
MsgSubType_AuthenticationReq = 1,
|
128
|
+
MsgSubType_AuthenticationResp = 2,
|
129
|
+
MsgSubType_AuthenticationQRResp = 3,
|
130
|
+
MsgSubType_AuthenticationDeepLinkResp = 4,
|
131
|
+
MsgSubType_FactReq = 5,
|
132
|
+
MsgSubType_FactResp = 6,
|
133
|
+
MsgSubType_FactQRResp = 7,
|
134
|
+
MsgSubType_FactDeepLinkResp = 8,
|
135
|
+
MsgSubType_EmailSecurityCodeReq = 9,
|
136
|
+
MsgSubType_EmailSecurityCodeResp = 10,
|
137
|
+
MsgSubType_PhoneSecurityCodeReq = 11,
|
138
|
+
MsgSubType_PhoneSecurityCodeResp = 12,
|
139
|
+
MsgSubType_PhoneVerificationReq = 13,
|
140
|
+
MsgSubType_PhoneVerificationResp = 14,
|
141
|
+
MsgSubType_EmailVerificationReq = 15,
|
142
|
+
MsgSubType_EmailVerificationResp = 16,
|
143
|
+
MsgSubType_DocumentVerificationReq = 17,
|
144
|
+
MsgSubType_DocumentVerificationResp = 18,
|
145
|
+
MsgSubType_MIN = MsgSubType_Unknown,
|
146
|
+
MsgSubType_MAX = MsgSubType_DocumentVerificationResp
|
147
|
+
};
|
148
|
+
|
149
|
+
inline const MsgSubType (&EnumValuesMsgSubType())[19] {
|
150
|
+
static const MsgSubType values[] = {
|
151
|
+
MsgSubType_Unknown,
|
152
|
+
MsgSubType_AuthenticationReq,
|
153
|
+
MsgSubType_AuthenticationResp,
|
154
|
+
MsgSubType_AuthenticationQRResp,
|
155
|
+
MsgSubType_AuthenticationDeepLinkResp,
|
156
|
+
MsgSubType_FactReq,
|
157
|
+
MsgSubType_FactResp,
|
158
|
+
MsgSubType_FactQRResp,
|
159
|
+
MsgSubType_FactDeepLinkResp,
|
160
|
+
MsgSubType_EmailSecurityCodeReq,
|
161
|
+
MsgSubType_EmailSecurityCodeResp,
|
162
|
+
MsgSubType_PhoneSecurityCodeReq,
|
163
|
+
MsgSubType_PhoneSecurityCodeResp,
|
164
|
+
MsgSubType_PhoneVerificationReq,
|
165
|
+
MsgSubType_PhoneVerificationResp,
|
166
|
+
MsgSubType_EmailVerificationReq,
|
167
|
+
MsgSubType_EmailVerificationResp,
|
168
|
+
MsgSubType_DocumentVerificationReq,
|
169
|
+
MsgSubType_DocumentVerificationResp
|
170
|
+
};
|
171
|
+
return values;
|
172
|
+
}
|
173
|
+
|
174
|
+
inline const char * const *EnumNamesMsgSubType() {
|
175
|
+
static const char * const names[20] = {
|
176
|
+
"Unknown",
|
177
|
+
"AuthenticationReq",
|
178
|
+
"AuthenticationResp",
|
179
|
+
"AuthenticationQRResp",
|
180
|
+
"AuthenticationDeepLinkResp",
|
181
|
+
"FactReq",
|
182
|
+
"FactResp",
|
183
|
+
"FactQRResp",
|
184
|
+
"FactDeepLinkResp",
|
185
|
+
"EmailSecurityCodeReq",
|
186
|
+
"EmailSecurityCodeResp",
|
187
|
+
"PhoneSecurityCodeReq",
|
188
|
+
"PhoneSecurityCodeResp",
|
189
|
+
"PhoneVerificationReq",
|
190
|
+
"PhoneVerificationResp",
|
191
|
+
"EmailVerificationReq",
|
192
|
+
"EmailVerificationResp",
|
193
|
+
"DocumentVerificationReq",
|
194
|
+
"DocumentVerificationResp",
|
195
|
+
nullptr
|
196
|
+
};
|
197
|
+
return names;
|
198
|
+
}
|
199
|
+
|
200
|
+
inline const char *EnumNameMsgSubType(MsgSubType e) {
|
201
|
+
if (flatbuffers::IsOutRange(e, MsgSubType_Unknown, MsgSubType_DocumentVerificationResp)) return "";
|
202
|
+
const size_t index = static_cast<size_t>(e);
|
203
|
+
return EnumNamesMsgSubType()[index];
|
204
|
+
}
|
205
|
+
|
206
|
+
} // namespace SelfMessaging
|
207
|
+
|
208
|
+
#endif // FLATBUFFERS_GENERATED_TYPES_SELFMESSAGING_H_
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#include <iostream>
|
2
|
+
#include "rice/rice.hpp"
|
3
|
+
#include "flatbuffers/flatbuffers.h"
|
4
|
+
#include "msgproto/notification_generated.h"
|
5
|
+
|
6
|
+
using namespace SelfMessaging;
|
7
|
+
|
8
|
+
VALUE notification_initialize(int argc, VALUE *argv, VALUE self)
|
9
|
+
{
|
10
|
+
VALUE opts;
|
11
|
+
|
12
|
+
(void)rb_scan_args(argc, argv, "0:", &opts);
|
13
|
+
|
14
|
+
opts = (opts == Qnil) ? rb_hash_new(): opts;
|
15
|
+
|
16
|
+
VALUE data = rb_hash_aref(opts, ID2SYM(rb_intern("data")));
|
17
|
+
|
18
|
+
if (data != Qnil) {
|
19
|
+
if(rb_obj_is_kind_of(data, rb_cString) != Qtrue){
|
20
|
+
rb_raise(rb_eTypeError, "notification data must be kind of String");
|
21
|
+
}
|
22
|
+
|
23
|
+
const uint8_t *data_ptr = (uint8_t *)RSTRING_PTR(data);
|
24
|
+
long data_len = RSTRING_LEN(data);
|
25
|
+
|
26
|
+
auto ntf = GetNotification(data_ptr);
|
27
|
+
|
28
|
+
flatbuffers::Verifier verifier(data_ptr, data_len);
|
29
|
+
|
30
|
+
if (!VerifyNotificationBuffer(verifier)) {
|
31
|
+
rb_raise(rb_eStandardError, "notification buffer is invalid");
|
32
|
+
}
|
33
|
+
|
34
|
+
auto id = ntf->id()->c_str();
|
35
|
+
auto mtype = ntf->msgtype();
|
36
|
+
auto error = ntf->error()->c_str();
|
37
|
+
|
38
|
+
VALUE idstr = rb_str_new(id, std::strlen(id));
|
39
|
+
rb_ivar_set(self, rb_intern("@id"), idstr);
|
40
|
+
|
41
|
+
VALUE mtypeint = rb_int2inum(mtype);
|
42
|
+
rb_ivar_set(self, rb_intern("@type"), mtypeint);
|
43
|
+
|
44
|
+
VALUE errorstr = rb_str_new(error, std::strlen(error));
|
45
|
+
rb_ivar_set(self, rb_intern("@error"), errorstr);
|
46
|
+
}
|
47
|
+
|
48
|
+
return self;
|
49
|
+
}
|
50
|
+
|
51
|
+
void notification_init() {
|
52
|
+
VALUE cRubySelfMsg = rb_define_module("SelfMsg");
|
53
|
+
VALUE cHeader = rb_define_class_under(cRubySelfMsg, "Notification", rb_cObject);
|
54
|
+
|
55
|
+
rb_define_method(cHeader, "initialize", notification_initialize, -1);
|
56
|
+
}
|
57
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#include "rice/rice.hpp"
|
2
|
+
#include <iostream>
|
3
|
+
|
4
|
+
using namespace Rice;
|
5
|
+
|
6
|
+
void acl_init();
|
7
|
+
void auth_init();
|
8
|
+
void header_init();
|
9
|
+
void message_init();
|
10
|
+
void notification_init();
|
11
|
+
|
12
|
+
|
13
|
+
extern "C"
|
14
|
+
void Init_self_msgproto()
|
15
|
+
{
|
16
|
+
acl_init();
|
17
|
+
auth_init();
|
18
|
+
header_init();
|
19
|
+
message_init();
|
20
|
+
notification_init();
|
21
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Copyright 2020 Self Group Ltd. All Rights Reserved.
|
2
|
+
|
3
|
+
require 'self_msgproto/version'
|
4
|
+
require 'self_msgproto/acl'
|
5
|
+
require 'self_msgproto/auth'
|
6
|
+
require 'self_msgproto/header'
|
7
|
+
require 'self_msgproto/message'
|
8
|
+
require 'self_msgproto/notification'
|
9
|
+
require 'self_msgproto/self_msgproto'
|
10
|
+
|
11
|
+
module SelfMsg
|
12
|
+
end
|