public void WriteByteWorksIfSegmentHasSpace_CopyTo() { var input = new byte[] { 11, 12, 13 }; using (var bufferWriter = new MemoryBufferWriter()) { bufferWriter.Write(input, 0, input.Length); bufferWriter.WriteByte(14); Assert.Equal(4, bufferWriter.Length); var data = new byte[bufferWriter.Length]; bufferWriter.CopyTo(data); Assert.Equal(11, data[0]); Assert.Equal(12, data[1]); Assert.Equal(13, data[2]); Assert.Equal(14, data[3]); } }
public void WriteRecord(Message <TKey, TValue> message, IBufferWriter <byte> output) { // Record... // length: varint // attributes: int8 // bit 0~7: unused // timestampDelta: varint // offsetDelta: varint // keyLength: varint // key: byte[] // valueLen: varint // value: byte[] // Headers => [Header] // Header... // headerKeyLength: varint // headerKey: String // headerValueLength: varint // Value: byte[] using var buffer = new MemoryBufferWriter(); buffer.WriteByte(0); // attributes: int8 - bit 0~7: unused buffer.WriteVarInt((uint)0); // timestampDelta: varint buffer.WriteVarInt((uint)0); // offsetDelta: varint buffer.WritePrefixed(keySerializer, message.Key, BufferWriterExtensions.PrefixType.VarInt); buffer.WritePrefixed(valueSerializer, message.Value, BufferWriterExtensions.PrefixType.VarInt); // headers buffer.WriteVarInt((ulong)message.HeadersCount); message.ForEachHeader(h => { buffer.WriteCompactString(h.Key); buffer.WritePrefixed(h.Value.AsSpan(), BufferWriterExtensions.PrefixType.VarInt); }); output.WriteVarInt(buffer.Length); buffer.CopyTo(output); }
public void WriteTo(IBufferWriter <byte> output) { output.WriteVarInt(buffer.Length); buffer.CopyTo(output); }