/// <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()); }
public UnpicklerImplementation(T input, IDictionary <int, object> memo, UnpickleStack stack, Unpickler unpickler) { this.input = input; this.memo = memo; this.stack = stack; this.unpickler = unpickler; }
/** * 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()); }
public void testClear() { UnpickleStack s=new UnpickleStack(); s.add("x"); s.add("y"); Assert.AreEqual(2, s.size()); s.clear(); Assert.AreEqual(0, s.size()); }
public void testTrim() { UnpickleStack s=new UnpickleStack(); s.add("a"); s.add("b"); s.add("c"); s.add("d"); s.add("e"); Assert.AreEqual(5, s.size()); s.trim(); Assert.AreEqual(5, s.size()); }
/** * Read a pickled object representation from the given input stream. * * @return the reconstituted object hierarchy specified in the file. */ public object load(Stream stream) { input = stream; stack = new UnpickleStack(); try { while (true) { byte key = PickleUtils.readbyte(input); dispatch(key); } } catch (StopException x) { return x.value; } }
public void testAddPop() { UnpickleStack s=new UnpickleStack(); Assert.AreEqual(0, s.size()); s.add("x"); Assert.AreEqual(1, s.size()); s.add("y"); Assert.AreEqual(2, s.size()); Assert.AreEqual("y", s.peek()); Assert.AreEqual("y", s.pop()); Assert.AreEqual("x", s.peek()); Assert.AreEqual("x", s.pop()); Assert.AreEqual(0, s.size()); }
/** * Read a pickled object representation from the given input stream. * * @return the reconstituted object hierarchy specified in the file. */ public object load(Stream stream) { input = stream; stack = new UnpickleStack(); while (true) { byte key = PickleUtils.readbyte(input); object value = dispatch(key); if (value != NO_RETURN_VALUE) { return(value); } } }
/// <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()); }
/** * Read a pickled object representation from the given input stream. * * @return the reconstituted object hierarchy specified in the file. */ public object load(Stream stream) { pu = new PickleUtils(stream); stack = new UnpickleStack(); try { while (true) { byte key = pu.readbyte(); dispatch(key); } } catch (StopException x) { return(x.value); } }
/** * Read a pickled object representation from the given input stream. * * @return the reconstituted object hierarchy specified in the file. */ public object load(Stream stream) { input = stream; stack = new UnpickleStack(); try { while (true) { byte key = PickleUtils.readbyte(input); dispatch(key); } } catch (StopException x) { return(x.value); } }
public void testPopSinceMarker() { UnpickleStack s=new UnpickleStack(); s.add("a"); s.add("b"); s.add_mark(); s.add("c"); s.add("d"); s.add_mark(); s.add("e"); s.add("f"); ArrayList top=s.pop_all_since_marker(); ArrayList expected=new ArrayList(); expected.Add("e"); expected.Add("f"); Assert.AreEqual(expected, top); Assert.AreEqual("d",s.pop()); Assert.AreEqual("c",s.pop()); }
/** * Read a pickled object representation from the given input stream. * * @return the reconstituted object hierarchy specified in the file. */ public object load(Stream stream) { input = stream; stack = new UnpickleStack(); while (true) { byte key = PickleUtils.readbyte(input); object value = dispatch(key); if(value != NO_RETURN_VALUE) return value; } }
/** * Read a pickled object representation from the given input stream. * * @return the reconstituted object hierarchy specified in the file. */ public object load(Stream stream) { pu = new PickleUtils(stream); stack = new UnpickleStack(); try { while (true) { byte key = pu.readbyte(); dispatch(key); } } catch (StopException x) { return x.value; } }