コード例 #1
0
        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);
        }
コード例 #2
0
 private static StunIPEndPoint CreateEndPoint(ReadOnlyMemory <byte> address, ReadOnlyMemory <byte> port)
 {
     return(new StunIPEndPoint(address, NetworkBitConverter.ToUInt16(port.Span)));
 }
コード例 #3
0
 private static bool IsContentLengthValid(ReadOnlyMemory <byte> bytes)
 {
     return(StunMessageHeaderLength + NetworkBitConverter.ToUInt16(bytes.Span.Slice(2, 2)) <= bytes.Length);
 }
コード例 #4
0
 private static ReadOnlyMemory <byte> SliceAttributes(ReadOnlyMemory <byte> bytes)
 {
     return(bytes.Slice(StunMessageHeaderLength, NetworkBitConverter.ToUInt16(bytes.Span.Slice(2, 2))));
 }
コード例 #5
0
 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));
 }
コード例 #6
0
 private void WriteAttributeType(short attributeType, Span <byte> bytes)
 {
     NetworkBitConverter.WriteBytes(bytes.Slice(0, 2), attributeType);
 }
コード例 #7
0
 private void WriteType(Span <byte> bytes)
 {
     NetworkBitConverter.WriteBytes(bytes.Slice(0, 2), type);
 }