Skip to content
Encoder Implementation
step 1/5

Reading — step 1 of 5

Read

~1 min readImplementation

Encoder Implementation

Encoder picks smallest format:

python

Performance:

  • Build via list of bytes objects + b''.join.
  • Avoids quadratic concat.
  • Modern Python: BytesIO also fine.

Roundtrip:

python

Custom types:

  • Pre-encode hook: user provides function for non-built-in types.
  • Most libs return ExtType for user-registered types.

Streaming encode:

  • For huge maps/arrays: emit length, then stream items.
  • Saves memory.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…