public override int Read(Span <byte> buffer) { var s = part.AsSpan().Slice((int)Position, Math.Min(buffer.Length, part.Length - (int)Position)); s.CopyTo(buffer); Position += s.Length; return(s.Length); }
void ChopTrimPart(IMessagePart part) { var bytes0 = Guid.NewGuid().ToByteArray(); var int0 = (uint)Util.rng.Next(1000, 1000000); var int1 = (uint)Util.rng.Next(1000, 1000000); part.Append(bytes0); part.Insert(int0); part.Insert(int0); part.Trim((UIntPtr)4); part.Trim(out var trim); Assert.Equal(int0, trim); Assert.True(Util.BytesEqual(bytes0, part.AsSpan())); part.Append(int1); part.Append(int1); part.Chop((UIntPtr)4); part.Chop(out var chop); Assert.Equal(int1, chop); Assert.True(Util.BytesEqual(bytes0, part.AsSpan())); }