Create an InputStream
to the file created in C#, and call
Person.parseFrom(InputStream)
There are other overloads to this method if you'd rather deal with bytes from that file.
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.
EDIT
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.
I know you didn't ask for this, but perhaps you'll find it useful.
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.)
public class MessageTypeMap {
private final Object lock;
final HashMap<Integer, GeneratedMessageLite> messageParserMap;
final HashMap<Class<?>, Integer> messageClassParserMap;
public MessageTypeMap() {
this.messageParserMap = new HashMap<Integer, GeneratedMessageLite>();
this.messageClassParserMap = new HashMap<Class<?>, Integer>();
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<?> 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());
}
}
}
}
Usage:
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());