Skip to content

Conversation

davidmorgan
Copy link
Contributor

For #3872 #3706

@davidmorgan davidmorgan requested a review from jakemac53 June 10, 2024 15:16
@davidmorgan
Copy link
Contributor Author

Hi @jakemac53, an attempt to put an actual proposal in writing re: dart_model, nothing really new but including the idea that we go with JSON schema + JsonBuffer per my experiments. Lots to discuss I'm sure :)


Each schema is available in two versions: a "strict" schema that only matches what the current package produces, and a "loose" schema that allows for future changes.

Schemas are versioned using semver. Schemas are updated in place for compatible changes, and as new files for major version (incompatible) releases.
Copy link
Contributor

Choose a reason for hiding this comment

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

How exactly does this interact with the strict vs loose formats?

This package will also be used as a part of SDK binaries, which will not take into account the current users package version, how does that affect things?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good questions.

I'm not currently envisaging using the schemas in any online way; so far I've only considered using them for testing--check that we think we comply with the schema--and for codegen, generate classes that match the schema. So this was mostly a guess about what would be useful.

I already found having the schemas embedded in Dart useful in testing, so that's why I mention it.

Re: the client package version, I guess we send it on the wire at some point.


Data types can be serialized to and from JSON per their schemas.

A binary serialization format is available for performance. When this is used, values are accumulated directly into a binary buffer, so there is no "serialize" step. The received of the value can use values directly from the buffer, so there is no "deserialize" step.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this binary format use String keys, a specified ordering, or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The POC I hacked together is pretty much a byte buffer representation for nested Map<String, Object?>, I like this direction, it should mean we can implement something once and use it without changes as the JSON evolves. It's not a design yet though, just "I think we can model as JSON and still do something fast underneath".

@jakemac53
Copy link
Contributor

As a high level doc of the concept this LGTM.

Would be great to build on this and discuss how exactly it should be used for macros though, how/when exactly diffs should be pushed, how/if this interacts with phases (or rounds), how references to specific objects should be sent back to the compiler, etc.

@davidmorgan
Copy link
Contributor Author

Thanks! Yes, a description of the higher level protocol on top is something we need; as well as next steps for bootstrapping some kind of package:dart_model within the current setup. Let's chat tomorrow :)

@davidmorgan davidmorgan merged commit a186841 into dart-lang:main Jun 11, 2024
@davidmorgan davidmorgan deleted the add-dart-model-proposal branch June 11, 2024 07:49
lrhn pushed a commit that referenced this pull request Jun 28, 2024
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.

2 participants