其他分享
首页 > 其他分享> > delphi将*.proto转换为pascal工具

delphi将*.proto转换为pascal工具

作者:互联网

delphi将*.proto转换为pascal工具

*.proto是google protobuf的结构描述语言。

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

//返回结果
message Res {
	int32 status = 1;
	string exception = 2;
	string message = 3;
}

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

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

//主从表
message Tables {
	int32 status = 1;
	string exception = 2;
	string message = 3;
	repeated Goods Goodss = 4;
	repeated Units Unitss= 5;
}

  运行codegen.bat

 

自动生成pbTablesMessages.pas

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

unit pbTablesMessages;

interface

uses Grijjy.ProtocolBuffers, SysUtils;

{ TRes }

type
  TRes = record
    [Serialize(1)] Status : Integer;
    [Serialize(2)] Exception : String;
    [Serialize(3)] Message : 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)] Status : Integer;
    [Serialize(2)] Exception : String;
    [Serialize(3)] Message : String;
    [Serialize(4)] Goodss : TArray<TGoods>;
    [Serialize(5)] Unitss : TArray<TUnits>;
  end;

implementation

end.

  

标签:end,String,proto,delphi,Serialize,pascal,message,string
来源: https://www.cnblogs.com/hnxxcxg/p/16463061.html