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());
        }
        public PlainBufferCell ReadCell()
        {
            if (!CheckLastTagWas(PlainBufferConsts.TAG_CELL))
            {
                throw new IOException("Expect TAG_CELL but it was " + PlainBufferConsts.PrintTag(GetLastTag()));
            }

            PlainBufferCell cell = new PlainBufferCell();

            ReadTag();
            if (GetLastTag() == PlainBufferConsts.TAG_CELL_NAME)
            {
                cell.SetCellName(ReadUTFString(ReadUInt32()));
                ReadTag();
            }

            if (GetLastTag() == PlainBufferConsts.TAG_CELL_VALUE)
            {
                cell.SetCellValue(ReadCellValue());
            }

            if (GetLastTag() == PlainBufferConsts.TAG_CELL_TYPE)
            {
                cell.SetCellType(this.inputStream.ReadRawByte());
                ReadTag();
            }

            if (GetLastTag() == PlainBufferConsts.TAG_CELL_TIMESTAMP)
            {
                long timestamp = (long)ReadInt64();
                if (timestamp < 0)
                {
                    throw new IOException("The timestamp is negative.");
                }

                cell.SetCellTimestamp(timestamp);
                ReadTag(); // consume next tag as all read function should consume next tag
            }

            if (GetLastTag() == PlainBufferConsts.TAG_CELL_CHECKSUM)
            {
                byte checksum = this.inputStream.ReadRawByte();
                ReadTag();
                if (cell.GetChecksum() != checksum)
                {
                    throw new IOException("Checksum is mismatch. Cell: " + cell + ". Checksum: " + checksum + ". PlainBuffer: " + this.inputStream);
                }
            }
            else
            {
                throw new IOException("Expect TAG_CELL_CHECKSUM but it was " + PlainBufferConsts.PrintTag(GetLastTag()));
            }

            return(cell);
        }