Hi,
I was testing storage of a Google Protobuf document into mongodb and decided for simplicity to use "." dot notation for the "_id" field in the database.
So the "_id" entry would be made from 3 fields from the protobuf as follows:
I implemented a MessageReadConverter & MessageWriteConverter for the spring data Converter all works great.
My questions is what part of the architect managed to convert the "." fields during reading the mongodb data into the correct Identity part of my protobuf object ?
The writer is:
and the reader:
and a correctly built protobuf object is populated:
I was testing storage of a Google Protobuf document into mongodb and decided for simplicity to use "." dot notation for the "_id" field in the database.
So the "_id" entry would be made from 3 fields from the protobuf as follows:
Code:
"_id" : "3936303865666539656633653461333362373536363664363534353766363831.517f7dfb.PDG*"
Code:
message Message {
message Identity {
required string group = 1; // 32 chars
required string epoch = 2; // 4 hex chars
required string sender = 3; // 3 chars
}
required Identity identity = 1; // 39 char
required string state = 2; // 1 char
message Signal { // 64 chars
... etc
}
required Signal signal = 3;
}
My questions is what part of the architect managed to convert the "." fields during reading the mongodb data into the correct Identity part of my protobuf object ?
The writer is:
Code:
@Override
public DBObject convert(Lwwk.Message msg) {
final DBObject dbo = new BasicDBObject();
final String jsonSignal = JsonFormat.printToString(msg.getSignal());
dbo.put("_id", Elements.toIdentityString(msg.getIdentity()));
dbo.put("state", msg.getState());
// TODO: this seems so wrong but it works
dbo.putAll((BSONObject) JSON.parse(jsonSignal)); // capture sub docs
return dbo;
}
Code:
@Override
public Message convert(DBObject o) {
// TODO: it works out the delimited ID itself ?
return composer.buildPartial();
}
Code:
2539 [main] INFO net.lwwk.services.core.BlackBox - GOT
identity {
group: "6136653462636639323363393464656439343933306130393939323135656563"
epoch: "517f8088"
sender: "PDG*"
}
state: "?"
signal {
...etc
}