delphi proto工具

delphi proto工具

1)编辑.proto

//protobuf模板文件
syntax="proto3";
package tables;

//返回结果
message Res {
	bool ok = 1;
	string err = 2;
}

//商品资料
message Goods {
	string goodsid = 1;
	string goodsname = 2;
}

//计量单位
message Units {
	string unitid = 1;
	string unitname = 2;
}

//主从表
message Tables {
	repeated Goods Goodss = 1;
	repeated Units Unitss= 2;
}

  笔者有一个工具,可以将数据表自动生成.proto

2)使用工具将.proto生成pascal结构代码

{ Unit pbTablesMessages.pas }
{ Generated from tables.proto }
{ Package Tables }

unit pbTablesMessages;

interface

uses Grijjy.ProtocolBuffers, SysUtils;

{ TRes }

type
  TRes = record
    [Serialize(1)] Ok : Boolean;
    [Serialize(2)] Err : String;
  end;

{ TGoods }

type
  TGoods = record
    [Serialize(1)] Goodsid : String;
    [Serialize(2)] Goodsname : String;
  end;

{ TUnits }

type
  TUnits = record
    [Serialize(1)] Unitid : String;
    [Serialize(2)] Unitname : String;
  end;

{ TTables }

type
  TTables = record
    [Serialize(1)] Goodss : TArray<TGoods>;
    [Serialize(2)] Unitss : TArray<TUnits>;
  end;

implementation

end.

  

 

posted @ 2022-07-07 17:17  delphi中间件  阅读(312)  评论(0编辑  收藏  举报