docs.unity3d.com
Search Results for

    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
    Assembly: solution.dll
    Syntax
    public static class BytePacker

    Fields

    Name Description
    BitPackedIntMax

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

    BitPackedIntMin

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

    BitPackedLongMax

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

    BitPackedLongMin

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

    BitPackedShortMax

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

    BitPackedShortMin

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

    BitPackedULongMax

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

    BitPackedUintMax

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

    BitPackedUshortMax

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

    Methods

    Name Description
    WriteValueBitPacked(FastBufferWriter, short)

    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.

    WriteValueBitPacked(FastBufferWriter, int)

    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.

    WriteValueBitPacked(FastBufferWriter, long)

    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.

    WriteValueBitPacked(FastBufferWriter, ushort)

    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.

    WriteValueBitPacked(FastBufferWriter, uint)

    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.

    WriteValueBitPacked(FastBufferWriter, ulong)

    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.

    WriteValuePacked(FastBufferWriter, bool)

    Write a bool to the buffer.

    WriteValuePacked(FastBufferWriter, byte)

    Write a byte to the buffer.

    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.

    WriteValuePacked(FastBufferWriter, double)

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

    WriteValuePacked(FastBufferWriter, short)

    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.

    WriteValuePacked(FastBufferWriter, int)

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

    WriteValuePacked(FastBufferWriter, long)

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

    WriteValuePacked(FastBufferWriter, sbyte)

    Write a signed byte to the buffer.

    WriteValuePacked(FastBufferWriter, float)

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

    WriteValuePacked(FastBufferWriter, string)

    Writes a string in a packed format

    WriteValuePacked(FastBufferWriter, ushort)

    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.

    WriteValuePacked(FastBufferWriter, uint)

    Write an unsigned int (UInt32) to the buffer.

    WriteValuePacked(FastBufferWriter, ulong)

    Write an unsigned long (UInt64) to the buffer.

    WriteValuePacked(FastBufferWriter, Color)

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

    WriteValuePacked(FastBufferWriter, Color32)

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

    WriteValuePacked(FastBufferWriter, Quaternion)

    Writes the rotation to the buffer.

    WriteValuePacked(FastBufferWriter, Ray)

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

    WriteValuePacked(FastBufferWriter, Ray2D)

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

    WriteValuePacked(FastBufferWriter, Vector2)

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

    WriteValuePacked(FastBufferWriter, Vector3)

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

    WriteValuePacked(FastBufferWriter, Vector4)

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

    WriteValuePacked<TEnum>(FastBufferWriter, TEnum)

    Write a packed enum value.

    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)