-
Notifications
You must be signed in to change notification settings - Fork 59
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
Nesting custom tags #252
Comments
I'm not sure. A series of CBOR byte codes that such a structure would encode into would surely help me figure out if this is feasible. |
I am working on building out the byte codes that match my idea, which is highlighting for me that perhaps this isn't a documentation issue with
Based on that idea, my concept is effectively to have a structure that looks like the following:
This is (amusingly) exactly the scenario defined in the spec; I have a data item ( Hopefully that helps clarify the intent. It seems from the spec like this should be possible, but both fortunately and unfortunately, |
After spending more time reading through the spec, I think that one reasonable sequence of bytes might look like the following. I used the CBOR Playground to test this.
For easier copy-paste, here is the raw byte string:
It seems like the array specifiers are perhaps a bit of a cheat, since I am using them to wrap existing well-defined CBOR types (floats), but if I can figure out how to define this structure in I am not able to get |
Ok, so have you read this yet? |
Yes, and that's where I think I am misunderstanding things. I have simple implementations of
I can then construct an object to encode, and encode it:
The resultant byte string is below:
This leads me to two questions; first - the tags I've defined ( The second question is what actually caused me to ask for help. If I have a sequence of bytes that means If I pass the byte string from my comment above (the one I constructed by hand) into
Hopefully that makes sense - it really feels like I am just reading the docs wrong here, since it seems like this is the expected behavior from the library, but not what I expected. |
What does your |
To simplify things, I've created a small example script that is just the bare bones of what I'm trying to do:
The goal is to end up with a reconstructed value that matches the test value - both in terms of the actual numeric values, but also the types. So the two areas where I'm doing something wrong are:
Thank you for helping out; I apologize if this feels like a really dumb sequence of back-and-forth - I really appreciate your time. |
This is probably caused by inheriting from |
That works for On a related note; I would have expected |
You're only telling As for the semantics of handling custom types inherited from natively handled types, I'll think about changing the semantics in the next major release (as such a change would be potentially backwards incompatible). The ability to override the encoding and decoding of any type has been requested before. |
Got it, thanks. I'll see how I can work around the inheritance issue. I think I can handle the callbacks by building functions that can handle nested types at runtime, but I'll have to play with that for a while - thank you for helping me understand! |
Things to check first
Feature description
I am working on a project where I'd like to be able to serialize nested custom tags, or collections of custom tags. I have been trying to understand from the documentation the best approach to use, especially if I'd also like to be able to use those tags separately. It feels like it should be possible now, but I can't feel out the right way to do it. I suspect it's just a documentation/user knowledge problem, so if there is an obvious way to do this that I am not understanding, I would be more than happy to take that lesson and write up a self-contained example and paragraph for a documentation PR.
Use case
As an example, I have an
Interval
type which is a wrapper around a 2-tuple of floats, with operators defined for interval arithmetic. Separately, I have aVector[T]
type which is a generic numeric vector (similar to a numpy vector or glm, etc) - one common use case in my project is aVector[Interval]
- so while I've defined encoders and decoders that can be passed todefault
andtag_hook
for the standalone types, I haven't found the right way to handle the case whereVector
is a collection ofInterval
s (rather thanfloat
orint
). Is there a way to do this that I am missing? Any pointers would be much appreciated!The text was updated successfully, but these errors were encountered: