有没有人知道在Delphi中执行Google Protocol Buffers实现的项目?
答案 0 :(得分:17)
答案 1 :(得分:10)
该项目包含Delphi协议缓冲区的实现。从项目实施特定项目所需的有限功能。那时,我认为转移整个项目代码没有任何意义。 http://sourceforge.net/projects/protobuf-delphi/
答案 2 :(得分:2)
您可能最好找到/制作C ++ / Delphi桥,而不是重新实现Protocol Buffers。代码库相当大。
答案 3 :(得分:1)
我在github上找到了another one。 (从2014年2月至2016年7月,截至2017年6月开发)
似乎有preliminary proto3 support。
我还没有测试过,但它可能是今天最好的。
https://github.com/stijnsanders/DelphiProtocolBuffer
修改强> 我对此进行了测试,但它似乎是用旧的delphi编写的,而不是unicode。
我可以编译生成器(使用10西雅图),但编译的exe无法生成pas文件: - (
<强> EDIT2:强>
代码生成器只是将TStream替换为TStreamReader / Writer。 我确认生成器可以转换最近的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
答案 4 :(得分:0)