Skip to content

Conversation

@aaa4xu
Copy link

@aaa4xu aaa4xu commented Jun 7, 2025

Hi there!

This pull request introduces new feature to the library: a Pickler class that enables the serialization of JavaScript objects into the Python pickle format. This complements the existing Parser and makes the library a complete, two-way solution for handling pickle data in a JS/TS environment.

Summary of Changes

Refactored BufferReader to use a shared Sizes enum.

  • Replaced magic numbers for data type sizes with a Sizes enum. This enum is now shared between the reader and writer.

BufferWriter class and IWriter interface (src/writer.ts)

  • A helper class for writing binary data to a dynamically growing buffer, serving as the counterpart to BufferReader.

Pickler class (src/pickler.ts)

  • The core serialization logic resides here
  • Handles JavaScript primitives (null, boolean, number, string, bigint)
  • Supports container types (Array, Object, Map) and correctly serializes them as Python list and dict.
  • Includes memoization to correctly handle shared object references and cyclical data structures (for protocols 1+).

Added tests for the Pickler

  • Unit Tests: Verifies the "round-trip" consistency (pickler.dump() -> parser.parse()) for supported data types and protocols.
  • Integration Tests: A new suite of tests that serialize data with Pickler and then successfully deserialize it using a standard Python pickle.loads.

I'm excited about this contribution and believe it will be a valuable addition to the project. I'm happy to discuss any part of the implementation or make any necessary changes.

Thanks for your time and consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant