Usage of MessageDeserializer to create message from byte array
Hello! I am working on rebuilding ros_serial for android and have run into a problem creating the actual Message object from the byte array.
In the last supported version, it was as simple as
TopicInfo tI = new TopicInfo();
tI.deserialize(byteBuffer);
Ros now uses the MessageDeserializer and MessageSerializer, and for the life of me, I cant seem to get the ChannelBuffer to cooperate. The obvious usage would be,
ChannelBuffer channelBuffer = ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, buffer);
MessageDeserializer<Message> serializer = node.getMessageSerializationFactory().newMessageDeserializer(type);
serializer.deserialize(channelBuffer);
but this crashes with the following error.
E//node ( 2549): Unable to read input stream E//node ( 2549): java.lang.IndexOutOfBoundsException: Invalid combined index of 458881, maximum is 72 E//node ( 2549): at org.jboss.netty.buffer.SlicedChannelBuffer.<init>(SlicedChannelBuffer.java:46) E//node ( 2549): at org.jboss.netty.buffer.HeapChannelBuffer.slice(HeapChannelBuffer.java:200) E//node ( 2549): at org.jboss.netty.buffer.AbstractChannelBuffer.readSlice(AbstractChannelBuffer.java:323) E//node ( 2549): at org.ros.internal.message.field.PrimitiveFieldType$14.deserialize(PrimitiveFieldType.java:584) E//node ( 2549): at org.ros.internal.message.field.PrimitiveFieldType$14.deserialize(PrimitiveFieldType.java:555) E//node ( 2549): at org.ros.internal.message.field.ValueField.deserialize(ValueField.java:68) E//node ( 2549): at org.ros.internal.message.DefaultMessageDeserializer.deserialize(DefaultMessageDeserializer.java:45) E//node ( 2549): at com.cloudspace.rosserial.Protocol.parsePacket(Protocol.java:285) E//node ( 2549): at com.cloudspace.rosserial.ROSSerial.handleByte(ROSSerial.java:344) E//node ( 2549): at com.cloudspace.rosserial.ROSSerial.run(ROSSerial.java:227) E//node ( 2549): at java.lang.Thread.run(Thread.java:818)
How do you deserialize a message passed from ros_serial?
I have the same problem with it.