File tree 3 files changed +49
-2
lines changed 3 files changed +49
-2
lines changed Original file line number Diff line number Diff line change
1
+
2
+ �
3
+ Person.proto"�
4
+ Person
5
+ name ( Rname
6
+ age (Rage
7
+ hand (2.Person.HandRhand
8
+ foot (2.Person.FootRfoot0
9
+ Hand
10
+ left ( Rleft
11
+ right ( Rright0
12
+ Foot
13
+ left ( Rleft
14
+ right ( Rrightbproto3
Original file line number Diff line number Diff line change
1
+ syntax = "proto3" ;
2
+
3
+ message Person
4
+ {
5
+ message Hand
6
+ {
7
+ string left = 1 ;
8
+ string right = 2 ;
9
+ }
10
+ message Foot
11
+ {
12
+ string left = 1 ;
13
+ string right = 2 ;
14
+ }
15
+ string name = 1 ;
16
+ uint32 age = 2 ;
17
+ Hand hand = 3 ;
18
+ Foot foot = 4 ;
19
+ }
Original file line number Diff line number Diff line change 1
- local Log = require ( " logging" ): new ()
1
+ local Log = require " logging"
2
2
3
3
local pb = require " protobuf"
4
4
5
- Log :DEBUG (pb .loadfile (" Person.lua" ))
5
+ --[[
6
+ 测试与使用指南:
7
+
8
+ 1. 安装protobuf的命令行二进制生成工具protoc.
9
+
10
+ 2. 使用命令 protoc Person.proto -o Person.pb 生成协议文件.
11
+
12
+ 3. 使用loadfile读取生成的协议文件Person.pb后就完成了数据结构注册与导入.
13
+
14
+ 4. 这有时候就可以开始使用encode/decode方法进行代码测试.
15
+
16
+ 5. 需要注意的是: protobuf协议需要"先定义(注册), 后使用", 支持protobuf v2/v3版本语法.
17
+ ]]
18
+
19
+ Log :DEBUG (pb .loadfile (" Person.pb" ))
6
20
7
21
local pb_string = pb .encode (" Person" , {
8
22
name = " CandyMi" ,
You can’t perform that action at this time.
0 commit comments