Vixen
02b45cc4
csharp
public ref struct SerializationWriter

Writes the binary format, either into a fixed span or into a growable sink.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

A , so it lives on the stack and the span it writes into cannot outlive the frame that owns it. Everything here is a bounds check and a store; no allocation happens on this path unless the sink grows.

Little-endian, always, asserted rather than assumed. Every multi-byte write goes through BinaryPrimitives with an explicit endianness, so content written on one machine reads identically on another regardless of what either CPU prefers. No big-endian target exists today; the point is that adding one would not silently corrupt every existing asset.

Constructed over a span, it writes until the span is full and then throws. Constructed over an IBufferWriter`1, it grows — and must be Flushed before the sink is read, because the bytes written since the last growth have not been handed back yet.

Fields and properties (1)

  • public readonly long BytesWritten

    How many bytes have been written in total.

Methods (34)

  • public SerializationWriter(Span<byte> destination)

    Writes into a fixed buffer. Overflowing it throws.

  • public SerializationWriter(IBufferWriter<byte> sink)

    Writes into a sink that can grow.

  • public void Flush()

    Hands everything written back to the sink. Required before the sink is read.

  • public void WriteByte(byte value)

    Writes one byte.

  • public void WriteBoolean(bool value)

    Writes a boolean as one byte, 0 or 1.

  • public void WriteSByte(sbyte value)

    Writes a signed byte.

  • public void WriteInt16(short value)

    Writes a 16-bit integer, little-endian.

  • public void WriteUInt16(ushort value)

    Writes an unsigned 16-bit integer, little-endian.

  • public void WriteInt32(int value)

    Writes a 32-bit integer, little-endian.

  • public void WriteUInt32(uint value)

    Writes an unsigned 32-bit integer, little-endian.

  • public void WriteInt64(long value)

    Writes a 64-bit integer, little-endian.

  • public void WriteUInt64(ulong value)

    Writes an unsigned 64-bit integer, little-endian.

  • public void WriteChar(char value)

    Writes a 16-bit character, little-endian.

  • public void WriteHalf(Half value)

    Writes a half-precision float.

  • public void WriteSingle(float value)

    Writes a single-precision float.

  • public void WriteDouble(double value)

    Writes a double-precision float, by its bits.

  • public void WriteDecimal(decimal value)

    Writes a decimal as its four constituent integers.

  • public void WriteGuid(Guid value)

    Writes a Guid in its 16-byte little-endian form.

  • public void WriteDateTime(DateTime value)

    Writes a DateTime as its ticks and kind.

  • public void WriteDateTimeOffset(DateTimeOffset value)

    Writes a DateTimeOffset as its ticks and offset.

  • public void WriteTimeSpan(TimeSpan value)

    Writes a TimeSpan as its ticks.

  • public void WriteVarUInt64(ulong value)

    Writes an unsigned integer in LEB128, seven bits per byte.

  • public void WriteVarInt64(long value)

    Writes a signed integer in zig-zag LEB128.

  • public void WriteString(string? value)

    Writes a length-prefixed UTF-8 string, or a null marker.

  • public void WriteBytes(ReadOnlySpan<byte> value)

    Writes raw bytes, without a length.

  • public void WriteBlittable<T>(ReadOnlySpan<T> value) where T : unmanaged

    Writes a blittable span as one bulk copy, without a length.

  • public void WriteValue<T>(in T value) where T : struct

    Writes a value type through its registered serializer.

  • public void WriteReference<T>(T? value) where T : class

    Writes a reference, or a null marker.

  • public void WriteNullable<T>(T? value) where T : struct

    Writes a nullable value type.

  • public void WritePolymorphic<TBase>(TBase? value) where TBase : class

    Writes a reference by its run-time type, so a derived instance survives.

  • public void WriteArray<T>(T[]? value)

    Writes an array, element by element.

  • public void WriteBlittableArray<T>(T[]? value) where T : unmanaged

    Writes an array of a primitive type as one bulk copy.

  • public void WriteList<T>(List<T>? value)

    Writes a list, element by element.

  • public void WriteDictionary<TKey, TValue>(Dictionary<TKey, TValue>? value) where TKey : notnull

    Writes a dictionary in its enumeration order.

Used by (392, showing 40)

  • Vixen_Samples_AddressablesRemote_GreetingSerializerAddressablesRemote
  • Vixen_Samples_ThirdPersonShooter_BoxCollisionSerializerThirdPersonShooter
  • Vixen_Samples_ThirdPersonShooter_CharacterVisualsSerializerThirdPersonShooter
  • Vixen_Samples_ThirdPersonShooter_SpawnPointSerializerThirdPersonShooter
  • AssetIdSerializerVixen.Core.Serialization
  • AssetReferenceSerializerVixen.Core.Serialization
  • BooleanSerializerVixen.Core.Serialization
  • ByteSerializerVixen.Core.Serialization
  • CharSerializerVixen.Core.Serialization
  • ChunkFormatVixen.Core.Serialization
  • ComponentTypeIdSerializerVixen.Core.Serialization
  • ContentReferenceSerializerVixen.Core.Serialization
  • ContractColumnVixen.Engine
  • DataSerializerVixen.Core.Serialization
  • DataSerializerVixen.Core.Serialization
  • DateTimeOffsetSerializerVixen.Core.Serialization
  • DateTimeSerializerVixen.Core.Serialization
  • DecimalSerializerVixen.Core.Serialization
  • DepthColumnVixen.Engine
  • DoubleSerializerVixen.Core.Serialization
  • EntitySerializerVixen.Core.Serialization
  • GuidSerializerVixen.Core.Serialization
  • HalfSerializerVixen.Core.Serialization
  • ISceneComponentBinderVixen.Engine
  • IWorldColumnVixen.Engine
  • Int16SerializerVixen.Core.Serialization
  • Int32SerializerVixen.Core.Serialization
  • Int64SerializerVixen.Core.Serialization
  • LocalTransformColumnVixen.Engine
  • ObjectIdSerializerVixen.Core.Serialization
  • SByteSerializerVixen.Core.Serialization
  • SceneComponentBinderVixen.Engine
  • SceneContentVixen.Engine
  • SceneTagColumnVixen.Engine
  • SerializationTestsVixen.Core.Serialization.Tests
  • SerializerVixen.Core.Serialization
  • SingleSerializerVixen.Core.Serialization
  • StringSerializerVixen.Core.Serialization
  • SubAssetIdSerializerVixen.Core.Serialization
  • TimeSpanSerializerVixen.Core.Serialization