-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProtobuf.lua
More file actions
64 lines (43 loc) · 1.32 KB
/
Protobuf.lua
File metadata and controls
64 lines (43 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
local Constants = {}
Constants.TYPES = {
uInt32 = 0,
sInt32 = 0,
int32 = 0,
double = 1,
string = 2,
message = 2,
float = 5
}
local Util = {}
Util.isSimpleType = function(type_)
return ( type_ == 'uInt32' or
type_ == 'sInt32' or
type_ == 'int32' or
type_ == 'uInt64' or
type_ == 'sInt64' or
type_ == 'float' or
type_ == 'double' or
type_ == 'bool' or
type_ == 'boolean')
end
Protobuf = {}
-- local Constants,Util, MsgEncoder, MsgDecoder, Parser, Codec = {}, {}, {}, {}, {}, {}
Protobuf.constants = Constants
Protobuf.util = Util
Protobuf.parser = require("libs.pomelo.protobuf.Parser")
Protobuf.codec = require("libs.pomelo.protobuf.Codec")
Protobuf.encoder = require("libs.pomelo.protobuf.Encoder")
Protobuf.decoder = require("libs.pomelo.protobuf.Decoder")
Protobuf.init = function(protos)
local parser = Protobuf.parser
-- dump(parser.parse(protos.decoderProtos), "decoderProtos")
Protobuf.encoder.init(parser.parse(protos.encoderProtos))
Protobuf.decoder.init(parser.parse(protos.decoderProtos))
end
Protobuf.encode = function(key, msg)
return Protobuf.encoder.encode(key, msg)
end
Protobuf.decode = function(key, msg)
return Protobuf.decoder.decode(key, msg)
end
return Protobuf