コード例 #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
        public PackedBinaryWriter(PackedBinaryStream stream, JsonTokenizer tokenizer, Allocator label)
        {
            m_Label = label;
            m_Data  = (Data *)UnsafeUtility.Malloc(sizeof(Data), UnsafeUtility.AlignOf <Data>(), label);
            UnsafeUtility.MemClear(m_Data, sizeof(Data));

            m_Stream    = stream;
            m_Tokenizer = tokenizer;
            m_Data->InputTokenNextIndex   = 0;
            m_Data->InputTokenParentIndex = -1;
        }
コード例 #3
0
        public NodeParser(JsonTokenizer tokenizer, int batchSize, Allocator label)
        {
            m_Label = label;
            m_Data  = (Data *)UnsafeUtility.Malloc(sizeof(Data), UnsafeUtility.AlignOf <Data>(), label);
            UnsafeUtility.MemClear(m_Data, sizeof(Data));

            m_Data->Tokenizer = tokenizer;
            m_Data->NodeType  = NodeType.None;

            if (batchSize < 1)
            {
                throw new ArgumentException("batchSize < 1");
            }

            m_Data->Nodes            = (int *)UnsafeUtility.Malloc(sizeof(int) * batchSize, 4, m_Label);
            m_Data->NodeLength       = batchSize;
            m_Data->NodeNextIndex    = 0;
            m_Data->TokenNextIndex   = 0;
            m_Data->TokenParentIndex = -1;
        }
コード例 #4
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;
        }
コード例 #5
0
 public NodeParser(JsonTokenizer tokenizer, Allocator label) : this(tokenizer, k_DefaultBatchSize, label)
 {
 }