-
Notifications
You must be signed in to change notification settings - Fork 2
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
Use CBOR tags to disambiguate which struct to fill an interface field with #8
Comments
Added support for slices containing pointers to struct. Started cleaning up support for different int sizes in structs. These seem to require some manual coding and shrinking to smaller types. More implementation and exhaustive testing is needed in this regard. We should also clean up all the type assertions to check the type and return an error if there is a mismatch instead of panicing because it would be bad for a server process to panic when a client sends malformed CBOR. For the purposes of using this library for RAINS, issue #8 will need to be fixed which seems most suitable by not having interface types in the data struct, as this is how the previous cap'n proto implementation was working. Personally I feel that if there is only one implementation of that interface there is not much benefit for it being an interface, it is much easier to just have a struct which the needed methods are implemented on. If replacement is a concern then it could be placed in a different package which can be swapped out easily.
tl;dr This is what CBOR tags are for. In the case that there is not enough semantic information in the CBOR object to determine what Go type an object needs to be (where this semantic information can come from the containing object, as in the RAINS message case, where the message section type is defined by the content of the section), that object should be preceded with a tag. Missing from We could use this to handle timestamps automatically, as well as to allow (Will leave it up to @rayhaanj as whether you want this as a separate issue, or just want to mutate this issue to be about tag reading. I can also drop by CAB before the group meering to discuss if it'd be helpful) |
I delved too deep into the reflection that I forgot about CBOR tags. I'll work on using tags to disambiguate the structs that go into interfaces, that seems like a nice solution (and rename this issue to that). |
Been going back and forth on this for a while, but it seems that it is unnecessary to have the registered structs themselves implement The problem is knowing which struct is being read in, and this can simply be done within borat itself, however will require the map parser to be changed to return a map which contains potentially tagged items. Then the struct reader can interpret the tag and choose the appropriate structure to unmarshal into. If the map is just being read as a normal map then the optionally tagged items can be converted into untagged items and returned to the caller. So I'll clean up and follow this plan now. |
I do apologise if this is the wrong place to ask but would this also allow borat to tag structs? And if so is this something that is being worked on? Thank you :) |
If a struct like the following is passed to the Unmarshaler, then it is unclear as to how the unmarshaler would know which concrete type to fill into the struct field:
When the struct is marshaled the information about what struct was actually in the interface is lost, only an un-type-annotated map is transferred via CBOR, so it does not seem possible to work out what type to create to put in this field when unmarshaling.
The text was updated successfully, but these errors were encountered: