I'm trying to decode message pack payload. They payload is written in go with the following code
var w bytes.Buffer
testBatch := []Event{
exampleEvent,
exampleEvent,
}
for _, e := range testBatch {
data, err := e.MarshalMsg(nil)
if err != nil {
t.Fatalf("MarshalMsg failed: %v", err)
}
if _, err := w.Write(data); err != nil {
t.Fatalf("Write: %v", err)
}
}
// w.Bytes() now contain bytes that java will read.
If I understand correctly, the payload now contains 2 msgpack encoded stack which is appended together.
for decoding in java, I'm using the following libaray
https://github.com/msgpack/msgpack-java
that project contain msgpack-jackson that handle decoding message to POJO
I manage to decode the first message in java using the following code:
ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
Event events1 = objectMapper.readValue(in, Event.class);
// Event events2 = objectMapper.readValue(in, Event.class); // this doesn't work
events1
contain the first struct which is decoded correctly, but I did not manage to get the second struct.
un-commenting the events1
line give the following error
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
at [Source: java.io.ByteArrayInputStream@2374d36a; line: -1, column: 0]
My objective is to get all the struct in the payload decoded correctly in java. I could find example.