public static void serialiseView(View view, ByteBuf buf) { buf.writeInt(view.id); buf.writeInt(view.members.size()); for (Address addr : view.members) { AddressSerializer.INSTANCE.toBinary(addr, buf); } }
public static byte[] serialiseAddress(Address addr) { ByteBuf buf = Unpooled.buffer(); AddressSerializer.INSTANCE.toBinary(addr, buf); byte[] bytes = new byte[buf.readableBytes()]; buf.readBytes(bytes); buf.release(); return bytes; }
public static View deserialiseView(ByteBuf buf) { int id = buf.readInt(); int memsize = buf.readInt(); ImmutableSortedSet.Builder<Address> addrs = ImmutableSortedSet.naturalOrder(); for (int i = 0; i < memsize; i++) { Address addr = (Address) AddressSerializer.INSTANCE.fromBinary(buf, Optional.absent()); addrs.add(addr); } return new View(addrs.build(), id); }
public static Address deserialiseAddress(byte[] data) { ByteBuf buf = Unpooled.wrappedBuffer(data); Address addr = (Address) AddressSerializer.INSTANCE.fromBinary(buf, Optional.absent()); buf.release(); return addr; }