ByteBuffer (final ByteBuffer buffer, final int encodedAttributeId, final int sizeOrRefId) { assert encodedAttributeId <= MAX_SUPPORTED_ATTRIBUTE_ID : "attributeId: " + encodedAttributeId + " > max " + MAX_SUPPORTED_ATTRIBUTE_ID; if (fitsTinyEntry(encodedAttributeId, sizeOrRefId)) { final byte firstByte = (byte)((encodedAttributeId << TINY_ENTRY_SIZE_BITS) | sizeOrRefId); return buffer.put(firstByte); } else if (fitsMediumEntry(encodedAttributeId, sizeOrRefId)) { final byte firstByte = (byte)(encodedAttributeId | TINY_ENTRY_MASK); return buffer.put(firstByte) .put((byte)sizeOrRefId); } else { final int attributeLow8Bits = encodedAttributeId & 0xFF; final int attributeHigh6Bits = encodedAttributeId >> 8; assert (attributeHigh6Bits & BIG_ENTRY_MASK) == 0 : "attributeId: " + encodedAttributeId + " is larger than possible"; final byte firstByte = (byte)(attributeHigh6Bits | BIG_ENTRY_MASK); return buffer.put(firstByte) .put((byte)attributeLow8Bits) .putInt(sizeOrRefId); } }