开发者

Delphi Protocol Buffers?

开发者 https://www.devze.com 2022-12-18 00:26 出处:网络
Does anyone know of a project to d开发者_运维知识库o a Google Protocol Buffers implementation in Delphi?Here:

Does anyone know of a project to d开发者_运维知识库o a Google Protocol Buffers implementation in Delphi?


Here:

Fundamentals Protocol Buffers 4.00.01 (10 Feb 2013)

Google Protocol Buffers

http://fundementals.sourceforge.net/dl.html


This project contains the implementation of Protocol Buffers for Delphi. From the project was implemented limited functionality necessary for a specific project. At that time, I do not see any sense to transfer the whole project code. http://sourceforge.net/projects/protobuf-delphi/


You may be better off finding / making a C++ / Delphi bridge, rather than re-implementing Protocol Buffers. The codebase is rather large.


I found another one on the github. (developped from Feb.2014 to Jul.2016, as of June 2017)

It seems to have preliminary proto3 support.

I didn't test yet, but it may be the best as of today.

https://github.com/stijnsanders/DelphiProtocolBuffer

EDIT: I tested this but it seems to be written in old delphi and not unicode ready.

I could compile the generator (using 10 Seattle), but compiled exe couldn't generate pas file :-(

EDIT2:

The code generator works just replacing TStream to TStreamReader/Writer. I confirmed generator can convert recent address book sample.

diff --git a/ProtBufParse.pas b/ProtBufParse.pas
index f29d7c7..cdd734d 100644
--- a/ProtBufParse.pas
+++ b/ProtBufParse.pas
@@ -236,16 +236,13 @@ var

   procedure LoadCode;
   var
-    f:TFileStream;
+    sr:TStreamReader;
   begin
-    f:=TFileStream.Create(FilePath,fmOpenRead or fmShareDenyWrite);
+    sr:=TStreamReader.Create(FilePath, True{DetectBOM});
     try
-      //TODO: UTF-8? UTF-16?
-      CodeL:=f.Size;
-      SetLength(Code,CodeL);
-      if f.Read(Code[1],CodeL)<>CodeL then RaiseLastOSError;
+      Code := sr.ReadToEnd;
     finally
-      f.Free;
+      sr.Free;
     end;
   end;

diff --git a/dpbp.dpr b/dpbp.dpr
index 4049480..b6dab90 100644
--- a/dpbp.dpr
+++ b/dpbp.dpr
@@ -22,7 +22,7 @@ var
   p:TProtocolBufferParser;
   s,t,InputFN,OutputFN,RelPath:string;
   i,j,l,l1:integer;
-  f:TFileStream;
+  sw:TStreamWriter;
   fv:TProtocolBufferParserValue;
   ff:TProtocolBufferParserFlag;
   Flags:TProtocolBufferParserFlags;
@@ -134,11 +134,12 @@ begin

         writeln('Writing '+OutputFN);
         s:=p.GenerateUnit(Flags);
-        f:=TFileStream.Create(OutputFN,fmCreate);
+
+        sw:=TStreamWriter.Create(OutputFN,False,TEncoding.UTF8);
         try
-          f.Write(s[1],Length(s));
+          sw.Write(s);
         finally
-          f.Free;
+          sw.Free;
         end;

       finally


I wonder what you think of using either JSON or BSON seems like a work in progress) as a protocol.

0

精彩评论

暂无评论...
验证码 换一张
取 消