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 static int ComputePlainBufferRow(PlainBufferRow row) { int size = 0; size += 1; // TAG_ROW_PK foreach (PlainBufferCell cell in row.GetPrimaryKey()) { size += ComputePlainBufferCell(cell); } if (row.GetCells().Count > 0) { size += 1; // TAG_ROW_DATA foreach (PlainBufferCell cell in row.GetCells()) { size += ComputePlainBufferCell(cell); } } if (row.HasDeleteMarker()) { size += 1; // TAG_DELETE_MARKER } if (row.HasExtension()) { size += ComputePlainBufferExtension(row.GetExtension()); } size += 2; // TAG_ROW_CHECKSUM + checksum return(size); }
private Response.OTSResponse DecodeGetRange(byte[] body, out IMessage _message) { var builder = PB.GetRangeResponse.CreateBuilder(); builder.MergeFrom(body); var message = builder.Build(); var response = new Response.GetRangeResponse { ConsumedCapacityUnit = ParseCapacityUnit(message.Consumed.CapacityUnit) }; if (!message.HasNextStartPrimaryKey) { response.NextPrimaryKey = null; } else { var inputStream = new PB.PlainBufferCodedInputStream(message.NextStartPrimaryKey.CreateCodedInput()); var rows = inputStream.ReadRowsWithHeader(); if (rows.Count != 1) { throw new IOException("Expect only one row return. Row count: " + rows.Count); } PB.PlainBufferRow row = rows[0]; if (row.HasDeleteMarker() || row.HasCells()) { throw new IOException("The next primary key should only have primary key: " + row); } response.NextPrimaryKey = PB.PlainBufferConversion.ToPrimaryKey(row.GetPrimaryKey()); } if (message.HasRows && !message.Rows.IsEmpty) { List <DataModel.Row> rows = new List <DataModel.Row>(); var inputStream = new PB.PlainBufferCodedInputStream(message.Rows.CreateCodedInput()); List <PB.PlainBufferRow> pbRows = inputStream.ReadRowsWithHeader(); foreach (var pbRow in pbRows) { rows.Add((DataModel.Row)PB.PlainBufferConversion.ToRow(pbRow)); } response.RowDataList = rows; } if (message.HasNextToken) { response.NextToken = message.NextToken.ToByteArray(); } _message = message; return(response); }
public static IRow ToRow(PlainBufferRow plainBufferRow) { if (plainBufferRow.HasDeleteMarker()) { throw new IOException("Row could not has delete marker: " + plainBufferRow); } if (plainBufferRow.GetPrimaryKey() == null) { throw new IOException("Row has no primary key: " + plainBufferRow); } List <Column> columns = new List <Column>(plainBufferRow.GetCells().Count); foreach (PlainBufferCell cell in plainBufferRow.GetCells()) { columns.Add(ToColumn(cell)); } return(new Row(ToPrimaryKey(plainBufferRow.GetPrimaryKey()), columns)); }
public static byte GetChecksum(byte crc, PlainBufferRow row) { foreach (PlainBufferCell cell in row.GetPrimaryKey()) { crc = crc8(crc, cell.GetChecksum()); } foreach (PlainBufferCell cell in row.GetCells()) { crc = crc8(crc, cell.GetChecksum()); } byte del = 0; if (row.HasDeleteMarker()) { del = (byte)0x1; } crc = crc8(crc, del); return(crc); }