Esempio n. 1
0
        /**
         * Read a pickled object representation from the given input stream.
         *
         * @return the reconstituted object hierarchy specified in the file.
         */
        public object load(Stream stream)
        {
            stack = new UnpickleStack();
            var unpickler = new UnpicklerImplementation <StreamReader>(new StreamReader(stream), memo, stack, this);

            return(unpickler.Load());
        }
Esempio n. 2
0
        /// <summary>
        /// Read a pickled object representation from the given pickle data bytes.
        /// </summary>
        /// <param name="pickledata">Serialized pickle data.</param>
        /// <param name="stackCapacity">Initial capacity of the UnpickleStack.</param>
        /// <returns>the reconstituted object hierarchy specified in the memory buffer.</returns>
        public object loads(byte[] pickledata, int stackCapacity)
        {
            stack = new UnpickleStack(stackCapacity);
            var unpickler = new UnpicklerImplementation <ArrayReader>(new ArrayReader(pickledata), memo, stack, this);

            return(unpickler.Load());
        }
Esempio n. 3
0
        /// <summary>
        /// Read a pickled object representation from the given pickle data memory buffer.
        /// </summary>
        /// <param name="pickledata">Serialized pickle data.</param>
        /// <param name="stackCapacity">Optional parameter that suggests the initial capacity of stack. The default value is 4.</param>
        /// <returns>the reconstituted object hierarchy specified in the memory buffer.</returns>
        public object loads(ReadOnlyMemory <byte> pickledata, int stackCapacity = UnpickleStack.DefaultCapacity)
        {
            // ROM is super fast for .NET Core 3.0, but Array is fast for all the runtimes
            // if we can get an array out of ROM, we use the Array instead
            if (MemoryMarshal.TryGetArray(pickledata, out ArraySegment <byte> arraySegment))
            {
                return(loads(arraySegment.Array, stackCapacity));
            }

            stack = new UnpickleStack(stackCapacity);
            var unpickler = new UnpicklerImplementation <ReadOnlyMemoryReader>(new ReadOnlyMemoryReader(pickledata), memo, stack, this);

            return(unpickler.Load());
        }