2

I am trying to serialize a POJO using the example of their wiki but I am getting "Protocol message contained an invalid tag (zero)." I want my POJO to be converted to byte[], send it to a message broker, retrieve it and deserialize it. I have a unit test to test this and it seems to work, but when I am passing it through the broker, it breaks. This is my code:

private final Schema<MyObject> schema = RuntimeSchema.getSchema(MyObject.class);
private final LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);

//Serialization
byte[] result = ProtostuffIOUtil.toByteArray(myObject, schema, buffer);

// Send result to message broker
// Receive result from message broker

//Deserialization
MyObject myObject = schema.newInstance();
ProtostuffIOUtil.mergeFrom(b, myObject, schema); <--- Exception thrown

The stack trace is:

Caused by: java.lang.RuntimeException: Reading from a byte array threw an IOException (should never happen).
at com.dyuproject.protostuff.IOUtil.mergeFrom(IOUtil.java:53) ~[protostuff-core-1.0.7.jar:1.0.7]
at com.dyuproject.protostuff.ProtostuffIOUtil.mergeFrom(ProtostuffIOUtil.java:96) ~[protostuff-core-1.0.7.jar:1.0.7]
... 19 more
Caused by: com.dyuproject.protostuff.ProtobufException: Protocol message contained an invalid tag (zero).
at com.dyuproject.protostuff.ProtobufException.invalidTag(ProtobufException.java:98) ~[protostuff-core-1.0.7.jar:1.0.7]
at com.dyuproject.protostuff.ByteArrayInput.readFieldNumber(ByteArrayInput.java:220) ~[protostuff-core-1.0.7.jar:1.0.7]
at com.dyuproject.protostuff.runtime.MappedSchema.mergeFrom(MappedSchema.java:179) ~[protostuff-runtime-1.0.7.jar:1.0.7]
at com.dyuproject.protostuff.IOUtil.mergeFrom(IOUtil.java:43) ~[protostuff-core-1.0.7.jar:1.0.7]
at com.dyuproject.protostuff.ProtostuffIOUtil.mergeFrom(ProtostuffIOUtil.java:96) ~[protostuff-core-1.0.7.jar:1.0.7]...

Any idea what I am doing wrong? Thanks!

hveiga
  • 6,725
  • 7
  • 54
  • 78
  • What is `b` in there? If that is related to `buffer`, is it possible that you're passing around the *oversized* buffer? Any unused space at the end of the buffer will present as a zero tag, which would explain the error – Marc Gravell Oct 10 '13 at 12:13
  • `b` is a `byte[]` which is the bytes I am sending and receiving, it is not related to a buffer. `b` is around 170 bytes and when creating it, I am using a `buffer` of 512 bytes size, which I believe it is sufficient. – hveiga Oct 10 '13 at 14:37
  • How confident are you that the 170 bytes is internally valid? If you can post the content as base-64 or hex I could trivially sanity check it for you - that will tell you whether the problem is in the reader vs in the data – Marc Gravell Oct 10 '13 at 17:13
  • This is it, thanks! Cg1BQUFBQkJCQkJDQ0NDEg5NeVByb3ZpZGVyTmFtZRksDjupQQEAACCsnOzJmigpLA47qUEBAAAwrJzsyZooSZ+sGK4OnkRAUei/B69d/kpAWgYxMjM0NTZhAAAAAAAAWUBpAAAAAAAATkCzAbQB – hveiga Oct 11 '13 at 20:36
  • I had to strip a nasty unicode character out of that - be careful of that - but: looks ok to me (ignore the numbers, it is hard to tell double vs long etc): 1: AAAABBBBBCCCC 2: MyProviderName 3: 1381523721772 4: 1381523721772 5: 1381523721772 6: 1381523721772 9: 4631000102731295903 10: 4632794845025910760 11: 123456 12: 4636737291354636288 13: 4633641066610819072 - and an empty group at 22 – Marc Gravell Oct 11 '13 at 21:50
  • Thank you for checking, I am not sure what else to try... – hveiga Oct 11 '13 at 22:46
  • if that is the base-64 from `b`, then indeed - it looks about right – Marc Gravell Oct 11 '13 at 22:49

0 Answers0