docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct PacketProcessor

    An API representing a packet acquired from a PacketsQueue, and which allows modifying the packet. The packet is represented as a slice inside a fixed-size buffer, which is why APIs like BytesAvailableAtEnd are offered.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    ValueType.ToString()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Networking.Transport
    Assembly: Unity.Networking.Transport.dll
    Syntax
    public struct PacketProcessor

    Properties

    BytesAvailableAtEnd

    Bytes available in the buffer after the end of the packet.

    Declaration
    public int BytesAvailableAtEnd { get; }
    Property Value
    Type Description
    int

    Size in bytes.

    BytesAvailableAtStart

    Bytes available in the buffer before the start of the packet.

    Declaration
    public int BytesAvailableAtStart { get; }
    Property Value
    Type Description
    int

    Size in bytes.

    Capacity

    Size of the buffer containing the packet.

    Declaration
    public int Capacity { get; }
    Property Value
    Type Description
    int

    Size in bytes.

    EndpointRef

    A reference to the endpoint of the packet. For packets in the receive queue, this is the endpoint from which the packet was received. For packets in the send queue, this is the endpoint the packet is destined to. This must be set appropriately for newly-enqueued packets.

    Declaration
    public ref NetworkEndpoint EndpointRef { get; }
    Property Value
    Type Description
    NetworkEndpoint

    Endpoint associated with the packet.

    IsCreated

    Whether the packet processor was obtained from a valid PacketsQueue.

    Declaration
    public bool IsCreated { get; }
    Property Value
    Type Description
    bool

    True if obtained from a valid queue, false otherwise.

    Length

    Size of the packet's data inside the buffer.

    Declaration
    public int Length { get; }
    Property Value
    Type Description
    int

    Size in bytes.

    Offset

    Offset of the packet's first byte inside the buffer.

    Declaration
    public int Offset { get; }
    Property Value
    Type Description
    int

    Offset in bytes.

    Methods

    AppendToPayload(void*, int)

    Copy the provided bytes at the end of the packet and increases its size accordingly.

    Declaration
    public void AppendToPayload(void* dataPtr, int size)
    Parameters
    Type Name Description
    void* dataPtr

    Pointer to the data to copy.

    int size

    Size in bytes to copy.

    Exceptions
    Type Condition
    ArgumentException

    If there are not enough bytes available at the end of the packet. Only thrown when collections checks are enabled (i.e. in the editor). Otherwise an error is logged and nothing is copied.

    AppendToPayload(PacketProcessor)

    Append the content of the given packet at the end of this one.

    Declaration
    public void AppendToPayload(PacketProcessor processor)
    Parameters
    Type Name Description
    PacketProcessor processor

    Packet processor to copy the data from.

    Exceptions
    Type Condition
    ArgumentException

    If there are not enough bytes available at the end of the packet. Only thrown when collections checks are enabled (i.e. in the editor). Otherwise an error is logged and nothing is copied.

    AppendToPayload<T>(T)

    Copy the provided value at the end of the packet and increase its size accordingly.

    Declaration
    public void AppendToPayload<T>(T value) where T : unmanaged
    Parameters
    Type Name Description
    T value

    Value to copy.

    Type Parameters
    Name Description
    T

    Type of the data to copy.

    Exceptions
    Type Condition
    ArgumentException

    If there are not enough bytes available at the end of the packet. Only thrown when collections checks are enabled (i.e. in the editor). Otherwise an error is logged and nothing is copied.

    CopyPayload(void*, int)

    Fill the provided buffer with the data at the start of the payload. The copied data will remain in the packet (compare to RemoveFromPayloadStart(void*, int) which removes the data from the packet).

    Declaration
    public int CopyPayload(void* destinationPtr, int size)
    Parameters
    Type Name Description
    void* destinationPtr

    Pointer to the buffer data will be copied to.

    int size
    Returns
    Type Description
    int

    Ammount of bytes copied.

    Exceptions
    Type Condition
    ArgumentException

    If the buffer is larger than the packet. Only thrown when collections checks are enabled (i.e. in the editor). Otherwise an error is logged and nothing is copied.

    Drop()

    Drop the packet from its queue by setting its length to 0. Packets with a length of 0 are considered to be dropped from the queue and will be batch-recycled at the end of the update cycle. This is more performant than properly releasing packets one at a time.

    Declaration
    public void Drop()

    GetPayloadDataRef<T>(int)

    Get a reference to the payload data reinterpreted to the type T.

    Declaration
    public ref T GetPayloadDataRef<T>(int offset = 0) where T : unmanaged
    Parameters
    Type Name Description
    int offset

    Offset from the start of the payload.

    Returns
    Type Description
    T

    Returns a reference to the payload data

    Type Parameters
    Name Description
    T

    Type of the data.

    Exceptions
    Type Condition
    ArgumentException

    If there is not enough bytes in the payload for the specified type. Only thrown when collections checks are enabled (i.e. in the editor). Otherwise the obtained reference may be partially corrupted.

    GetUnsafePayloadPtr()

    Get a raw pointer to the packet data.

    Declaration
    public void* GetUnsafePayloadPtr()
    Returns
    Type Description
    void*

    A pointer to the packet data.

    PrependToPayload<T>(T)

    Copy the provided value at the start of the packet and increase its size accordingly.

    Declaration
    public void PrependToPayload<T>(T value) where T : unmanaged
    Parameters
    Type Name Description
    T value

    Value to copy.

    Type Parameters
    Name Description
    T

    Type of the data to copy.

    Exceptions
    Type Condition
    ArgumentException

    If there are not enough bytes available at the start of the packet. Only thrown when collections checks are enabled (i.e. in the editor). Otherwise an error is logged and nothing is copied.

    RemoveFromPayloadStart(void*, int)

    Fill the provided buffer with the data at the start of the payload, and remove that data from the packet, decreasing its size accordingly.

    Declaration
    public void RemoveFromPayloadStart(void* ptr, int size)
    Parameters
    Type Name Description
    void* ptr

    Pointer to the start of the buffer to fill.

    int size

    Size of the buffer to fill.

    Exceptions
    Type Condition
    ArgumentException

    If the buffer is larger than the packet. Only thrown when collections checks are enabled (i.e. in the editor). Otherwise an error is logged and nothing is copied.

    RemoveFromPayloadStart<T>()

    Get and remove data at the start of the payload reinterpreted to the type T.

    Declaration
    public T RemoveFromPayloadStart<T>() where T : unmanaged
    Returns
    Type Description
    T

    Extracted data value.

    Type Parameters
    Name Description
    T

    Type of the data.

    Exceptions
    Type Condition
    ArgumentException

    If there are not enough bytes available at the start of the packet. Only thrown when collections checks are enabled (i.e. in the editor). Otherwise an error is logged and a default value is returned.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)