Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Create an <code>InputStream</code> to the file created in C#, and call </p> <pre><code>Person.parseFrom(InputStream) </code></pre> <p>There are other overloads to this method if you'd rather deal with bytes from that file.</p> <p>If you are implementing a protocol you'll need to include a header to identify what type of data the bytes represent. From there you'd just select the correct proto to parse the data with.</p> <p><strong>EDIT</strong></p> <p>Here's a class I created for mapping id's to class's and vice versa to assist in developing a protocol with protobufs. If you aren't developing a protocol for network transmission this might not help, but I'm pretty sure you are.</p> <p>I know you didn't ask for this, but perhaps you'll find it useful.</p> <p>Register ids to all your protobuff generators, then retrieve the correct generator for unserializing bytes on receive. Get the correct ID for each protobuf object before you send. ID would be included in every packet so you know what type of data is in each packet. (Packet being abstract here, this would work with a stream protocol too.)</p> <pre><code>public class MessageTypeMap { private final Object lock; final HashMap&lt;Integer, GeneratedMessageLite&gt; messageParserMap; final HashMap&lt;Class&lt;?&gt;, Integer&gt; messageClassParserMap; public MessageTypeMap() { this.messageParserMap = new HashMap&lt;Integer, GeneratedMessageLite&gt;(); this.messageClassParserMap = new HashMap&lt;Class&lt;?&gt;, Integer&gt;(); this.lock = new Object(); } public void addMessageType(int typeID, GeneratedMessageLite message) { synchronized (this.lock) { this.messageParserMap.put(typeID, message); this.messageClassParserMap.put(message.getDefaultInstanceForType() .getClass(), typeID); } } public GeneratedMessageLite getBuilderFor(int id) throws ProtocolException { synchronized (this.lock) { if (this.messageParserMap.containsKey(id)) { GeneratedMessageLite lite = this.messageParserMap.get(id); return lite; } else { throw new ProtocolException("No message builder for ID " + id); } } } public int getIDFor(Object obj) throws ProtocolException { synchronized (this.lock) { if (obj == null) { throw new NullPointerException( "Object null while retrieving type id."); } Class&lt;?&gt; c = obj.getClass(); if (this.messageClassParserMap.containsKey(c)) { int typeID = this.messageClassParserMap.get(c); return typeID; } else { throw new ProtocolException("No type id for class " + c.getSimpleName()); } } } </code></pre> <p>}</p> <p>Usage:</p> <pre><code>MessageTypeMap map = new MessageTypeMap(); //register the person type. map.addMessageType(100, Person.getDefaultInstance()); //use this to unserialize whatever object some bytes are. GeneratedMessageLite builder = mpa.getBuilderFor(100); //be sure to include the type id with each transmission of an object. int id = map.getIDFor(Person.getDefaultInstance()); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload