Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify field order in array_like=True structs #137

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,10 @@ doesn't match or if any required fields are missing.
msgspec.DecodeError: Expected `str`, got `int` - at `$.groups[1]`

If you pass ``array_like=True`` when defining the struct type, they're instead
treated as ``array`` types during encoding/decoding (with fields serialized in
their definition order). This can further improve performance at the cost of
less human readable messaging. Like ``array_like=False`` (the default) structs,
treated as ``array`` types during encoding/decoding. In this case fields are
serialized in their normalized order (definition order, with optional fields
shifted to the end). This can further improve performance at the cost of less
human readable messaging. Like ``array_like=False`` (the default) structs,
extra (trailing) fields are ignored during decoding, and any missing optional
fields have their defaults applied. Type checking also still applies.

Expand Down Expand Up @@ -643,7 +644,7 @@ message).
>>> # Compose a larger message containing the pre-encoded fragment
... msg = {"a": 1, "b": fragment}

>>> # During encoding, the raw message is efficiently copied into
>>> # During encoding, the raw message is efficiently copied into
... # the output buffer, avoiding any extra encoding cost
... msgspec.json.encode(msg)
b'{"a":1,"b":{"x": 1, "y": 2}}'
Expand Down