/** * Write instance {@code val} into buffer {@code buff}. */ public int encodeShort(byte[] buff, int offset, short val) { return Bytes.putShort(buff, offset, val); } }
private static int encodeUnsignedShort(short v, byte[] b, int o) { checkForSufficientLength(b, o, Bytes.SIZEOF_SHORT); if (v < 0) { throw new RuntimeException(); } Bytes.putShort(b, o, v); return Bytes.SIZEOF_SHORT; }
@Override public int encode(PositionedByteRange dst, Short val) { Bytes.putShort(dst.getBytes(), dst.getOffset() + dst.getPosition(), val); return skip(dst); }
pos = Bytes.putInt(bytes, pos, keylength); pos = Bytes.putInt(bytes, pos, vlength); pos = Bytes.putShort(bytes, pos, (short)(rlength & 0x0000ffff)); pos += rlength; pos = Bytes.putByte(bytes, pos, (byte)(flength & 0x0000ff));
@Test public void testCopyFromArrayToBuffer() { byte[] b = new byte[15]; b[0] = -1; long l = 988L; int i = 135; short s = 7; Bytes.putLong(b, 1, l); Bytes.putShort(b, 9, s); Bytes.putInt(b, 11, i); ByteBuffer buffer = ByteBuffer.allocate(14); ByteBufferUtils.copyFromArrayToBuffer(buffer, b, 1, 14); buffer.rewind(); assertEquals(l, buffer.getLong()); assertEquals(s, buffer.getShort()); assertEquals(i, buffer.getInt()); }
public static int appendKeyTo(final Cell cell, final byte[] output, final int offset) { int nextOffset = offset; nextOffset = Bytes.putShort(output, nextOffset, cell.getRowLength()); nextOffset = CellUtil.copyRowTo(cell, output, nextOffset); nextOffset = Bytes.putByte(output, nextOffset, cell.getFamilyLength()); nextOffset = CellUtil.copyFamilyTo(cell, output, nextOffset); nextOffset = CellUtil.copyQualifierTo(cell, output, nextOffset); nextOffset = Bytes.putLong(output, nextOffset, cell.getTimestamp()); nextOffset = Bytes.putByte(output, nextOffset, cell.getTypeByte()); return nextOffset; }
pos = Bytes.putShort(backingArray, pos, (short)elemLen); IOUtils.readFully(cin, backingArray, pos, elemLen); pos += elemLen;
@Override public int encodeShort(short v, byte[] b, int o) { if (v < 0) { throw new IllegalDataException(); } Bytes.putShort(b, o, v); return Bytes.SIZEOF_SHORT; } }
pos = Bytes.putInt(buffer, pos, keyLength); pos = Bytes.putInt(buffer, pos, vlength); pos = Bytes.putShort(buffer, pos, (short)(rlength & 0x0000ffff)); pos = Bytes.putBytes(buffer, pos, row, roffset, rlength); pos = Bytes.putByte(buffer, pos, (byte) (flength & 0x0000ff));
pos = Bytes.putInt(bytes, pos, keyLength); pos = Bytes.putInt(bytes, pos, vlength); pos = Bytes.putShort(bytes, pos, (short)(rlength & 0x0000ffff)); pos = Bytes.putBytes(bytes, pos, row, roffset, rlength); pos = Bytes.putByte(bytes, pos, (byte)(flength & 0x0000ff));
pos = Bytes.putShort(bytes, pos, (short)(rlength & 0x0000ffff)); pos = Bytes.putBytes(bytes, pos, row, roffset, rlength); pos = Bytes.putByte(bytes, pos, (byte)(flength & 0x0000ff));
/** * Serialize the value bit set into a byte array. The byte array * is expected to have enough room (use {@link #getEstimatedLength()} * to ensure enough room exists. * @param b the byte array into which to put the serialized bit set * @param offset the offset into the byte array * @return the incremented offset */ public int toBytes(byte[] b, int offset) { if (schema == null) { return offset; } // If the total number of possible values is bigger than 16 bits (the // size of a short), then serialize the long array followed by the // array length. if (isVarLength()) { short nLongs = (short)((maxSetBit + BITS_PER_LONG) / BITS_PER_LONG); for (int i = 0; i < nLongs; i++) { offset = Bytes.putLong(b, offset, bits[i]); } offset = Bytes.putShort(b, offset, nLongs); } else { // Else if the number of values is less than or equal to 16, // serialize the bits directly into a short. offset = Bytes.putShort(b, offset, (short)bits[0]); } return offset; }
/** * Serialize the value bit set into a byte array. The byte array * is expected to have enough room (use {@link #getEstimatedLength()} * to ensure enough room exists. * @param b the byte array into which to put the serialized bit set * @param offset the offset into the byte array * @return the incremented offset */ public int toBytes(byte[] b, int offset) { if (schema == null) { return offset; } // If the total number of possible values is bigger than 16 bits (the // size of a short), then serialize the long array followed by the // array length. if (isVarLength()) { short nLongs = (short)((maxSetBit + BITS_PER_LONG - 1) / BITS_PER_LONG); for (int i = 0; i < nLongs; i++) { offset = Bytes.putLong(b, offset, bits[i]); } offset = Bytes.putShort(b, offset, nLongs); } else { // Else if the number of values is less than or equal to 16, // serialize the bits directly into a short. offset = Bytes.putShort(b, offset, (short)bits[0]); } return offset; }
compression.getDictionary(CompressionContext.DictionaryIndex.ROW)); checkLength(elemLen, Short.MAX_VALUE); pos = Bytes.putShort(backingArray, pos, (short)elemLen); pos += elemLen;
@Override public int encodeShort(short v, byte[] b, int o) { checkForSufficientLength(b, o, Bytes.SIZEOF_SHORT); if (v < 0) { throw newIllegalDataException(); } Bytes.putShort(b, o, v); return Bytes.SIZEOF_SHORT; } }
int offsetArrayElementSize = useShortNew ? Bytes.SIZEOF_SHORT : Bytes.SIZEOF_INT; if (useShortNew) { Bytes.putShort(newArray, currentPosition, (short)(0 - Short.MAX_VALUE)); } else { Bytes.putInt(newArray, currentPosition, 0); if (arrayBytes[offset + oldOffset] == QueryConstants.SEPARATOR_BYTE && nullsAtBeginning) { if (useShortNew) { Bytes.putShort(newArray, currentPosition, (short)(oldOffset - Short.MAX_VALUE)); } else { Bytes.putInt(newArray, currentPosition, oldOffset); Bytes.putShort(newArray, currentPosition, (short)(oldOffset + offsetShift - Short.MAX_VALUE)); } else { Bytes.putInt(newArray, currentPosition, oldOffset + offsetShift);
? (short) pos : (short) (pos - Short.MAX_VALUE); Bytes.putShort(offsetArr, off, val); off += Bytes.SIZEOF_SHORT;
System.arraycopy(arrayBytes, offset + offsetArrayPosition, newArray, newOffsetArrayPosition, offsetArrayLength); Bytes.putShort(newArray, newOffsetArrayPosition + offsetArrayLength, (short)(newElementPosition - Short.MAX_VALUE));
int offset = getOffset(array1Bytes, index, !useIntArray1, array1BytesOffset + offsetArrayPositionArray1, serializationVersion1); Bytes.putShort(newArray, currentPosition, (short)(offset - Short.MAX_VALUE)); currentPosition += Bytes.SIZEOF_SHORT; int offset = getOffset(array2Bytes, index, !useIntArray2, array2BytesOffset + offsetArrayPositionArray2, serializationVersion2); Bytes.putShort(newArray, currentPosition, (short)(offset + array2StartingPosition - Short.MAX_VALUE)); currentPosition += Bytes.SIZEOF_SHORT; int offset = getOffset(array2Bytes, index, !useIntArray2, array2BytesOffset + offsetArrayPositionArray2, serializationVersion2); Bytes.putShort(newArray, currentPosition, (short)(offset - array2FirstNonNullElementOffset + part2NonNullStartingPosition - Short.MAX_VALUE)); currentPosition += Bytes.SIZEOF_SHORT;
@Override public int encode(PositionedByteRange dst, Short val) { Bytes.putShort(dst.getBytes(), dst.getOffset() + dst.getPosition(), val); return skip(dst); }