jcrist · GitHub

added 4 commits

July 27, 2023 23:17
This adds support for decoding UUIDs from 16-byte binary inputs if
`strict=False`. The inputs are interpreted as big-endian 128-bit
integers. This is supported for `msgspec.convert` and
`msgspec.msgpack.decode` alone, since other protocols don't have native
binary input support.
This adds a new `uuid_format` to the json and msgpack encoders,
configuring how msgspec will handle uuids. This may be one of:
- 'canonical': encoded as canonical strings (same as `str(uuid)`).
- 'hex': encoded as strings without hyphens (same as `uuid.hex`).
- 'bytes': encoded as binary values representing big-endian 128-bit
  integers (same as `uuid.bytes`).
Note that only msgpack supports the `'bytes'` value, as JSON lacks a
native binary type. Defaults to `'canonical'`.
This seems safe to do since encoding UUIDs as 16 byte values is a well
defined format and common-enough format.

@jcrist

@jcrist

jcrist deleted the uuid-as-bytes branch

July 28, 2023 04:39

Closed

Read the original on github.com ↗