Delphi 协议缓冲区?

发布于 2024-08-19 03:51:47 字数 53 浏览 2 评论 0原文

有谁知道在 Delphi 中实现 Google Protocol Buffers 的项目吗?

Does anyone know of a project to do a Google Protocol Buffers implementation in Delphi?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

热风软妹 2024-08-26 03:51:47

此处:

Fundamentals Protocol Buffers 4.00.01(2013 年 2 月 10 日)

Google Protocol Buffers

http://fundementals.sourceforge.net/dl.html< /a>

Here:

Fundamentals Protocol Buffers 4.00.01 (10 Feb 2013)

Google Protocol Buffers

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

夏了南城 2024-08-26 03:51:47

该项目包含 Delphi 的 Protocol Buffers 的实现。从该项目中实现了特定项目所需的有限功能。当时,我认为转移整个项目代码没有任何意义。
http://sourceforge.net/projects/protobuf-delphi/

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/

浮生面具三千个 2024-08-26 03:51:47

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

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

乖乖公主 2024-08-26 03:51:47

我在 github 上找到了另一个。 (从2014年2月开发到2016年7月,截至2017年6月)

似乎有 初步 proto3支持

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

https: //github.com/stijnsanders/DelphiProtocolBuffer

编辑:
我测试了这个,但它似乎是用旧的 delphi 编写的,并且没有准备好 unicode。

我可以编译生成器(使用 10 Seattle),但编译后的 exe 无法生成 pas 文件:-(

EDIT2:

代码生成器只需将 TStream 替换为 TStreamReader/Writer。
我确认生成器可以转换最近的地址簿示例

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 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
太阳男子 2024-08-26 03:51:47

我想知道您对使用 JSONBSON 似乎是一项正在进行的工作)作为一个协议。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文