writePrimaryKeyValue: function()

in lib/protocol/plain_buffer_coded_stream.js [314:363]


    writePrimaryKeyValue: function (value, cellCheckSum) {
        this.writeTag(TableStore.plainBufferConsts.TAG_CELL_VALUE);
        if (value === TableStore.INF_MIN) {
            this.outputStream.writeRawLittleEndian32(1);
            this.outputStream.writeRawByte(TableStore.plainBufferConsts.VT_INF_MIN);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, TableStore.plainBufferConsts.VT_INF_MIN);
        } else if (value === TableStore.INF_MAX) {
            this.outputStream.writeRawLittleEndian32(1);
            this.outputStream.writeRawByte(TableStore.plainBufferConsts.VT_INF_MAX);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, TableStore.plainBufferConsts.VT_INF_MAX);
        } else if (value === TableStore.PK_AUTO_INCR) {
            this.outputStream.writeRawLittleEndian32(1);
            this.outputStream.writeRawByte(TableStore.plainBufferConsts.VT_AUTO_INCREMENT);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, TableStore.plainBufferConsts.VT_AUTO_INCREMENT);
        } else 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 string_value = value;
            var stringValueLength = TableStore.util.string.byteLength(string_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(string_value);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, TableStore.plainBufferConsts.VT_STRING);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt32(cellCheckSum, stringValueLength);
            cellCheckSum = TableStore.plainBufferCrc8.crcString(cellCheckSum, string_value);
        } else if (value instanceof Buffer) {
            var binary_value = value;
            var prefix_length = TableStore.plainBufferConsts.LITTLE_ENDIAN_32_SIZE + 1;

            this.outputStream.writeRawLittleEndian32(prefix_length + binary_value.length);
            this.outputStream.writeRawByte(TableStore.plainBufferConsts.VT_BLOB);
            this.outputStream.writeRawLittleEndian32(binary_value.length);
            this.outputStream.writeBytes(binary_value);

            cellCheckSum = TableStore.plainBufferCrc8.crcInt8(cellCheckSum, TableStore.plainBufferConsts.VT_BLOB);
            cellCheckSum = TableStore.plainBufferCrc8.crcInt32(cellCheckSum, binary_value.length);
            cellCheckSum = TableStore.plainBufferCrc8.crcString(cellCheckSum, binary_value);
        } else {
            throw new Error("Unsupported primary key type: " + typeof (value));
        }
        return cellCheckSum;

    },