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); }