public void WriteCell(PlainBufferCell cell)
        {
            WriteTag(PlainBufferConsts.TAG_CELL);

            if (cell.HasCellName())
            {
                WriteCellName(cell.GetNameRawData());
            }

            if (cell.HasCellValue())
            {
                var columnValue = cell.IsPk() ? cell.GetPkCellValue() : cell.GetCellValue();
                WriteCellValue(columnValue);
            }

            if (cell.HasCellType())
            {
                WriteTag(PlainBufferConsts.TAG_CELL_TYPE);
                output.WriteRawByte(cell.GetCellType());
            }

            if (cell.HasCellTimestamp())
            {
                WriteTag(PlainBufferConsts.TAG_CELL_TIMESTAMP);
                output.WriteRawLittleEndian64(cell.GetCellTimestamp());
            }

            WriteTag(PlainBufferConsts.TAG_CELL_CHECKSUM);
            output.WriteRawByte(cell.GetChecksum());
        }
Exemplo n.º 2
0
        public static int ComputePlainBufferCell(PlainBufferCell cell)
        {
            int size = 1; // TAG_CELL

            if (cell.HasCellName())
            {
                size += 1;                                             // TAG_CELL_NAME
                size += PlainBufferOutputStream.LITTLE_ENDIAN_32_SIZE; // length
                size += cell.GetNameRawData().Length;
            }
            if (cell.HasCellValue())
            {
                size += 1; // TAG_CELL_VALUE
                if (cell.IsPk())
                {
                    size += ComputePrimaryKeyValue(cell.GetPkCellValue());
                }
                else
                {
                    size += ComputeColumnValue(cell.GetCellValue());
                }
            }
            if (cell.HasCellType())
            {
                size += 2; // TAG_CELL_OP_TYPE + type
            }
            if (cell.HasCellTimestamp())
            {
                size += 1 + PlainBufferOutputStream.LITTLE_ENDIAN_64_SIZE; // TAG_CELL_TIMESTAMP + timestamp
            }
            size += 2;                                                     // TAG_CELL_CHECKSUM + checksum
            return(size);
        }
        public static byte GetChecksum(byte crc, PlainBufferCell cell)
        {
            if (cell.HasCellName())
            {
                crc = crc8(crc, cell.GetNameRawData());
            }

            if (cell.HasCellValue())
            {
                if (cell.IsPk())
                {
                    crc = cell.GetPkCellValue().GetChecksum(crc);
                }
                else
                {
                    crc = cell.GetCellValue().GetChecksum(crc);
                }
            }

            if (cell.HasCellTimestamp())
            {
                crc = crc8(crc, cell.GetCellTimestamp());
            }

            if (cell.HasCellType())
            {
                crc = crc8(crc, cell.GetCellType());
            }

            return(crc);
        }
Exemplo n.º 4
0
        public static Column ToColumn(PlainBufferCell cell)
        {
            if (!cell.HasCellName() || !cell.HasCellValue())
            {
                throw new IOException("The cell has no name or value: " + cell);
            }

            if (cell.HasCellType() && cell.GetCellType() != PlainBufferConsts.INCREMENT)
            {
                throw new IOException("The cell should not has type: " + cell);
            }

            if (cell.HasCellTimestamp())
            {
                return(new Column(cell.GetCellName(), cell.GetCellValue(), cell.GetCellTimestamp()));
            }
            else
            {
                return(new Column(cell.GetCellName(), cell.GetCellValue()));
            }
        }