Skip to main content

Unity.Netcode.BytePacker

Utility class for packing values in serialization.

Inheritance#

System.Dynamic.ExpandoObject

System.Dynamic.ExpandoObject

Inherited Members#

Object.Equals(Object)

Object.Equals(Object, Object)

Object.GetHashCode()

Object.GetType()

Object.MemberwiseClone()

Object.ReferenceEquals(Object, Object)

Object.ToString()

Namespace: System.Dynamic.ExpandoObject#
Assembly: MLAPI.dll#
Syntax#
public static class BytePacker

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#

public static void WriteValueBitPacked(FastBufferWriter writer, short value)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.Int16valueThe 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#

public static void WriteValueBitPacked(FastBufferWriter writer, int value)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.Int32valueThe 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#

public static void WriteValueBitPacked(FastBufferWriter writer, long value)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.Int64valueThe 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#

public static void WriteValueBitPacked(FastBufferWriter writer, ushort value)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.UInt16valueThe 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#

public static void WriteValueBitPacked(FastBufferWriter writer, uint value)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.UInt32valueThe 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#

public static void WriteValueBitPacked(FastBufferWriter writer, ulong value)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.UInt64valueThe value to pack

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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
ColorcolorColor 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
Color32colorColor to write

WriteValuePacked(FastBufferWriter, Quaternion)#

Writes the rotation to the buffer.

Declaration#

public static void WriteValuePacked(FastBufferWriter writer, Quaternion rotation)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
QuaternionrotationRotation 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
RayrayRay 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
Ray2Dray2dRay2D to write

WriteValuePacked(FastBufferWriter, Boolean)#

Write a bool to the buffer.

Declaration#

public static void WriteValuePacked(FastBufferWriter writer, bool value)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.BooleanvalueValue to write

WriteValuePacked(FastBufferWriter, Byte)#

Write a byte to the buffer.

Declaration#

public static void WriteValuePacked(FastBufferWriter writer, byte value)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.BytevalueValue 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.CharcValue 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.DoublevalueValue 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.Int16valueValue 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.Int32valueValue 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.Int64valueValue to write

WriteValuePacked(FastBufferWriter, SByte)#

Write a signed byte to the buffer.

Declaration#

public static void WriteValuePacked(FastBufferWriter writer, sbyte value)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.SBytevalueValue 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.SinglevalueValue to write

WriteValuePacked(FastBufferWriter, String)#

Writes a string in a packed format

Declaration#

public static void WriteValuePacked(FastBufferWriter writer, string s)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.StringsThe 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.UInt16valueValue to write

WriteValuePacked(FastBufferWriter, UInt32)#

Write an unsigned int (UInt32) to the buffer.

Declaration#

public static void WriteValuePacked(FastBufferWriter writer, uint value)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.UInt32valueValue to write

WriteValuePacked(FastBufferWriter, UInt64)#

Write an unsigned long (UInt64) to the buffer.

Declaration#

public static void WriteValuePacked(FastBufferWriter writer, ulong value)

Parameters#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
System.UInt64valueValue 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
Vector2vector2Vector 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
Vector3vector3Vector 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
Vector4vector4Vector 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#

TypeNameDescription
FastBufferWriterwriterThe writer to write to
TEnumvalueThe value to write

Type Parameters#

NameDescription
TEnumAn enum type