private int EXTRA_HEADERS_WO_SIZE = EXTRA_HEADERS_LEN - 4;
@Override
protected void encode(ChannelHandlerContext ctx, Segment s, ByteBuf out)
throws Exception {
SegmentId id = s.getSegmentId();
ByteArrayOutputStream baos = new ByteArrayOutputStream(s.size());
s.writeTo(baos);
byte[] segment = baos.toByteArray();
Hasher hasher = Hashing.murmur3_32().newHasher();
long hash = hasher.putBytes(segment).hash().padToLong();
int len = segment.length + EXTRA_HEADERS_WO_SIZE;
out.writeInt(len);
out.writeByte(Messages.HEADER_SEGMENT);
out.writeLong(id.getMostSignificantBits());
out.writeLong(id.getLeastSignificantBits());
out.writeLong(hash);
out.writeBytes(segment);
}