Exemple #1
0
        public static void WritePrimaryKeyValue(ColumnValue value, PlainBufferOutputStream output)
        {
            if (value.IsInfMin())
            {
                output.WriteRawLittleEndian32(1);
                output.WriteRawByte(PlainBufferConsts.VT_INF_MIN);
                return;
            }

            if (value.IsInfMax())
            {
                output.WriteRawLittleEndian32(1);
                output.WriteRawByte(PlainBufferConsts.VT_INF_MAX);
                return;
            }

            if (value.IsPlaceHolderForAutoIncr())
            {
                output.WriteRawLittleEndian32(1);
                output.WriteRawByte(PlainBufferConsts.VT_AUTO_INCREMENT);
                return;
            }

            switch (value.Type)
            {
            case ColumnValueType.String:
            {
                byte[] rawData      = value.AsStringInBytes();
                int    prefixLength = PlainBufferOutputStream.LITTLE_ENDIAN_32_SIZE + 1; // length + type + length
                output.WriteRawLittleEndian32(prefixLength + rawData.Length);            // length + type + value
                output.WriteRawByte(PlainBufferConsts.VT_STRING);
                output.WriteRawLittleEndian32(rawData.Length);
                output.WriteBytes(rawData);
                break;
            }

            case ColumnValueType.Integer:
            {
                output.WriteRawLittleEndian32(1 + PlainBufferOutputStream.LITTLE_ENDIAN_64_SIZE);
                output.WriteRawByte(PlainBufferConsts.VT_INTEGER);
                output.WriteRawLittleEndian64(value.IntegerValue);
                break;
            }

            case ColumnValueType.Binary:
            {
                byte[] rawData      = value.BinaryValue;
                int    prefixLength = PlainBufferOutputStream.LITTLE_ENDIAN_32_SIZE + 1; // length + type + length
                output.WriteRawLittleEndian32(prefixLength + rawData.Length);            // length + type + value
                output.WriteRawByte(PlainBufferConsts.VT_BLOB);
                output.WriteRawLittleEndian32(rawData.Length);
                output.WriteBytes(rawData);
                break;
            }

            default:
                throw new IOException("Bug: unsupported primary key type: " + value.GetType());
            }
        }
Exemple #2
0
        // Bytes Data: value_type + type
        public static int ComputeColumnValueWithoutLengthPrefix(ColumnValue value)
        {
            int size = 1; // length + type + value

            if (value.IsInfMin() || value.IsInfMax() || value.IsPlaceHolderForAutoIncr())
            {
                return(size); // inf value and AutoIncr only has a type.
            }

            switch (value.Type)
            {
            case ColumnValueType.String:
            {
                size += PlainBufferOutputStream.LITTLE_ENDIAN_32_SIZE;
                size += value.AsStringInBytes().Length;
                break;
            }

            case ColumnValueType.Integer:
            {
                size += PlainBufferOutputStream.LITTLE_ENDIAN_64_SIZE;
                break;
            }

            case ColumnValueType.Binary:
            {
                size += PlainBufferOutputStream.LITTLE_ENDIAN_32_SIZE;
                size += value.BinaryValue.Length;
                break;
            }

            case ColumnValueType.Double:
            {
                size += PlainBufferOutputStream.LITTLE_ENDIAN_64_SIZE;
                break;
            }

            case ColumnValueType.Boolean:
            {
                size += 1;
                break;
            }

            default:
                throw new IOException("Bug: unsupported column type: " + value.Type);
            }

            return(size);
        }
        public void WritePrimaryKeyValueWithoutLengthPrefix(ColumnValue value)
        {
            if (value.IsInfMin())
            {
                output.WriteRawByte(PlainBufferConsts.VT_INF_MIN);
                return;
            }

            if (value.IsInfMax())
            {
                output.WriteRawByte(PlainBufferConsts.VT_INF_MAX);
                return;
            }

            if (value.IsPlaceHolderForAutoIncr())
            {
                output.WriteRawByte(PlainBufferConsts.VT_AUTO_INCREMENT);
                return;
            }

            byte[] rawData;

            switch (value.Type)
            {
            case ColumnValueType.String:
                rawData = value.AsStringInBytes();
                output.WriteRawByte(PlainBufferConsts.VT_STRING);
                output.WriteRawLittleEndian32(rawData.Length);
                output.WriteBytes(rawData);
                break;

            case ColumnValueType.Integer:
                output.WriteRawByte(PlainBufferConsts.VT_INTEGER);
                output.WriteRawLittleEndian64(value.IntegerValue);
                break;

            case ColumnValueType.Binary:
                rawData = value.BinaryValue;
                output.WriteRawByte(PlainBufferConsts.VT_BLOB);
                output.WriteRawLittleEndian32(rawData.Length);
                output.WriteBytes(rawData);
                break;

            default:
                throw new IOException("Bug: unsupported primary key type: " + value.Type);
            }
        }
        public void WriteCellValue(ColumnValue value)
        {
            WriteTag(PlainBufferConsts.TAG_CELL_VALUE);
            if (value.IsInfMin())
            {
                output.WriteRawLittleEndian32(1);
                output.WriteRawByte(PlainBufferConsts.VT_INF_MIN);
                return;
            }

            if (value.IsInfMax())
            {
                output.WriteRawLittleEndian32(1);
                output.WriteRawByte(PlainBufferConsts.VT_INF_MAX);
                return;
            }

            if (value.IsPlaceHolderForAutoIncr())
            {
                output.WriteRawLittleEndian32(1);
                output.WriteRawByte(PlainBufferConsts.VT_AUTO_INCREMENT);
                return;
            }

            byte[] rawData;
            int    prefixLength;

            switch (value.Type)
            {
            case ColumnValueType.String:
                rawData      = value.AsStringInBytes();
                prefixLength = PlainBufferOutputStream.LITTLE_ENDIAN_32_SIZE + 1; // length + type + length
                output.WriteRawLittleEndian32(prefixLength + rawData.Length);     // length + type + value
                output.WriteRawByte(PlainBufferConsts.VT_STRING);
                output.WriteRawLittleEndian32(rawData.Length);
                output.WriteBytes(rawData);
                break;

            case ColumnValueType.Integer:
                output.WriteRawLittleEndian32(1 + PlainBufferOutputStream.LITTLE_ENDIAN_64_SIZE);
                output.WriteRawByte(PlainBufferConsts.VT_INTEGER);
                output.WriteRawLittleEndian64(value.IntegerValue);
                break;

            case ColumnValueType.Binary:
                rawData      = value.BinaryValue;
                prefixLength = PlainBufferOutputStream.LITTLE_ENDIAN_32_SIZE + 1; // length + type + length
                output.WriteRawLittleEndian32(prefixLength + rawData.Length);     // length + type + value
                output.WriteRawByte(PlainBufferConsts.VT_BLOB);
                output.WriteRawLittleEndian32(rawData.Length);
                output.WriteBytes(rawData);
                break;

            case ColumnValueType.Boolean:
                output.WriteRawLittleEndian32(2);
                output.WriteRawByte(PlainBufferConsts.VT_BOOLEAN);
                output.WriteBool(value.BooleanValue);
                break;

            case ColumnValueType.Double:
                output.WriteRawLittleEndian32(1 + PlainBufferOutputStream.LITTLE_ENDIAN_64_SIZE);
                output.WriteRawByte(PlainBufferConsts.VT_DOUBLE);
                output.WriteDouble(value.DoubleValue);
                break;

            default:
                throw new IOException("Bug: unsupported column type: " + value.Type);
            }
        }