public static int getNumBytesToStoreLength(int strlen) { return VarLenIntEncoderDecoder.getBytesRequired(strlen); }
public static int getNumberBytesToStoreMeta(int length) { return VarLenIntEncoderDecoder.getBytesRequired(length); }
@Override protected int getFieldSlotsBytes(ITupleReference tuple) { int fieldSlotBytes = 0; for (int i = inputKeyFieldCount; i < inputTotalFieldCount; i++) { if (!typeTraits[i].isFixedLength()) { fieldSlotBytes += VarLenIntEncoderDecoder.getBytesRequired(tuple.getFieldLength(i)); } } return fieldSlotBytes; }
protected int getFieldSlotsBytes(ITupleReference tuple, int startField, int numFields) { int fieldSlotBytes = 0; for (int i = startField; i < startField + numFields; i++) { if (!typeTraits[i].isFixedLength()) { fieldSlotBytes += VarLenIntEncoderDecoder.getBytesRequired(tuple.getFieldLength(i)); } } return fieldSlotBytes; }
/** * Start to build an variable length object * * @param ary the destination storage array * @param estimateLength the estimate length of this object * @throws IOException */ public void reset(GrowableArray ary, int estimateLength) throws IOException { this.ary = ary; this.out = ary.getDataOutput(); this.startOffset = ary.getLength(); this.estimateMetaLen = VarLenIntEncoderDecoder.getBytesRequired(estimateLength); // increase the offset for (int i = 0; i < estimateMetaLen; i++) { out.writeByte(0); } }
protected int getFieldSlotsBytes(ITupleReference tuple) { int fieldSlotBytes = 0; for (int i = 0; i < tuple.getFieldCount(); i++) { if (!typeTraits[i].isFixedLength()) { fieldSlotBytes += VarLenIntEncoderDecoder.getBytesRequired(tuple.getFieldLength(i)); } } return fieldSlotBytes; }
@Test public void testGetBytesRequired() throws Exception { for (int bound = 0; bound < bounds.length - 1; bound++) { assertEquals(bound + 1, getBytesRequired(bounds[bound])); assertEquals(bound + 1, getBytesRequired(bounds[bound + 1] - 1)); } }
int actualMetaLen = VarLenIntEncoderDecoder.getBytesRequired(actualDataLength); if (actualMetaLen != estimateMetaLen) {// ugly but rare situation if the estimate vary a lot int diff = estimateMetaLen - actualMetaLen;