/** * Returns a byte array encoded with the tag and little endian 32 */ public static byte[] getTagAndRawLittleEndian32Bytes(int tag, int value) { int tagSize = computeRawVarint32Size(tag); int offset = 0; byte[] buffer = new byte[tagSize + LITTLE_ENDIAN_32_SIZE]; if (tagSize == 1) { buffer[offset++] = (byte) tag; } else { for (int i = 0, last = tagSize - 1; i < last; i++, tag >>>= 7) buffer[offset++] = (byte) ((tag & 0x7F) | 0x80); buffer[offset++] = (byte) tag; } writeRawLittleEndian32(value, buffer, offset); return buffer; }
/** * Returns the buffer encoded with the tag and little endian 32 */ public static LinkedBuffer writeTagAndRawLittleEndian32(int tag, int value, final WriteSession session, LinkedBuffer lb) { final int tagSize = computeRawVarint32Size(tag); final int totalSize = tagSize + LITTLE_ENDIAN_32_SIZE; if (lb.offset + totalSize > lb.buffer.length) lb = new LinkedBuffer(session.nextBufferSize, lb); final byte[] buffer = lb.buffer; int offset = lb.offset; lb.offset += totalSize; session.size += totalSize; if (tagSize == 1) buffer[offset++] = (byte) tag; else { for (int i = 0, last = tagSize - 1; i < last; i++, tag >>>= 7) buffer[offset++] = (byte) ((tag & 0x7F) | 0x80); buffer[offset++] = (byte) tag; } writeRawLittleEndian32(value, buffer, offset); return lb; }