docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct BitWriter

    Helper class for doing bitwise writes for a FastBufferWriter. Ensures all bitwise writes end on proper byte alignment so FastBufferWriter doesn't have to be concerned with misaligned writes.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    ValueType.ToString()
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetType()
    Namespace: Unity.Netcode
    Assembly: solution.dll
    Syntax
    public ref struct BitWriter

    Properties

    Name Description
    BitAligned

    Whether or not the current BitPosition is evenly divisible by 8. I.e. whether or not the BitPosition is at a byte boundary.

    Methods

    Name Description
    Dispose()

    Pads the written bit count to byte alignment and commits the write back to the writer

    TryBeginWriteBits(int)

    Allows faster serialization by batching bounds checking. When you know you will be writing multiple fields back-to-back and you know the total size, you can call TryBeginWriteBits() once on the total size, and then follow it with calls to WriteBit() or WriteBits().

    Bitwise write operations will throw OverflowException in editor and development builds if you go past the point you've marked using TryBeginWriteBits(). In release builds, OverflowException will not be thrown for performance reasons, since the point of using TryBeginWrite is to avoid bounds checking in the following operations in release builds. Instead, attempting to write past the marked position in release builds will write to random memory and cause undefined behavior, likely including instability and crashes.

    WriteBit(bool)

    Write a single bit to the buffer

    WriteBits(byte, uint)

    Write bits to stream.

    WriteBits(ulong, uint)

    Write s certain amount of bits to the stream.

    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)