Class BytePacker
Utility class for packing values in serialization. ByteUnpacker to unpack packed values.
Inherited Members
Namespace: Unity.Netcode
Assembly: Unity.Netcode.Runtime.dll
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 |
---|---|
int |
BitPackedIntMin
Obsolete value that no longer carries meaning. Do not use.
Declaration
public const int BitPackedIntMin = -536870912
Field Value
Type | Description |
---|---|
int |
BitPackedLongMax
Obsolete value that no longer carries meaning. Do not use.
Declaration
public const long BitPackedLongMax = 1152921504606846975
Field Value
Type | Description |
---|---|
long |
BitPackedLongMin
Obsolete value that no longer carries meaning. Do not use.
Declaration
public const long BitPackedLongMin = -1152921504606846976
Field Value
Type | Description |
---|---|
long |
BitPackedShortMax
Obsolete value that no longer carries meaning. Do not use.
Declaration
public const short BitPackedShortMax = 16383
Field Value
Type | Description |
---|---|
short |
BitPackedShortMin
Obsolete value that no longer carries meaning. Do not use.
Declaration
public const short BitPackedShortMin = -16384
Field Value
Type | Description |
---|---|
short |
BitPackedULongMax
Obsolete value that no longer carries meaning. Do not use.
Declaration
public const ulong BitPackedULongMax = 2305843009213693951
Field Value
Type | Description |
---|---|
ulong |
BitPackedUintMax
Obsolete value that no longer carries meaning. Do not use.
Declaration
public const uint BitPackedUintMax = 1073741823
Field Value
Type | Description |
---|---|
uint |
BitPackedUshortMax
Obsolete value that no longer carries meaning. Do not use.
Declaration
public const ushort BitPackedUshortMax = 32767
Field Value
Type | Description |
---|---|
ushort |
Methods
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.
Declaration
public static void WriteValueBitPacked(FastBufferWriter writer, short value)
Parameters
Type | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
short | value | The value to pack |
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.
Declaration
public static void WriteValueBitPacked(FastBufferWriter writer, int value)
Parameters
Type | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
int | value | The value to pack |
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.
Declaration
public static void WriteValueBitPacked(FastBufferWriter writer, long value)
Parameters
Type | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
long | value | The value to pack |
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.
Declaration
public static void WriteValueBitPacked(FastBufferWriter writer, ushort value)
Parameters
Type | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
ushort | value | The value to pack |
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.
Declaration
public static void WriteValueBitPacked(FastBufferWriter writer, uint value)
Parameters
Type | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
uint | value | The value to pack |
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.
Declaration
public static void WriteValueBitPacked(FastBufferWriter writer, ulong value)
Parameters
Type | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
ulong | value | The value to pack |
WriteValuePacked(FastBufferWriter, bool)
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 |
bool | 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, 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.
Declaration
public static void WriteValuePacked(FastBufferWriter writer, short value)
Parameters
Type | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
short | value | Value to write |
WriteValuePacked(FastBufferWriter, int)
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 |
int | value | Value to write |
WriteValuePacked(FastBufferWriter, long)
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 |
long | 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, float)
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 |
float | 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, 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.
Declaration
public static void WriteValuePacked(FastBufferWriter writer, ushort value)
Parameters
Type | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to write to |
ushort | value | Value to write |
WriteValuePacked(FastBufferWriter, uint)
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 |
uint | value | Value to write |
WriteValuePacked(FastBufferWriter, ulong)
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 |
ulong | 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 : unmanaged, 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 |