@Override public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException, ClassNotFoundException { return ProtobufUtil.fromWrappedByteArray(getSerializationContext(), buf, offset, length); }
private void roundtrip(Object in) throws Exception { BaseProtoStreamMarshaller marshaller = makeInstance(); assertTrue(marshaller.isMarshallable(in)); byte[] buffer = marshaller.objectToByteBuffer(in); assertNotNull(buffer); Object out = marshaller.objectFromByteBuffer(buffer); assertNotNull(out); assertEquals(in.getClass(), out.getClass()); if (in instanceof byte[]) { assertArrayEquals((byte[]) in, (byte[]) out); } else { assertEquals(in, out); } }
@Override public boolean isMarshallable(Object o) { // our marshaller can handle all of these primitive/scalar types as well even if we do not // have a per-type marshaller defined in our SerializationContext return o instanceof String || o instanceof Long || o instanceof Integer || o instanceof Double || o instanceof Float || o instanceof Boolean || o instanceof byte[] || o instanceof Byte || o instanceof Short || o instanceof Character || o instanceof java.util.Date || o instanceof java.time.Instant || getSerializationContext().canMarshall(o.getClass()); }
@Override protected ByteBuffer objectToBuffer(Object o, int estimatedSize) throws IOException, InterruptedException { byte[] bytes = ProtobufUtil.toWrappedByteArray(getSerializationContext(), o); return new ByteBufferImpl(bytes, 0, bytes.length); }