private int ReadInt32B(ref ReadOnlySequence <byte> bytes) { if (bytes.Length < 4) { throw new ArgumentException("Not enough bytes.", nameof(bytes)); } var slice = bytes.Slice(bytes.Start, 4); // slice the required bytes int value; if (slice.IsSingleSegment) { var span = slice.FirstSpan(); value = span.ReadInt32(); } else { // enumerate sequence value = bytes.ReadInt32(); } // consume the slice bytes = bytes.Slice(slice.End); return(value); }