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.

  

posted @ 2022-07-10 13:34  delphi中间件  阅读(77)  评论(0编辑  收藏  举报