基于结构的数据同步

基于结构的数据同步

可用于异构平台间的数据同步。

一个是支持跨语言,结构使用google protocol定义。二个是支持JSON和GOOGLE PROTOBUF二种序列。

1)代码工厂自动生成.proto

enum State {
    INSERT = 0; 
    UPDATE = 1;
    DELETE = 2;
}

message inproject {
    string prjid = 1;
    string prjname = 2;
	State action = 3;
	string where = 4;
}

message inprojectArray {
    repeated inproject inprojects = 1;
}

message Res {
    int32 status = 1;
    string exception = 2;
    string message = 3;
}

  2)将.proto用工具转化为所用语言的代码

{ Unit pbInprojectMessages.pas }
{ Generated from inproject.proto }
{ Package Inproject }

unit pbInprojectMessages;

interface

uses Grijjy.ProtocolBuffers, SysUtils;

{ TState }

type
  TState = (
    stateINSERT = 0,
    stateUPDATE = 1,
    stateDELETE = 2
  );


{ TInproject }

type
  TInproject = record
    [Serialize(1)] Prjid : String;
    [Serialize(2)] Prjname : String;
    [Serialize(3)] Action : TState;
    [Serialize(4)] Where : String;
  end;

{ TInprojectArray }

type
  TInprojectArray = record
    [Serialize(1)] Inprojects : TArray<TInproject>;
  end;

{ TRes }

type
  TRes = record
    [Serialize(1)] Status : Integer;
    [Serialize(2)] Exception : String;
    [Serialize(3)] Message : String;
  end;

implementation

end.

  

posted @ 2022-07-15 08:33  delphi中间件  阅读(126)  评论(0编辑  收藏  举报