docs.unity3d.com
    Show / Hide Table of Contents

    Class BytePacker

    Utility class for packing values in serialization. ByteUnpacker to unpack packed values.

    Inheritance
    Object
    BytePacker
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.Netcode
    Syntax
    public static class BytePacker

    Fields

    BitPackedIntMax

    Obsolete value that no longer carries meaning. Do not use.

    Declaration
    public const int BitPackedIntMax = 536870911
    Field Value
    Type Description
    Int32

    BitPackedIntMin

    Obsolete value that no longer carries meaning. Do not use.

    Declaration
    public const int BitPackedIntMin = -536870912
    Field Value
    Type Description
    Int32

    BitPackedLongMax

    Obsolete value that no longer carries meaning. Do not use.

    Declaration
    public const long BitPackedLongMax = 1152921504606846975L
    Field Value
    Type Description
    Int64

    BitPackedLongMin

    Obsolete value that no longer carries meaning. Do not use.

    Declaration
    public const long BitPackedLongMin = -1152921504606846976L
    Field Value
    Type Description
    Int64

    BitPackedShortMax

    Obsolete value that no longer carries meaning. Do not use.

    Declaration
    public const short BitPackedShortMax = 16383
    Field Value
    Type Description
    Int16

    BitPackedShortMin

    Obsolete value that no longer carries meaning. Do not use.

    Declaration
    public const short BitPackedShortMin = -16384
    Field Value
    Type Description
    Int16

    BitPackedUintMax

    Obsolete value that no longer carries meaning. Do not use.

    Declaration
    public const uint BitPackedUintMax = 1073741823U
    Field Value
    Type Description
    UInt32

    BitPackedULongMax

    Obsolete value that no longer carries meaning. Do not use.

    Declaration
    public const ulong BitPackedULongMax = 2305843009213693951UL
    Field Value
    Type Description
    UInt64

    BitPackedUshortMax

    Obsolete value that no longer carries meaning. Do not use.

    Declaration
    public const ushort BitPackedUshortMax = 32767
    Field Value
    Type Description
    UInt16

    Methods

    WriteValueBitPacked(FastBufferWriter, Int16)

    Writes a 16-bit signed short to the buffer in a bit-encoded packed format. Zig-zag encoding is used to move the sign bit to the least significant bit, so that negative values are still able to be compressed. The first two bits indicate whether the value is 1, 2, or 3 bytes. If the value uses 14 bits or less, the remaining 14 bits contain the value. For performance, reasons, if the value is 15 bits or more, there will be six 0 bits, followed by the original unmodified 16-bit value in the next 2 bytes.

    Declaration
    public static void WriteValueBitPacked(FastBufferWriter writer, short value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Int16 value

    The value to pack

    WriteValueBitPacked(FastBufferWriter, Int32)

    Writes a 32-bit signed int to the buffer in a bit-encoded packed format. Zig-zag encoding is used to move the sign bit to the least significant bit, so that negative values are still able to be compressed. The first three bits indicate whether the value is 1, 2, 3, 4, or 5 bytes. If the value uses 29 bits or less, the remaining 29 bits contain the value. For performance, reasons, if the value is 30 bits or more, there will be five 0 bits, followed by the original unmodified 32-bit value in the next 4 bytes.

    Declaration
    public static void WriteValueBitPacked(FastBufferWriter writer, int value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Int32 value

    The value to pack

    WriteValueBitPacked(FastBufferWriter, Int64)

    Writes a 64-bit signed long to the buffer in a bit-encoded packed format. Zig-zag encoding is used to move the sign bit to the least significant bit, so that negative values are still able to be compressed. The first four bits indicate whether the value is 1, 2, 3, 4, 5, 6, 7, 8, or 9 bytes. If the value uses 60 bits or less, the remaining 60 bits contain the value. For performance, reasons, if the value is 61 bits or more, there will be four 0 bits, followed by the original unmodified 64-bit value in the next 8 bytes.

    Declaration
    public static void WriteValueBitPacked(FastBufferWriter writer, long value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Int64 value

    The value to pack

    WriteValueBitPacked(FastBufferWriter, UInt16)

    Writes a 16-bit unsigned short to the buffer in a bit-encoded packed format. The first two bits indicate whether the value is 1, 2, or 3 bytes. If the value uses 14 bits or less, the remaining 14 bits contain the value. For performance, reasons, if the value is 15 bits or more, there will be six 0 bits, followed by the original unmodified 16-bit value in the next 2 bytes.

    Declaration
    public static void WriteValueBitPacked(FastBufferWriter writer, ushort value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    UInt16 value

    The value to pack

    WriteValueBitPacked(FastBufferWriter, UInt32)

    Writes a 32-bit unsigned int to the buffer in a bit-encoded packed format. The first three bits indicate whether the value is 1, 2, 3, 4, or 5 bytes. If the value uses 29 bits or less, the remaining 29 bits contain the value. For performance, reasons, if the value is 30 bits or more, there will be five 0 bits, followed by the original unmodified 32-bit value in the next 4 bytes.

    Declaration
    public static void WriteValueBitPacked(FastBufferWriter writer, uint value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    UInt32 value

    The value to pack

    WriteValueBitPacked(FastBufferWriter, UInt64)

    Writes a 64-bit unsigned long to the buffer in a bit-encoded packed format. The first four bits indicate whether the value is 1, 2, 3, 4, 5, 6, 7, 8, or 9 bytes. If the value uses 60 bits or less, the remaining 60 bits contain the value. For performance, reasons, if the value is 61 bits or more, there will be four 0 bits, followed by the original unmodified 64-bit value in the next 8 bytes.

    Declaration
    public static void WriteValueBitPacked(FastBufferWriter writer, ulong value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    UInt64 value

    The value to pack

    WriteValuePacked(FastBufferWriter, Boolean)

    Write a bool to the buffer.

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, bool value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Boolean value

    Value to write

    WriteValuePacked(FastBufferWriter, Byte)

    Write a byte to the buffer.

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, byte value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Byte value

    Value to write

    WriteValuePacked(FastBufferWriter, Char)

    Write a two-byte character as a varint to the buffer. WARNING: If the value you're writing is > 2287, this will use MORE space (3 bytes instead of 2), and if your value is > 240 you'll get no savings at all. Only use this if you're certain your value will be small.

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, char c)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Char c

    Value to write

    WriteValuePacked(FastBufferWriter, Double)

    Write double-precision floating point value to the buffer as a varint

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, double value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Double value

    Value to write

    WriteValuePacked(FastBufferWriter, Int16)

    Write a signed short (Int16) as a ZigZag encoded varint to the buffer. WARNING: If the value you're writing is > 2287, this will use MORE space (3 bytes instead of 2), and if your value is > 240 you'll get no savings at all. Only use this if you're certain your value will be small.

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, short value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Int16 value

    Value to write

    WriteValuePacked(FastBufferWriter, Int32)

    Write a signed int (Int32) as a ZigZag encoded varint to the buffer.

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, int value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Int32 value

    Value to write

    WriteValuePacked(FastBufferWriter, Int64)

    Write a signed long (Int64) as a ZigZag encoded varint to the buffer.

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, long value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Int64 value

    Value to write

    WriteValuePacked(FastBufferWriter, SByte)

    Write a signed byte to the buffer.

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, sbyte value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    SByte value

    Value to write

    WriteValuePacked(FastBufferWriter, Single)

    Write single-precision floating point value to the buffer as a varint

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, float value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Single value

    Value to write

    WriteValuePacked(FastBufferWriter, String)

    Writes a string in a packed format

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, string s)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    String s

    The value to pack

    WriteValuePacked(FastBufferWriter, UInt16)

    Write an unsigned short (UInt16) as a varint to the buffer. WARNING: If the value you're writing is > 2287, this will use MORE space (3 bytes instead of 2), and if your value is > 240 you'll get no savings at all. Only use this if you're certain your value will be small.

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, ushort value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    UInt16 value

    Value to write

    WriteValuePacked(FastBufferWriter, UInt32)

    Write an unsigned int (UInt32) to the buffer.

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, uint value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    UInt32 value

    Value to write

    WriteValuePacked(FastBufferWriter, UInt64)

    Write an unsigned long (UInt64) to the buffer.

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, ulong value)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    UInt64 value

    Value to write

    WriteValuePacked(FastBufferWriter, Color)

    Convenience method that writes four varint floats from the color to the buffer

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, Color color)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Color color

    Color to write

    WriteValuePacked(FastBufferWriter, Color32)

    Convenience method that writes four varint floats from the color to the buffer

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, Color32 color)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Color32 color

    Color to write

    WriteValuePacked(FastBufferWriter, Quaternion)

    Writes the rotation to the buffer.

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, Quaternion rotation)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Quaternion rotation

    Rotation to write

    WriteValuePacked(FastBufferWriter, Ray)

    Convenience method that writes two packed Vector3 from the ray to the buffer

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, Ray ray)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Ray ray

    Ray to write

    WriteValuePacked(FastBufferWriter, Ray2D)

    Convenience method that writes two packed Vector2 from the ray to the buffer

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, Ray2D ray2d)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Ray2D ray2d

    Ray2D to write

    WriteValuePacked(FastBufferWriter, Vector2)

    Convenience method that writes two varint floats from the vector to the buffer

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, Vector2 vector2)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Vector2 vector2

    Vector to write

    WriteValuePacked(FastBufferWriter, Vector3)

    Convenience method that writes three varint floats from the vector to the buffer

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, Vector3 vector3)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Vector3 vector3

    Vector to write

    WriteValuePacked(FastBufferWriter, Vector4)

    Convenience method that writes four varint floats from the vector to the buffer

    Declaration
    public static void WriteValuePacked(FastBufferWriter writer, Vector4 vector4)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    Vector4 vector4

    Vector to write

    WriteValuePacked<TEnum>(FastBufferWriter, TEnum)

    Write a packed enum value.

    Declaration
    public static void WriteValuePacked<TEnum>(FastBufferWriter writer, TEnum value)
        where TEnum : struct, Enum
    Parameters
    Type Name Description
    FastBufferWriter writer

    The writer to write to

    TEnum value

    The value to write

    Type Parameters
    Name Description
    TEnum

    An enum type

    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on 26 October 2023