public void WriteRow(PlainBufferRow row) { WriteTag(PlainBufferConsts.TAG_ROW_PK); foreach (PlainBufferCell cell in row.GetPrimaryKey()) { WriteCell(cell); } if (row.GetCells().Count > 0) { WriteTag(PlainBufferConsts.TAG_ROW_DATA); foreach (PlainBufferCell cell in row.GetCells()) { WriteCell(cell); } } if (row.HasDeleteMarker()) { WriteTag(PlainBufferConsts.TAG_DELETE_ROW_MARKER); } if (row.HasExtension()) { WriteExtension(row.GetExtension()); } WriteTag(PlainBufferConsts.TAG_ROW_CHECKSUM); output.WriteRawByte(row.GetChecksum()); }
public PlainBufferRow ReadRow() { List <PlainBufferCell> columns = new List <PlainBufferCell>(); List <PlainBufferCell> primaryKey = new List <PlainBufferCell>(); bool hasDeleteMarker = false; if (CheckLastTagWas(PlainBufferConsts.TAG_ROW_PK)) { primaryKey = ReadRowPK(); if (primaryKey.Count <= 0) { throw new IOException("The primary key of row is empty."); } } if (CheckLastTagWas(PlainBufferConsts.TAG_ROW_DATA)) { columns = ReadRowData(); } if (CheckLastTagWas(PlainBufferConsts.TAG_DELETE_ROW_MARKER)) { hasDeleteMarker = true; ReadTag(); } PlainBufferRow row = new PlainBufferRow(primaryKey, columns, hasDeleteMarker); row.SetExtension(ReadExtension()); if (CheckLastTagWas(PlainBufferConsts.TAG_ROW_CHECKSUM)) { byte checksum = this.inputStream.ReadRawByte(); ReadTag(); if (row.GetChecksum() != checksum) { throw new IOException("Checksum is mismatch.Row: " + row + ". Checksum: " + checksum + ". PlainBuffer: " + this.inputStream); } } else { throw new IOException("Expect TAG_ROW_CHECKSUM but it was " + PlainBufferConsts.PrintTag(GetLastTag())); } return(row); }