我已经用 c# 编写了这个 protobuf 消息
C#客户端:
public AddressBook InitializeAdressBook() { Person newContact = new Person(); AddressBook addressBookBuilder = new AddressBook(); Person john = new Person(); john.id=1234; john.name="John Doe"; john.email="jdoe@example.com"; Person.PhoneNumber nr = new Person.PhoneNumber(); nr.number="5554321"; john.phone.Add(nr); addressBookBuilder.person.Add(john); TextBox.Text += ("Client: Initialisiert? " + addressBookBuilder.ToString()) + "\t" + "\n"; TextBox.Text += " Erster Person " + addressBookBuilder.person.First().name + "\t" + "\n"; return addressBookBuilder; }
问题
我正在尝试将 protobuf 消息从 ac# 客户端发送到此 java 服务器...
Java 服务器
public ControllerThread(Socket s){ this.s = s; try { AddressBook adb = AddressBook.parseFrom(s.getInputStream()); System.out.println("Server: Addressbook:" + adb.getPersonCount()); } catch (IOException e) { System.out.println("Server: BufferedReader oder PrintWriter von ThermoClient konnte nicht erstellt werden"); e.printStackTrace(); } }
}
问题:
我应该将此消息序列化为字节数组,以便我可以将其发送到 java 服务器...不幸的是,ProtoBuf.Serializer.Serialize方法不返回字节数组。那么如何将其序列化为字节数组并将其发送到我的 Java 服务器呢?任何帮助表示感谢!