Skip to content

Commit 97eb508

Browse files
committed
更新测试文件与测试文件
1 parent a1fb6d5 commit 97eb508

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

Person.pb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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

Person.proto

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

script/test_protobuf.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
local Log = require ("logging"):new()
1+
local Log = require "logging"
22

33
local pb = require "protobuf"
44

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"))
620

721
local pb_string = pb.encode("Person", {
822
name = "CandyMi",

0 commit comments

Comments
 (0)