private void WriteAttributeContentLength(int attributeContentLength, Span <byte> bytes) { if (attributeContentLength > ushort.MaxValue) { throw new ArgumentOutOfRangeException("Attribute length is too long"); } NetworkBitConverter.WriteBytes(bytes.Slice(2, 2), (ushort)attributeContentLength); }
private static StunIPEndPoint CreateEndPoint(ReadOnlyMemory <byte> address, ReadOnlyMemory <byte> port) { return(new StunIPEndPoint(address, NetworkBitConverter.ToUInt16(port.Span))); }
private static bool IsContentLengthValid(ReadOnlyMemory <byte> bytes) { return(StunMessageHeaderLength + NetworkBitConverter.ToUInt16(bytes.Span.Slice(2, 2)) <= bytes.Length); }
private static ReadOnlyMemory <byte> SliceAttributes(ReadOnlyMemory <byte> bytes) { return(bytes.Slice(StunMessageHeaderLength, NetworkBitConverter.ToUInt16(bytes.Span.Slice(2, 2)))); }
private StunMessage(ReadOnlyMemory <byte> bytes) { Type = new StunMessageType(NetworkBitConverter.ToUInt16(bytes.Span.Slice(0, 2))); TransactionId = new StunTransactionId(bytes.Slice(8, 12)); Attributes = new StunAttributes(SliceAttributes(bytes)); }
private void WriteAttributeType(short attributeType, Span <byte> bytes) { NetworkBitConverter.WriteBytes(bytes.Slice(0, 2), attributeType); }
private void WriteType(Span <byte> bytes) { NetworkBitConverter.WriteBytes(bytes.Slice(0, 2), type); }