私は C# と C++ の間でさまざまな成功を収めて通信しようとしています。
リプライ/リクエストを使用して 2 つの間でメッセージを送信できますが、受信している double が正しくありません。
デバッグの目的と理解のために、私は現在以下を実行しています:
Clrzmq 3.0 rc1、Google ProtocolBuffer 2.5、Protobuf-csharp-port-2.4、ZeroMQ-3.2.3
.プロト
package InternalComm;
message Point
{
optional double x = 1;
optional double y = 2;
optional string label = 3;
}
server.cpp (該当部分)
while (true) {
zmq::message_t request;
// Wait for next request from client
socket.recv (&request);
zmq::message_t reply (request.size());
memcpy ((void*)reply.data(), request.data(), request.size());
socket.send(reply);
}
client.cs (該当部分)
public static Point ProtobufPoint(Point point)
{
Point rtn = new Point(0,0);
using (var context = ZmqContext.Create())
{
using (ZmqSocket requester = context.CreateSocket(SocketType.REQ))
{
requester.Connect("tcp://localhost:5555");
var p = InternalComm.Point.CreateBuilder().SetX(point.X).SetY(point.Y).Build().ToByteArray();
requester.Send(p);
string reply = requester.Receive(Encoding.ASCII);
Console.WriteLine("Input: {0}", point);
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(reply);
var message = InternalComm.Point.ParseFrom(bytes);
rtn.X = message.X;
rtn.Y = message.Y;
Console.WriteLine("Output: {0}", rtn);
}
}
return rtn;
}
C# 側では、Point は非常に単純な構造体です。x および y プロパティのみ。
上記のコードを実行した結果、単体テストから得られた結果は次のとおりです。
入力 (1.31616874365468、4.55516872325469)
出力 (0.000473917985115791、4.55516872323627)入力 (274.120398471829、274.128936418736)
出力 (274.077917334613、274.128936049925)入力 (150.123798461987、2.345E-12)
出力 (145.976459594794、1.11014954927532E-13)入力 (150, 0)
出力 (145.96875, 0)
問題は、protobuf コードが正しくないことだと考えています (これは Skeet 側のバグであるとは思えません)。また、server.cpp はメッセージに対して何もせず、そのまま返すという前提で実行しています。
考え?