writeColumnValueWithChecksum: function()

in lib/protocol/plain_buffer_coded_stream.js [365:413]


    writeColumnValueWithChecksum: function (value, cellCheckSum) {
        this.writeTag(TableStore.plainBufferConsts.TAG_CELL_VALUE);
        if (value instanceof Int64buf.Int64LE) {
            this.outputStream.writeRawLittleEndian32(1 + TableStore.plainBufferConsts.LITTLE_ENDIAN_64_SIZE);
            this.outputStream.writeRawByte(TableStore.plainBufferConsts.VT_INTEGER);
            this.outputStream.writeInt64LE(value);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, TableStore.plainBufferConsts.VT_INTEGER);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt64Buf(cellCheckSum, value.toBuffer());
        } else if (typeof (value) === 'string') {
            var stringValueLength = TableStore.util.string.byteLength(value);
            var prefix_length = TableStore.plainBufferConsts.LITTLE_ENDIAN_32_SIZE + 1;
            this.outputStream.writeRawLittleEndian32(prefix_length + stringValueLength);
            this.outputStream.writeRawByte(TableStore.plainBufferConsts.VT_STRING);
            this.outputStream.writeRawLittleEndian32(stringValueLength);
            this.outputStream.writeBytes(value);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, TableStore.plainBufferConsts.VT_STRING);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt32(cellCheckSum, stringValueLength);
            cellCheckSum = TableStore.plainBufferCrc8.crcString(cellCheckSum, value);
        } else if (value instanceof Buffer) {
            prefix_length = TableStore.plainBufferConsts.LITTLE_ENDIAN_32_SIZE + 1
            this.outputStream.writeRawLittleEndian32(prefix_length + value.length);
            this.outputStream.writeRawByte(TableStore.plainBufferConsts.VT_BLOB);
            this.outputStream.writeRawLittleEndian32(value.length);
            this.outputStream.writeBytes(value);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, TableStore.plainBufferConsts.VT_BLOB);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt32(cellCheckSum, value.length);
            cellCheckSum = TableStore.plainBufferCrc8.crcString(cellCheckSum, value);
        } else if (typeof (value) === 'boolean') {
            this.outputStream.writeRawLittleEndian32(2);
            this.outputStream.writeRawByte(TableStore.plainBufferConsts.VT_BOOLEAN);
            this.outputStream.writeBoolean(value);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, TableStore.plainBufferConsts.VT_BOOLEAN);
            if (value) {
                cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, 1);
            } else {
                cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, 0);
            }
        } else if (typeof (value) === 'number') {
            var int64 = TableStore.util.Int64.doubleToRawLongBits(value);
            this.outputStream.writeRawLittleEndian32(1 + TableStore.plainBufferConsts.LITTLE_ENDIAN_64_SIZE);
            this.outputStream.writeRawByte(TableStore.plainBufferConsts.VT_DOUBLE);
            this.outputStream.writeDouble(value);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, TableStore.plainBufferConsts.VT_DOUBLE);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt64Buf(cellCheckSum, int64.toBuffer());
        } else {
            throw new Error("Unsupported column type " + typeof (value));
        }
        return cellCheckSum;
    },