-
Notifications
You must be signed in to change notification settings - Fork 74
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
Formally define and consistently use "CapData [record]"/"Smallcaps [encoding]"/etc. #1478
Comments
I still believe that even I think however that If we want we can place a restriction that any future body related property will have its name start with I suggest the following types to describes CapData: type Copiable = string | number | boolean | null | Copiable[] | { [key: string]: Copiable };
type JSONFirstCharacter = '{' | '[' | 'n' | 't' | 'f' | '"';
type CapData<
Slot extends string,
BodyContent extends Copiable = Copiable,
BodyKeySuffix extends string = '',
> = { [bodyKey in `body${BodyKeySuffix}`]: BodyContent } & { slot: Slot[] };
type SerializedSmallCapData<Slot extends string> = CapData<Slot, `#${string}`>;
type SerializedQClassCapData<Slot extends string> = CapData<Slot, `${JSONFirstCharacter}${string}`>;
type SmallCapData<Slot extends string> = CapData<Slot, Copiable, 'SmallCap'>; |
slots are not necessarily strings. For example, sometimes they are the remotable itself. |
I've always thought of CapData as an encoding that enabled transport over a serialized channel. I suppose we could define a general purpose CapData as allowing remotable in slots, and a specific SerializableCapData restricting the slots to string variants. However I fail to see the cases where this would be useful vs passing a copy of the original data not encoded. |
what of bigints and undefined? |
More precisely, they are encoded as strings by Smallcaps and as objects by the older import '@endo/init';
import { makeMarshal } from '@endo/marshal';
const marshaller = makeMarshal();
marshaller.toCapData(harden([undefined, 0n])));
// => { body: '[{"@qclass":"undefined"},{"@qclass":"bigint","digits":"0"}]', slots: [] } |
All the CapData type definitions I've seen have been parameterized by the type of slot, so swingset knows about If the marshaller grows additional methods to merely transform a passable object graph into a JSON-serializable object tree, instead of going all the way to a string, I'd like to see that named Although.. I see a fair point that could be made, that I see the value of a marshaller which does slightly less work. It would transfer some responsibility onto the caller (assuming they'll eventually need to get the data into a bytestring, which is almost always true), but it would also let them avoid some amount of duplicate encoding (their one I'm not sure how I feel about the idea of expanding The main downside I can think of is that it weakens the canonical-serialization story a bit. With |
In the structure I suggest, we're using a key named The main requirement is that code handling "cap data" in the general form passes through any non
Correct, we shouldn't rely on comparing a serialized form unless that serialization has a canonical representation (like djson). However marshal does not care about property key order when decoding, and does in fact sort keys when encoding, so we're assured the key order of a plain |
Have these formal definitions been documented and, if so, where? |
Now that we have an implicit definition of "CapData" as a
{ body: string, slots: Copyable[] }
structure with constraints onbody
(that will hopefully be relaxed), we should make that explicit (which may involve naming the@qclass
-based encoding that preceded smallcaps).From #1402 (review) :
The text was updated successfully, but these errors were encountered: