void (final ByteBuffer target, final int offset, final int capacity, final int length, final int redirectTo, final ByteBuffer payload) { if (capacity < MIN_CAPACITY || capacity > MAX_CAPACITY) { throw new IllegalArgumentException("capacity(" + capacity + ") must be in [" + MIN_CAPACITY + ".." + MAX_CAPACITY + "]"); } if (length < 0 || length > MAX_CAPACITY) { throw new IllegalArgumentException("length(" + length + ") must be in [0, " + MAX_CAPACITY + "]"); } final int capacityOverFirstBucket = capacity - MIN_CAPACITY; if ((capacityOverFirstBucket % OFFSET_BUCKET) != 0) { throw new IllegalArgumentException("capacity-MIN (=" + capacityOverFirstBucket + ") must be rounded up to " + OFFSET_BUCKET); } final int packedCapacity = capacityOverFirstBucket >> OFFSET_BUCKET_BITS; final byte headerByte0 = (byte)(RECORD_TYPE_ACTUAL | RECORD_SIZE_TYPE_SMALL | packedCapacity); final byte headerByte1 = (byte)length; target.put(offset, headerByte0); target.put(offset + 1, headerByte1); target.put(offset + HEADER_SIZE, payload, payload.position(), length); }