Expand description
Python’s pickle format, read into a tree of values and written back, as far as music21’s cache files use it.
music21 keeps its corpus metadata as a pickled MetadataBundle. Reading
one runs pickle’s stack machine over its opcodes; what comes out is a
Pickle: every value the stream built, in one arena, with objects of
Python classes kept as the class they name, the arguments they were made
with and the state they were given. Nothing is imported or run. Writing
is the reverse: a Pickle built with Pickle::push is written as
protocol 5, which Python’s own pickle.loads reads.
use music21::common::pickle::{Pickle, PickleValue};
let mut built = Pickle::default();
let key = built.push(PickleValue::Text("title".into()));
let value = built.push(PickleValue::Int(7));
let root = built.push(PickleValue::Dict(vec![(key, value)]));
built.set_root(root);
let read = Pickle::read(&built.write()).unwrap();
let found = read.dict_get(read.root(), "title").unwrap();
assert_eq!(read.get(found), &PickleValue::Int(7));Structs§
- Pickle
- A pickle’s values, as read or as built to be written.
Enums§
- Construction
- How an object of a Python class was made.
- Pickle
Value - One value a pickle builds.
Constants§
- PROTOCOL
- The protocol
Pickle::writewrites, as music21’spickle.dumps(..., protocol=5)does.