Class BytePacker
Utility class for packing values in serialization. ByteUnpacker to unpack packed values.
#
InheritanceSystem.Object
BytePacker
#
Inherited MembersSystem.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
#
Namespace: Unity.Netcode#
Assembly: MLAPI.dll#
Syntax#
Fields#
BitPackedIntMaxMaximum serializable value for a BitPacked int
#
Declaration#
Field ValueType | Description |
---|---|
System.Int32 |
#
BitPackedIntMinMinimum serializable value size for a BitPacked int
#
Declaration#
Field ValueType | Description |
---|---|
System.Int32 |
#
BitPackedLongMaxMaximum serializable value for a BitPacked long
#
Declaration#
Field ValueType | Description |
---|---|
System.Int64 |
#
BitPackedLongMinMinimum serializable value size for a BitPacked long
#
Declaration#
Field ValueType | Description |
---|---|
System.Int64 |
#
BitPackedShortMaxMaximum serializable value for a BitPacked short
#
Declaration#
Field ValueType | Description |
---|---|
System.Int16 |
#
BitPackedShortMinMinimum serializable value size for a BitPacked ushort
#
Declaration#
Field ValueType | Description |
---|---|
System.Int16 |
#
BitPackedUintMaxMaximum serializable value for a BitPacked uint (minimum for unsigned is 0)
#
Declaration#
Field ValueType | Description |
---|---|
System.UInt32 |
#
BitPackedULongMaxMaximum serializable value for a BitPacked ulong (minimum for unsigned is 0)
#
Declaration#
Field ValueType | Description |
---|---|
System.UInt64 |
#
BitPackedUshortMaxMaximum serializable value for a BitPacked ushort (minimum for unsigned is 0)
#
Declaration#
Field ValueType | Description |
---|---|
System.UInt16 |
#
Methods#
WriteValueBitPacked(FastBufferWriter, Int16)Writes a 14-bit signed short to the buffer in a bit-encoded packed format. The first bit indicates whether the value is 1 byte or 2. The sign bit takes up another bit. That leaves 14 bits for the value. A value greater than 2^14-1 or less than -2^14 will throw an exception in editor and development builds. In release builds builds the exception is not thrown and the value is truncated by losing its two most significant bits after zig-zag encoding.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.Int16 | value | The value to pack |
#
WriteValueBitPacked(FastBufferWriter, Int32)Writes a 29-bit signed int to the buffer in a bit-encoded packed format. The first two bits indicate whether the value is 1, 2, 3, or 4 bytes. The sign bit takes up another bit. That leaves 29 bits for the value. A value greater than 2^29-1 or less than -2^29 will throw an exception in editor and development builds. In release builds builds the exception is not thrown and the value is truncated by losing its three most significant bits after zig-zag encoding.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.Int32 | value | The value to pack |
#
WriteValueBitPacked(FastBufferWriter, Int64)Writes a 60-bit signed long to the buffer in a bit-encoded packed format. The first three bits indicate whether the value is 1, 2, 3, 4, 5, 6, 7, or 8 bytes. The sign bit takes up another bit. That leaves 60 bits for the value. A value greater than 2^60-1 or less than -2^60 will throw an exception in editor and development builds. In release builds builds the exception is not thrown and the value is truncated by losing its four most significant bits after zig-zag encoding.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.Int64 | value | The value to pack |
#
WriteValueBitPacked(FastBufferWriter, UInt16)Writes a 15-bit unsigned short to the buffer in a bit-encoded packed format. The first bit indicates whether the value is 1 byte or 2. That leaves 15 bits for the value. A value greater than 2^15-1 will throw an exception in editor and development builds. In release builds builds the exception is not thrown and the value is truncated by losing its most significant bit.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.UInt16 | value | The value to pack |
#
WriteValueBitPacked(FastBufferWriter, UInt32)Writes a 30-bit unsigned int to the buffer in a bit-encoded packed format. The first two bits indicate whether the value is 1, 2, 3, or 4 bytes. That leaves 30 bits for the value. A value greater than 2^30-1 will throw an exception in editor and development builds. In release builds builds the exception is not thrown and the value is truncated by losing its two most significant bits.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.UInt32 | value | The value to pack |
#
WriteValueBitPacked(FastBufferWriter, UInt64)Writes a 61-bit unsigned long to the buffer in a bit-encoded packed format. The first three bits indicate whether the value is 1, 2, 3, 4, 5, 6, 7, or 8 bytes. That leaves 31 bits for the value. A value greater than 2^61-1 will throw an exception in editor and development builds. In release builds builds the exception is not thrown and the value is truncated by losing its three most significant bits.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.UInt64 | value | The value to pack |
#
WriteValuePacked(FastBufferWriter, Color)Convenience method that writes four varint floats from the color to the buffer
#
Declaration#
ParametersType | 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#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
Color32 | color | Color to write |
#
WriteValuePacked(FastBufferWriter, Quaternion)Writes the rotation to the buffer.
#
Declaration#
ParametersType | 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#
ParametersType | 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#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
Ray2D | ray2d | Ray2D to write |
#
WriteValuePacked(FastBufferWriter, Boolean)Write a bool to the buffer.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.Boolean | value | Value to write |
#
WriteValuePacked(FastBufferWriter, Byte)Write a byte to the buffer.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.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#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.Char | c | Value to write |
#
WriteValuePacked(FastBufferWriter, Double)Write double-precision floating point value to the buffer as a varint
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.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#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.Int16 | value | Value to write |
#
WriteValuePacked(FastBufferWriter, Int32)Write a signed int (Int32) as a ZigZag encoded varint to the buffer.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.Int32 | value | Value to write |
#
WriteValuePacked(FastBufferWriter, Int64)Write a signed long (Int64) as a ZigZag encoded varint to the buffer.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.Int64 | value | Value to write |
#
WriteValuePacked(FastBufferWriter, SByte)Write a signed byte to the buffer.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.SByte | value | Value to write |
#
WriteValuePacked(FastBufferWriter, Single)Write single-precision floating point value to the buffer as a varint
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.Single | value | Value to write |
#
WriteValuePacked(FastBufferWriter, String)Writes a string in a packed format
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.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#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.UInt16 | value | Value to write |
#
WriteValuePacked(FastBufferWriter, UInt32)Write an unsigned int (UInt32) to the buffer.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.UInt32 | value | Value to write |
#
WriteValuePacked(FastBufferWriter, UInt64)Write an unsigned long (UInt64) to the buffer.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
System.UInt64 | value | Value to write |
#
WriteValuePacked(FastBufferWriter, Vector2)Convenience method that writes two varint floats from the vector to the buffer
#
Declaration#
ParametersType | 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#
ParametersType | 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#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
Vector4 | vector4 | Vector to write |
#
WriteValuePacked\<TEnum>(FastBufferWriter, TEnum)Write a packed enum value.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
TEnum | value | The value to write |
#
Type ParametersName | Description |
---|---|
TEnum | An enum type |