Any Attribute that holds an immutable view of a byte array More...
Inherits NobleConnect.Stun.Attribute.
Public Member Functions | |
AttributeData (AttributeType attributeType, ArraySegment< byte > payload) | |
Construct an AttributeData of the provided AttributeType using the provided ArraySegment of bytes as the payload. More... | |
AttributeData (AttributeType type, byte[] buffer, ref int offset) | |
Construct an AttributeData from the provided byte array More... | |
override void | SerializeValues (BufferView buffer, ReadOnlyByteArray transactionID) |
Serialize the payload to the provided buffer. More... | |
void | SendTo (Socket socket, EndPoint endPoint) |
Send the payload over the provided socket to the provided end point More... | |
byte[] | AsArray () |
Get a copy of the payload as a byte array More... | |
override ushort | GetValueSize () |
Get the serialized size of the attribute values More... | |
![]() | |
Attribute (AttributeType type) | |
Construct an Attribute of the provided AttributeType More... | |
Attribute (AttributeType type, ref int offset) | |
void | Serialize (BufferView buffer, ReadOnlyByteArray transactionID) |
Convert this attribute to a bunch of bytes and add them to the provided buffer More... | |
ushort | GetSize () |
Public Attributes | |
readonly ImmutableArraySegment< byte > | payload |
This is a thread-safe, immutable view into a byte array. More... | |
![]() | |
readonly AttributeType | attributeType |
The AttributeType of this Attribute More... | |
Additional Inherited Members | |
![]() | |
static ushort | DeserializeLength (byte[] buffer, ref int offset) |
Read the Attribute length from a byte array. More... | |
static ushort | GetNumPaddingBytes (int length) |
Calculate padding based on length More... | |
![]() | |
const int | HEADER_SIZE = 4 |
Any Attribute that holds an immutable view of a byte array
This Attribute has been carefully designed to hold an immutable view of a byte array. The backing array can not be accessed directly, as this would make it unsafe to share this Attribute across threads. You can however get a copy of the byte data using AsArray().
Methods are also provided to serialize the backing array to a Buffer or send it out over a socket.
The unsafe ArraySegment is kept around internally for performance reasons. For some applications it is useful to be able to receive a Data message from the Turn server and immediately send it back out over another socket. The design of this class allows for the incoming bytes from one socket to be passed directly out over another with no copying, while still maintaining thread-safety by being immutable.
NobleConnect.Stun.AttributeData.AttributeData | ( | AttributeType | attributeType, |
ArraySegment< byte > | payload | ||
) |
Construct an AttributeData of the provided AttributeType using the provided ArraySegment of bytes as the payload.
This is called when constructing an Attribute to send to a Stun server.
attributeType | |
value |
NobleConnect.Stun.AttributeData.AttributeData | ( | AttributeType | type, |
byte[] | buffer, | ||
ref int | offset | ||
) |
Construct an AttributeData from the provided byte array
The first 2 bytes of the byte array should contain the length of the payload. This is called when deserializing an AttributeData from a Stun server.
type | |
buffer | |
offset |
byte [] NobleConnect.Stun.AttributeData.AsArray | ( | ) |
Get a copy of the payload as a byte array
|
virtual |
Get the serialized size of the attribute values
Reimplemented from NobleConnect.Stun.Attribute.
void NobleConnect.Stun.AttributeData.SendTo | ( | Socket | socket, |
EndPoint | endPoint | ||
) |
Send the payload over the provided socket to the provided end point
socket | |
endPoint |
|
virtual |
Serialize the payload to the provided buffer.
This is safe because there is no way to do anything with the data on the buffer other than read it.
Reimplemented from NobleConnect.Stun.Attribute.
readonly ImmutableArraySegment<byte> NobleConnect.Stun.AttributeData.payload |
This is a thread-safe, immutable view into a byte array.