public static void WriteMetadata(this IMetadataEncoder encoder, IBufferWriter <byte> writer, Frame frame) { var metaLength = encoder.GetLength(frame.Metadata); var metaSpan = writer.GetSpan(metaLength); encoder.Write(metaSpan, frame.Metadata); writer.Advance(metaLength); }
public async Task WriteFrameAsync_ShouldSerializeCorrectly(short messageId, int length) { var encodedFrame = FrameProvider.GetRandom(messageId, length); var metadata = new MessageMetadata(messageId, length); var frame = new Frame(encodedFrame.Slice( _encoder.GetLength(metadata)), metadata); var pipe = new Pipe(); var writeResult = await _encoder.WriteFrameAsync(pipe.Writer, frame); Assert.True(!writeResult.IsCompleted && !writeResult.IsCanceled); pipe.Reader.TryRead(out var result); var expected = encodedFrame.ToArray(); var actual = result.Buffer.ToArray(); Assert.Equal(expected, actual); }