2010-01-27 211 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