private static MessageHistory readHistoryFromBytes(final Wire wire, MessageHistory history) { final Bytes<?> bytes = wire.bytes(); if (MESSAGE_HISTORY_METHOD_ID != wire.readEventNumber()) return null; ((BytesMarshallable) history).readMarshallable(bytes); return history; }
@Override public void encode(Object[] objects, BytesOut out) { for (Object object : objects) { if (object instanceof BytesMarshallable) { ((BytesMarshallable) object).writeMarshallable(out); continue; } throw new IllegalArgumentException("Object type " + object + " not supported"); } }
@Override protected void getValue(Object o, BytesOut write) throws IllegalAccessException { @NotNull BytesMarshallable o2 = (BytesMarshallable) field.get(o); assert o2 != null; o2.writeMarshallable(write); }
@Override public Object[] decode(Object[] lastObjects, BytesIn in) { for (Object lastObject : lastObjects) ((BytesMarshallable) lastObject).readMarshallable(in); return lastObjects; } };
private void initBytes() { if (!bytesInit) { bytes.clear(); instance.writeMarshallable(bytes); bytesInit = true; } }
@NotNull @Override public T read(Bytes in, @Nullable T using) { if (using == null) using = createInstance(); using.readMarshallable(in); return using; } }
default String $toString() { HexDumpBytes bytes = new HexDumpBytes(); writeMarshallable(bytes); String s = "# " + getClass().getName() + "\n" + bytes.toHexString(); bytes.release(); return s; } }
@Override protected void setValue(Object o, BytesIn read) throws IllegalAccessException, IORuntimeException { @NotNull BytesMarshallable o2 = (BytesMarshallable) field.get(o); if (!field.getType().isInstance(o2)) field.set(o, o2 = (BytesMarshallable) ObjectUtils.newInstance((Class) field.getType())); o2.readMarshallable(read); } }
throw new IllegalArgumentException("Cannot serialize " + obj.getClass() + " as an " + componentType); if (obj instanceof BytesMarshallable) { ((BytesMarshallable) obj).writeMarshallable(this); return;
private static MessageHistory readHistoryFromBytes(final Wire wire, MessageHistory history) { final Bytes<?> bytes = wire.bytes(); if (MESSAGE_HISTORY_METHOD_ID != wire.readEventNumber()) return null; ((BytesMarshallable) history).readMarshallable(bytes); return history; }
@Override public void writeTo(RandomDataOutput target, long targetOffset) { if (bytesInit) { target.write(targetOffset, bytes(), offset(), size()); } else { targetBytes.bytesStore((BytesStore) target, targetOffset, target.capacity() - targetOffset); targetBytes.writePosition(targetOffset); instance.writeMarshallable(targetBytes); targetBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0); } }
@Override public T getUsing(@Nullable T using) { if (using == null) using = createInstance(); initBytes(); using.readMarshallable(bytes); bytes.readPosition(0); return using; }
default <T> T readObject(Class<T> componentType) { if (BytesMarshallable.class.isAssignableFrom(componentType)) { BytesMarshallable bm = (BytesMarshallable) ObjectUtils.newInstance(componentType); bm.readMarshallable(this); return (T) bm; } if (Enum.class.isAssignableFrom(componentType)) { return (T) readEnum((Class) componentType); } switch (componentType.getName()) { case "java.lang.String": return (T) readUtf8(); case "java.lang.Double": return (T) (Double) readDouble(); case "java.lang.Long": return (T) (Long) readLong(); case "java.lang.Integer": return (T) (Integer) readInt(); default: throw new UnsupportedOperationException("Unsupported " + componentType); } } }