deser-pickle 0.10.1

Python pickle format support for deser
Documentation
  • Coverage
  • 100%
    38 out of 38 items documented13 out of 13 items with examples
  • Size
  • Source code size: 249.5 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.6 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • mitsuhiko/deser
    455 8 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mitsuhiko

deser-pickle

Support for Python's pickle format for deser.

use deser::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Session {
    user_id: u64,
    roles: Vec<String>,
}

// `pickle.dumps({"user_id": 42, "roles": ["admin"]}, 4)`
let input = b"\x80\x04\x95$\x00\x00\x00\x00\x00\x00\x00}\x94(\x8c\x07user_id\x94K*\x8c\x05roles\x94]\x94\x8c\x05admin\x94au.";
let session: Session = deser_pickle::from_slice(input).unwrap();
assert_eq!(session.roles, ["admin"]);
let output = deser_pickle::to_vec(&session).unwrap();
assert_eq!(deser_pickle::from_slice::<Session>(&output).unwrap(), session);
  • Reads all protocols (0 to 5) like CPython's unpickler, but never imports or calls anything: objects are recorded with their class, arguments and state and passed on as their state (or items or arguments). The class is passed on out of band.
  • Shared values are emitted at every place they are reached, values that contain themselves are cut with references. Both carry ids so that the graph can be restored.
  • Writes protocols 2 to 5 (4 by default) that Python reads back, including objects of a class and shared and recursive values.

License and Links