A reader and writer for Pythons' pickle format in Golang
Switch branches/tags
Clone or download
Latest commit 6de214d Feb 25, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
python update scaffolding to write named constants for opcode numbers. Updat… Sep 21, 2014
struct_export_test Add more tests, add missing types to unpack. Add overflow check on in… Sep 22, 2014
.gitignore Initial commit Aug 14, 2014
LICENSE add license Sep 7, 2014
README.md Allow composition of multiple resolvers Feb 26, 2018
fuzz.go Add fuzzing framework and crashers Aug 19, 2015
fuzz_test.go Add fuzzing framework and crashers Aug 19, 2015
helpers.go set helper + sanity test Jan 31, 2018
helpers_test.go add conversion of *big.Int into int64 when possible Sep 7, 2014
jump_list.go cleanup types Sep 7, 2014
opcodes.go update scaffolding to write named constants for opcode numbers. Updat… Sep 21, 2014
pickle_machine.go Add INST/BUILD support Feb 26, 2018
pickle_machine_test.go Add INST/BUILD support Feb 26, 2018
pickle_writer.go Handle embedded Oct 12, 2016
pickle_writer_test.go fix uint test on 32-bit archs Nov 12, 2016
populate_jump_list.go update scaffolding to write named constants for opcode numbers. Updat… Sep 21, 2014
protocol_0.go Add INST/BUILD support Feb 26, 2018
protocol_1.go More guards against panics Aug 19, 2015
protocol_2.go general code cleanup and performance increases. Approx 80% of origina… Dec 6, 2014
python_builtin_resolver.go Allow composition of multiple resolvers Feb 26, 2018
python_resolver.go Allow composition of multiple resolvers Feb 26, 2018
python_types.go this is more sane. Add more tests. Sep 22, 2014
sentinel.go Add INST/BUILD support Feb 26, 2018
tuple.go add limited tuple support. Add support for pickling nil as None. Sep 22, 2014
unpack.go Deal with unpacking the bytearray Feb 25, 2018
unpack_test.go Deal with unpacking the bytearray Feb 25, 2018

README.md

stalecucumber

This package reads and writes pickled data. The format is the same as the Python "pickle" module.

Protocols 0,1,2 are implemented. These are the versions written by the Python 2.x series. Python 3 defines newer protocol versions, but can write the older protocol versions so they are readable by this package.

Full documentation is available here.

TLDR

Read a pickled string or unicode object

pickle.dumps("foobar")
---
var somePickledData io.Reader
mystring, err := stalecucumber.String(stalecucumber.Unpickle(somePickledData))

Read a pickled integer

pickle.dumps(42)
---
var somePickledData io.Reader
myint64, err := stalecucumber.Int(stalecucumber.Unpickle(somePickledData))

Read a pickled list of numbers into a structure

pickle.dumps([8,8,2005])
---
var somePickledData io.Reader
numbers := make([]int64,0)

err := stalecucumber.UnpackInto(&numbers).From(stalecucumber.Unpickle(somePickledData))

Read a pickled dictionary into a structure

pickle.dumps({"apple":1,"banana":2,"cat":"hello","Dog":42.0})
---
var somePickledData io.Reader
mystruct := struct{
	Apple int
	Banana uint
	Cat string
	Dog float32}{}

err := stalecucumber.UnpackInto(&mystruct).From(stalecucumber.Unpickle(somePickledData))

Pickle a struct

buf := new(bytes.Buffer)
mystruct := struct{
		Apple int
		Banana uint
		Cat string
		Dog float32}{}

err := stalecucumber.NewPickler(buf).Pickle(mystruct)