/** * Concatenates all fields, in order, to the ByteDataBuffer supplied. This concatenation is the * verbatim serialized representation in the FlatBlob. * * @param buf */ public void writeDataTo(ByteDataBuffer buf) { for (int i = 0; i < fieldData.length; i++) { FieldType fieldType = getSchema().getFieldType(i); if (isNonNull[i]) { if (fieldType.startsWithVarIntEncodedLength()) { VarInt.writeVInt(buf, (int) fieldData[i].length()); } fieldData[i].copyTo(buf); } else { if (fieldType == FieldType.FLOAT) { FastBlobFrameworkSerializer.writeNullFloat(buf); } else if (fieldType == FieldType.DOUBLE) { FastBlobFrameworkSerializer.writeNullDouble(buf); } else { VarInt.writeVNull(buf); } } } }
/** * Returns the number of bytes which will be written when writeDataTo(ByteDataBuffer buf) is * called. * * @param buf */ public int sizeOfData() { int dataSize = 0; for (int i = 0; i < fieldData.length; i++) { FieldType fieldType = getSchema().getFieldType(i); if (isNonNull[i]) { if (fieldType.startsWithVarIntEncodedLength()) { dataSize += VarInt.sizeOfVInt((int) fieldData[i].length()); } dataSize += fieldData[i].length(); } else { if (fieldType == FieldType.FLOAT) { dataSize += 4; } else if (fieldType == FieldType.DOUBLE) { dataSize += 8; } else { dataSize++; } } } return dataSize; }