示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SerializedObjectReader"/> class based on the specified input stream, output stream and configuration.
        /// </summary>
        /// <param name="input">The input stream.</param>
        /// <param name="output">The output stream.</param>
        /// <param name="configuration">The configuration parameters to use for the reader.</param>
        /// <param name="label">The memory allocator label to use.</param>
        /// <param name="leaveInputOpen">True to leave the input stream open after the reader object is disposed; otherwise, false.</param>
        /// <param name="leaveOutputOpen">True to leave the output stream open after the reader object is disposed; otherwise, false.</param>
        /// <exception cref="ArgumentException">The configuration is invalid.</exception>
        public SerializedObjectReader(Stream input, PackedBinaryStream output, SerializedObjectReaderConfiguration configuration, Allocator label = SerializationConfiguration.DefaultAllocatorLabel, bool leaveInputOpen = true, bool leaveOutputOpen = true)
        {
            if (configuration.BlockBufferSize < 16)
            {
                throw new ArgumentException("BlockBufferSize < 16");
            }

            if (configuration.TokenBufferSize < 16)
            {
                throw new ArgumentException("TokenBufferSize < 16");
            }

            m_LeaveOutputOpen = leaveOutputOpen;

            m_StreamBlockReader = configuration.UseReadAsync
                ? (IUnsafeStreamBlockReader) new AsyncBlockReader(input, configuration.BlockBufferSize, leaveInputOpen)
                : (IUnsafeStreamBlockReader) new SyncBlockReader(input, configuration.BlockBufferSize, leaveInputOpen);

            m_Tokenizer    = new JsonTokenizer(configuration.TokenBufferSize, configuration.ValidationType, label);
            m_Parser       = new NodeParser(m_Tokenizer, configuration.NodeBufferSize, label);
            m_BinaryStream = output;
            m_BinaryWriter = new PackedBinaryWriter(m_BinaryStream, m_Tokenizer, label);
            m_InitialBlock = default;
            m_CurrentBlock = default;
        }
示例#2
0
        static Stream OpenFileStreamWithConfiguration(string path, SerializedObjectReaderConfiguration configuration)
        {
            if (configuration.BlockBufferSize < 16)
            {
                throw new ArgumentException("SerializedObjectReaderConfiguration.BlockBufferSize < 16");
            }

            return(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, configuration.BlockBufferSize, configuration.UseReadAsync ? FileOptions.Asynchronous : FileOptions.None));
        }
示例#3
0
        static PackedBinaryStream OpenBinaryStreamWithConfiguration(SerializedObjectReaderConfiguration configuration, Allocator label)
        {
            if (configuration.TokenBufferSize < 16)
            {
                throw new ArgumentException("TokenBufferSize < 16");
            }

            if (configuration.OutputBufferSize < 16)
            {
                throw new ArgumentException("OutputBufferSize < 16");
            }

            return(new PackedBinaryStream(configuration.TokenBufferSize, configuration.OutputBufferSize, label));
        }
示例#4
0
 static TextReader CreateTextReader(Stream stream, SerializedObjectReaderConfiguration configuration, bool leaveInputOpen)
 {
     return(new StreamReader(stream, Encoding.UTF8, detectEncodingFromByteOrderMarks: false, bufferSize: configuration.BlockBufferSize, leaveInputOpen));
 }
示例#5
0
        internal SerializedObjectReader(UnsafeBuffer <char> buffer, PackedBinaryStream output, SerializedObjectReaderConfiguration configuration, Allocator label = SerializationConfiguration.DefaultAllocatorLabel)
        {
            if (configuration.TokenBufferSize < 16)
            {
                throw new ArgumentException("TokenBufferSize < 16");
            }

            if (IsEmpty(buffer))
            {
                throw new ArgumentException("Input stream is null or empty.");
            }

            m_LeaveOutputOpen   = false;
            m_StreamBlockReader = null;
            m_Tokenizer         = new JsonTokenizer(configuration.TokenBufferSize, configuration.ValidationType, label);
            m_Parser            = new NodeParser(m_Tokenizer, configuration.NodeBufferSize, label);
            m_BinaryStream      = output;
            m_BinaryWriter      = new PackedBinaryWriter(m_BinaryStream, m_Tokenizer, label);
            m_Block             = buffer;
        }
示例#6
0
 internal SerializedObjectReader(UnsafeBuffer <char> buffer, SerializedObjectReaderConfiguration configuration, Allocator label = SerializationConfiguration.DefaultAllocatorLabel)
     : this(buffer, OpenBinaryStreamWithConfiguration(configuration, label), configuration, label)
 {
 }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SerializedObjectReader"/> class based on the specified input stream and configuration.
 /// </summary>
 /// <param name="input">The input stream.</param>
 /// <param name="configuration">The configuration parameters to use for the reader.</param>
 /// <param name="label">The memory allocator label to use.</param>
 /// <param name="leaveInputOpen">True to leave the input stream open after the reader object is disposed; otherwise, false.</param>
 public SerializedObjectReader(Stream input, SerializedObjectReaderConfiguration configuration, Allocator label = SerializationConfiguration.DefaultAllocatorLabel, bool leaveInputOpen = true)
     : this(input, OpenBinaryStreamWithConfiguration(configuration, label), configuration, label, leaveInputOpen, false)
 {
 }
示例#8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SerializedObjectReader"/> class with the specified path, output stream and configuration.
 /// </summary>
 /// <param name="path">A relative or absolute file path.</param>
 /// <param name="output">The output stream.</param>
 /// <param name="configuration">The configuration parameters to use for the reader.</param>
 /// <param name="label">The memory allocator label to use.</param>
 /// <param name="leaveOutputOpen">True to leave the output stream open after the reader object is disposed; otherwise, false.</param>
 public SerializedObjectReader(string path, PackedBinaryStream output, SerializedObjectReaderConfiguration configuration, Allocator label = SerializationConfiguration.DefaultAllocatorLabel, bool leaveOutputOpen = true)
     : this(OpenFileStreamWithConfiguration(path, configuration), output, configuration, label, false, leaveOutputOpen)
 {
 }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SerializedObjectReader"/> class with the specified path and configuration.
 /// </summary>
 /// <param name="path">A relative or absolute file path.</param>
 /// <param name="configuration">The configuration parameters to use for the reader.</param>
 /// <param name="label">The memory allocator label to use.</param>
 public SerializedObjectReader(string path, SerializedObjectReaderConfiguration configuration, Allocator label = SerializationConfiguration.DefaultAllocatorLabel)
     : this(path, OpenBinaryStreamWithConfiguration(configuration, label), configuration, label, false)
 {
 }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SerializedObjectReader"/> class based on the specified input buffer, output stream and configuration.
 /// </summary>
 /// <param name="buffer">The pointer to the input buffer.</param>
 /// <param name="length">The input buffer length.</param>
 /// <param name="output">The output stream.</param>
 /// <param name="configuration">The configuration parameters to use for the reader.</param>
 /// <param name="label">The memory allocator label to use.</param>
 public unsafe SerializedObjectReader(char *buffer, int length, PackedBinaryStream output, SerializedObjectReaderConfiguration configuration, Allocator label = SerializationConfiguration.DefaultAllocatorLabel)
     : this(new UnsafeBuffer <char>(buffer, length), output, configuration, label)
 {
 }