Skip to content

Implement De-/Serialize for Record manually - #12365

Merged
WindSoilder merged 2 commits into
nushell:mainfrom
sholderbach:record-serde
Apr 6, 2024
Merged

WindSoilder merged 2 commits into
nushell:mainfrom
sholderbach:record-serde

Conversation

@sholderbach

Copy link
Copy Markdown
Member

Description

This decouples the serialized representation of Record from its internal implementation. It now gets treated as a map type in serde.

This has several benefits:

  • more efficient representation (not showing inner fields)
  • human readable e.g. as a JSON record
  • no breaking changes when refactoring the Record internals in the future (see Refactor Record to use a single backing Vec #12326, or potential introduction of indexmap::IndexMap for large N)
  • we now deny the creation of invalid records a non-cooperating plugin could produce
    • guaranteed key-value correspondence
    • checking for unique keys

Breaking change to the plugin protocol:

Now expects a record/map directly as the Record.val field instead of a serialization of it.

This decouples the serialized representation of `Record` from its
internal implementation. It now gets treated as a map type in `serde`.

This has several benefits:
- more efficient representation (not showing inner fields)
- human readable e.g. as a JSON record
- no breaking changes when refactoring the `Record` internals in the
  future (see nushell#12326, or potential introduction of `indexmap::IndexMap`
  for large N)
- we now deny the creation of invalid records a non-cooperating plugin
  could produce
  - guaranteed key-value correspondence
  - checking for unique keys
Lay out the format, check the unique property
@devyn

devyn commented Apr 6, 2024

Copy link
Copy Markdown
Contributor

Are we waiting on anything for this? I want to document the serialized format of all Value types, and it would be nice to have this landed first so I don't have to change it later.

@WindSoilder

Copy link
Copy Markdown
Contributor

Are we waiting on anything for this? I want to document the serialized format of all Value types, and it would be nice to have this landed first so I don't have to change it later.

I don't think so, it's just because no one has looked into it yet.

@WindSoilder WindSoilder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank! Let's land and try it out

@WindSoilder
WindSoilder merged commit 01c79bb into nushell:main Apr 6, 2024
@hustcer hustcer added this to the v0.93.0 milestone Apr 7, 2024
@devyn

devyn commented Apr 7, 2024

Copy link
Copy Markdown
Contributor

Thanks @WindSoilder ❤️

@fdncred fdncred added the notes:breaking-changes Noted in Breaking Changes section label Apr 7, 2024
@sholderbach
sholderbach deleted the record-serde branch April 7, 2024 21:53
FilipAndersson245 pushed a commit to FilipAndersson245/nushell that referenced this pull request Apr 10, 2024
# Description
This decouples the serialized representation of `Record` from its
internal implementation. It now gets treated as a map type in `serde`.

This has several benefits:
- more efficient representation (not showing inner fields)
- human readable e.g. as a JSON record
- no breaking changes when refactoring the `Record` internals in the
future (see nushell#12326, or potential introduction of `indexmap::IndexMap`
for large N)
- we now deny the creation of invalid records a non-cooperating plugin
could produce
  - guaranteed key-value correspondence
  - checking for unique keys

# Breaking change to the plugin protocol:
Now expects a record/map directly as the `Record.val` field instead of a
serialization of it.
NotTheDr01ds pushed a commit to NotTheDr01ds/nushell that referenced this pull request Apr 12, 2024
# Description
This decouples the serialized representation of `Record` from its
internal implementation. It now gets treated as a map type in `serde`.

This has several benefits:
- more efficient representation (not showing inner fields)
- human readable e.g. as a JSON record
- no breaking changes when refactoring the `Record` internals in the
future (see nushell#12326, or potential introduction of `indexmap::IndexMap`
for large N)
- we now deny the creation of invalid records a non-cooperating plugin
could produce
  - guaranteed key-value correspondence
  - checking for unique keys

# Breaking change to the plugin protocol:
Now expects a record/map directly as the `Record.val` field instead of a
serialization of it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-changes Noted in Breaking Changes section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants