2010-01-27 215 views
17

有没有人知道一个项目在Delphi中执行Google协议缓冲区实现?Delphi协议缓冲区?

+0

看起来不那么难一展身手,在它自己(自己呢?),这只是时间(时间!)我希望我有一个每天多几个小时。 – 2010-01-27 18:13:04

+2

阿门!希望能帮忙,而不是从头开始。 – 2010-01-28 02:31:32

+1

Protocol Buffers site:http://code.google.com/p/protobuf/ protobuf-net是一个.net实现:http://code.google.com/p/protobuf-net/ 基于在它之上必须比我第一次想到更多的工作。 我想在Delphi中使用win32或非.net版本。 – 2010-01-28 02:41:34

回答

9

该项目包含Delphi的Protocol Buffers的实现。项目实施了特定项目所需的有限功能。那时候,我看不出有什么意义可以传输整个项目代码。 http://sourceforge.net/projects/protobuf-delphi/

+0

,并且自2011年以来未再被触及。请参阅下面的内容基本面的答案似乎仍然是积极维持的。 – 2013-04-10 23:03:19

+1

版本1.1已于2013年4月发布。 – 2013-06-26 13:34:44

2

您可能会更好地找到/制作C++/Delphi桥接器,而不是重新实现Protocol Buffers。代码库相当大。

0

我想知道你使用JSON还是BSON看起来像是一个正在进行的工作)作为一个协议。

+0

它看起来像协议缓冲区功能更丰富,因为它们允许例如可选元素,所以它更接近于XML + XSD/WSDL/SOAP协议,而不是序列化格式 – mjn 2011-03-17 05:36:37

14

这里:

基础Protocol Buffers的4.00.01(2013年2月10日)

谷歌协议缓冲

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

+2

似乎需要积极维护。 +1,而接受的答案似乎是冻结的,自2011年以来从未接触过。 – 2013-04-10 23:02:47

1

我在github上发现another one。 (从2014年2月开始至2016年7月,截至2017年6月)

好像有preliminary proto3 support

我还没有测试,但它可能是今天最好的。

https://github.com/stijnsanders/DelphiProtocolBuffer

编辑: 我测试了这一点,但它似乎是写在老德尔福,而不是Unicode的准备。

我可以编译生成器(使用10西雅图),但编译的exe无法生成PAS文件:-(

EDIT2:

代码生成工作只是更换T流至TStreamReader /写卡器。 我证实发生器可以转换最近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