docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct SerializedObjectReader

    The SerializedObjectReader is the high level API used to deserialize a stream of data.

    Implements
    IDisposable
    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    ValueType.ToString()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Serialization.Json
    Assembly: Unity.Serialization.dll
    Syntax
    public struct SerializedObjectReader : IDisposable

    Constructors

    SerializedObjectReader(char*, int, PackedBinaryStream, SerializedObjectReaderConfiguration, Allocator)

    Initializes a new instance of the SerializedObjectReader class based on the specified input buffer, output stream and configuration.

    Declaration
    public SerializedObjectReader(char* buffer, int length, PackedBinaryStream output, SerializedObjectReaderConfiguration configuration, Allocator label = Allocator.TempJob)
    Parameters
    Type Name Description
    char* buffer

    The pointer to the input buffer.

    int length

    The input buffer length.

    PackedBinaryStream output

    The output stream.

    SerializedObjectReaderConfiguration configuration

    The configuration parameters to use for the reader.

    Allocator label

    The memory allocator label to use.

    SerializedObjectReader(char*, int, SerializedObjectReaderConfiguration, Allocator)

    Initializes a new instance of the SerializedObjectReader class based on the specified input buffer and configuration.

    Declaration
    public SerializedObjectReader(char* buffer, int length, SerializedObjectReaderConfiguration configuration, Allocator label = Allocator.TempJob)
    Parameters
    Type Name Description
    char* buffer

    The pointer to the input buffer.

    int length

    The input buffer length.

    SerializedObjectReaderConfiguration configuration

    The configuration parameters to use for the reader.

    Allocator label

    The memory allocator label to use.

    SerializedObjectReader(Stream, Allocator, bool)

    Initializes a new instance of the SerializedObjectReader class based on the specified input stream.

    Declaration
    public SerializedObjectReader(Stream input, Allocator label = Allocator.TempJob, bool leaveInputOpen = true)
    Parameters
    Type Name Description
    Stream input

    The input stream.

    Allocator label

    The memory allocator label to use.

    bool leaveInputOpen

    True to leave the input stream open after the reader object is disposed; otherwise, false.

    SerializedObjectReader(Stream, PackedBinaryStream, Allocator, bool, bool)

    Initializes a new instance of the SerializedObjectReader class based on the specified input stream and output stream.

    Declaration
    public SerializedObjectReader(Stream input, PackedBinaryStream output, Allocator label = Allocator.TempJob, bool leaveInputOpen = true, bool leaveOutputOpen = true)
    Parameters
    Type Name Description
    Stream input

    The input stream.

    PackedBinaryStream output

    The output stream.

    Allocator label

    The memory allocator label to use.

    bool leaveInputOpen

    True to leave the input stream open after the reader object is disposed; otherwise, false.

    bool leaveOutputOpen

    True to leave the output stream open after the reader object is disposed; otherwise, false.

    SerializedObjectReader(Stream, PackedBinaryStream, SerializedObjectReaderConfiguration, Allocator, bool, bool)

    Initializes a new instance of the SerializedObjectReader class based on the specified input stream, output stream and configuration.

    Declaration
    public SerializedObjectReader(Stream input, PackedBinaryStream output, SerializedObjectReaderConfiguration configuration, Allocator label = Allocator.TempJob, bool leaveInputOpen = true, bool leaveOutputOpen = true)
    Parameters
    Type Name Description
    Stream input

    The input stream.

    PackedBinaryStream output

    The output stream.

    SerializedObjectReaderConfiguration configuration

    The configuration parameters to use for the reader.

    Allocator label

    The memory allocator label to use.

    bool leaveInputOpen

    True to leave the input stream open after the reader object is disposed; otherwise, false.

    bool leaveOutputOpen

    True to leave the output stream open after the reader object is disposed; otherwise, false.

    Exceptions
    Type Condition
    ArgumentException

    The configuration is invalid.

    SerializedObjectReader(Stream, SerializedObjectReaderConfiguration, Allocator, bool)

    Initializes a new instance of the SerializedObjectReader class based on the specified input stream and configuration.

    Declaration
    public SerializedObjectReader(Stream input, SerializedObjectReaderConfiguration configuration, Allocator label = Allocator.TempJob, bool leaveInputOpen = true)
    Parameters
    Type Name Description
    Stream input

    The input stream.

    SerializedObjectReaderConfiguration configuration

    The configuration parameters to use for the reader.

    Allocator label

    The memory allocator label to use.

    bool leaveInputOpen

    True to leave the input stream open after the reader object is disposed; otherwise, false.

    SerializedObjectReader(string, Allocator)

    Initializes a new instance of the SerializedObjectReader class with the specified path.

    Declaration
    public SerializedObjectReader(string path, Allocator label = Allocator.TempJob)
    Parameters
    Type Name Description
    string path

    A relative or absolute file path.

    Allocator label

    The memory allocator label to use.

    SerializedObjectReader(string, PackedBinaryStream, Allocator, bool)

    Initializes a new instance of the SerializedObjectReader class with the specified path and output stream.

    Declaration
    public SerializedObjectReader(string path, PackedBinaryStream output, Allocator label = Allocator.TempJob, bool leaveOutputOpen = true)
    Parameters
    Type Name Description
    string path

    A relative or absolute file path.

    PackedBinaryStream output

    The output stream.

    Allocator label

    The memory allocator label to use.

    bool leaveOutputOpen

    True to leave the stream open after the reader object is disposed; otherwise, false.

    SerializedObjectReader(string, PackedBinaryStream, SerializedObjectReaderConfiguration, Allocator, bool)

    Initializes a new instance of the SerializedObjectReader class with the specified path, output stream and configuration.

    Declaration
    public SerializedObjectReader(string path, PackedBinaryStream output, SerializedObjectReaderConfiguration configuration, Allocator label = Allocator.TempJob, bool leaveOutputOpen = true)
    Parameters
    Type Name Description
    string path

    A relative or absolute file path.

    PackedBinaryStream output

    The output stream.

    SerializedObjectReaderConfiguration configuration

    The configuration parameters to use for the reader.

    Allocator label

    The memory allocator label to use.

    bool leaveOutputOpen

    True to leave the output stream open after the reader object is disposed; otherwise, false.

    SerializedObjectReader(string, SerializedObjectReaderConfiguration, Allocator)

    Initializes a new instance of the SerializedObjectReader class with the specified path and configuration.

    Declaration
    public SerializedObjectReader(string path, SerializedObjectReaderConfiguration configuration, Allocator label = Allocator.TempJob)
    Parameters
    Type Name Description
    string path

    A relative or absolute file path.

    SerializedObjectReaderConfiguration configuration

    The configuration parameters to use for the reader.

    Allocator label

    The memory allocator label to use.

    SerializedObjectReader(PackedBinaryStream, SerializedObjectReaderConfiguration, Allocator)

    Initializes a new instance of the SerializedObjectReader class based on the specified configuration.

    Declaration
    public SerializedObjectReader(PackedBinaryStream output, SerializedObjectReaderConfiguration configuration, Allocator label = Allocator.TempJob)
    Parameters
    Type Name Description
    PackedBinaryStream output

    The output stream.

    SerializedObjectReaderConfiguration configuration

    The configuration parameters to use for the reader.

    Allocator label

    The memory allocator label to use.

    SerializedObjectReader(SerializedObjectReaderConfiguration, Allocator)

    Initializes a new instance of the SerializedObjectReader class based on the specified configuration.

    Declaration
    public SerializedObjectReader(SerializedObjectReaderConfiguration configuration, Allocator label = Allocator.TempJob)
    Parameters
    Type Name Description
    SerializedObjectReaderConfiguration configuration

    The configuration parameters to use for the reader.

    Allocator label

    The memory allocator label to use.

    Properties

    RequiresExplicitExceptionHandling

    If this flag is true. No exceptions are thrown unless CheckAndThrowInvalidJsonException() is called.

    Declaration
    public bool RequiresExplicitExceptionHandling { get; set; }
    Property Value
    Type Description
    bool

    Methods

    CheckAndThrowInvalidJsonException()

    Throws any invalid json exceptions generated from within a burst context.

    Declaration
    public void CheckAndThrowInvalidJsonException()

    DiscardCompleted()

    Discards completed data from the buffers.

    Declaration
    public void DiscardCompleted()

    Dispose()

    Releases all resources used by the SerializedObjectReader.

    Declaration
    public void Dispose()

    Read(char*, int)

    Reads the specified data and returns a new SerializedValueView.

    Declaration
    public SerializedValueView Read(char* ptr, int length)
    Parameters
    Type Name Description
    char* ptr

    The char buffer.

    int length

    The char buffer length.

    Returns
    Type Description
    SerializedValueView

    The view for the first node in the stream.

    Remarks

    This will invalidate any generated views from this reader.

    Read(NodeType)

    Reads the next node in the stream, respecting depth/scope.

    Declaration
    public NodeType Read(NodeType node = (NodeType)-1)
    Parameters
    Type Name Description
    NodeType node

    The node type to stop at.

    Returns
    Type Description
    NodeType

    The node type that was read.

    Read(out SerializedValueView, NodeType)

    Reads the next node in the stream, respecting depth/scope.

    Declaration
    public NodeType Read(out SerializedValueView view, NodeType node = (NodeType)-1)
    Parameters
    Type Name Description
    SerializedValueView view

    The view at the returned node type.

    NodeType node

    The node type to stop at.

    Returns
    Type Description
    NodeType

    The node type the parser stopped at.

    ReadArrayElement(out SerializedValueView)

    Reads the next node as an array element.

    Declaration
    public bool ReadArrayElement(out SerializedValueView view)
    Parameters
    Type Name Description
    SerializedValueView view

    The view of the array element.

    Returns
    Type Description
    bool

    True if the element was successfully read, false otherwise.

    ReadArrayElementBatch(NativeArray<SerializedValueView>, int)

    Reads the next count elements of an array and writes views to the given buffer.

    Declaration
    public int ReadArrayElementBatch(NativeArray<SerializedValueView> views, int count)
    Parameters
    Type Name Description
    NativeArray<SerializedValueView> views

    The array to write the views to.

    int count

    The number of elements to read.

    Returns
    Type Description
    int

    The number of elements read.

    Exceptions
    Type Condition
    IndexOutOfRangeException

    The count exceeded the array of views.

    ReadArrayElementBatch(SerializedValueView*, int)

    Reads the next count elements of an array and writes views to the given buffer.

    Declaration
    public int ReadArrayElementBatch(SerializedValueView* views, int count)
    Parameters
    Type Name Description
    SerializedValueView* views

    The buffer to write the views to.

    int count

    The number of elements to read.

    Returns
    Type Description
    int

    The number of elements read.

    ReadMember()

    Reads the next node as a SerializedMemberView.

    Declaration
    public SerializedMemberView ReadMember()
    Returns
    Type Description
    SerializedMemberView
    Exceptions
    Type Condition
    InvalidOperationException

    The reader state is invalid.

    ReadMember(SerializedMemberViewCollection)

    Reads the next node as a member, respecting depth/scope and adds it to the given SerializedMemberViewCollection.

    Declaration
    public void ReadMember(SerializedMemberViewCollection collection)
    Parameters
    Type Name Description
    SerializedMemberViewCollection collection

    The collection to add the member to.

    ReadObject()

    Reads the next node as a SerializedObjectView

    Declaration
    public SerializedObjectView ReadObject()
    Returns
    Type Description
    SerializedObjectView

    The SerializedObjectView that was read.

    Exceptions
    Type Condition
    InvalidOperationException

    The reader state is invalid.

    Reset()

    Resets the reader for re-use.

    Declaration
    public void Reset()

    SetSource(char*, int)

    Sets the data source for the reader.

    Declaration
    public void SetSource(char* ptr, int length)
    Parameters
    Type Name Description
    char* ptr

    The char buffer.

    int length

    The char buffer length.

    Remarks

    This will invalidate any generated views from this reader.

    Step(NodeType)

    Advances the reader to the given node type, ignoring depth/scope.

    Declaration
    public NodeType Step(NodeType node = (NodeType)-1)
    Parameters
    Type Name Description
    NodeType node

    The node type to stop at.

    Returns
    Type Description
    NodeType

    The node type the parser stopped at.

    Step(out SerializedValueView, NodeType)

    Advances the reader to the given node type, ignoring depth/scope.

    Declaration
    public NodeType Step(out SerializedValueView view, NodeType node = (NodeType)-1)
    Parameters
    Type Name Description
    SerializedValueView view

    The view at the returned node type.

    NodeType node

    The node type to stop at.

    Returns
    Type Description
    NodeType

    The node type the parser stopped at.

    Implements

    IDisposable
    In This Article
    Back to top
    Copyright © 2025 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)