Closed daurnimator closed 5 years ago
I found the bug, but I'm not sure how I want to handle it. The intended code was supposed to throw an error, but thinking about it now, I'm not sure if I want to do that as it is a valid condition. I currently throw errors on bad input, which I'm also thinking was a bad idea (throwing on encoding is fine as that's a programming error, but upon decoding? That's not the programmer's fault but the sender's---at least, that's my thinking).
It now throws an error on no input, which was the original intent.
Is there something I can encode to get "nothing"?
That's an interesting question---by "nothing" to you mean a 0-byte blob of data? Or some CBOR value that represents "nothing"? I never thought about the former (what would that even mean?) and the later can be accomplished by calling cbor.SIMPLE.null(), which returns a CBOR null value or by calling cbor.SIMPLE.undefined(), which returns a CBOR undefined value. I'm not sure what would be better.
by "nothing" to you mean a 0-byte blob of data
That's what I originally attempted. But I now see that that is probably incorrect
Or some CBOR value that represents "nothing"? I never thought about the former (what would that even mean?) and the later can be accomplished by calling cbor.SIMPLE.null(), which returns a CBOR null value or by calling cbor.SIMPLE.undefined(), which returns a CBOR undefined value. I'm not sure what would be better.
I guess I was looking for cbor.encode(nil)
But that works. cbor.encode()
and cbor.encode(nil)
both return a string of one character, "\246" which is a CBOR null value.