-
Notifications
You must be signed in to change notification settings - Fork 88
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
Textual representation of the wire format of a type (recursively) #143
Comments
Hey @ia0, I'm definitely open to a separate tool that consumes the At the moment I believe you could print with Debug, or serialize the schema to some format, such as JSON, and you could check that with something like I think this would be a useful stepping stone towards also generating ser/de impls in languages other than Rust (and not with Serde) in the future potentially. |
I'll try to get something on my side first, since the wire format is stable (and I don't expect it to change on the parts that I'm using, I'm not using |
For what it's worth, I plan to release I'm definitely interested in seeing what you build! Part of the intent of the Schema derive was to be able to do these kinds of things, I just hadn't gotten to it yet. |
I went with this wire representation and convert from
The general format is |
Ok, I finally have something that I can show. I later learned about your
Hope this helps! |
Neat, thanks! I'll take a look at this soon. Btw @ia0 if you want to have a call to chat about this some time, I'd be interested, my email is on my profile! |
I would like to have a textual representation of the wire format of a type. I would use it as a generated file in my repository during reviews. The format could look like an annotated grammar of the wire format. Here is an example of the workflow I have in mind:
foo
in a repository, that contains a few serializable types likeFoo
andBar
.foo.postcard
file containing a textual representation ofFoo
in wire format (essentially the language recognized by deserialization, which is a bit more than the one produced by serialization because postcard is not canonical).The textual representation can simply be some annotated grammar of the language recognized by postcard for the type. For example:
Would become something like this:
Note how named things are prefixed with
name=
. Those annotations do not affect the wire format (the language recognized). Terminals are just bytes (0x00
to0xff
). Identifiers (Rust paths) are non-terminals unless they are a name. Also note the difference between "unions" using|=
and "sequences" using&=
(the symbol is repeated on each line to support empty unions and sequences). Ideally the file would recursively contain all definitions (hereFooA
,FooB1
, etc).In my case, I would consider the following change acceptable (it forgets a name, thus doesn't affect the wire format):
Would result in the following diff:
I would also consider the following diff acceptable (when deprecating a variant):
I suspect the experimental "schema" feature could be useful, however I see at least 2 problems:
Note that maps are really just
n*(k v)
wherek
andv
are schema names. And byte sequences are justn*u8
. By definition ofSeq
,n
isvarint(usize)
.The text was updated successfully, but these errors were encountered: