FYI -- works in Octave now
unicode2native and native2unicode seem to work fine in more recent versions of Octave, so this library does too.
I don't really know what to do with the containers.Map returned in lieu of the input struct, but 1. that's my problem, 2. it works the same in MATLAB, and 3. the data looks fine if I serialize it as JSON:
> version
ans = 5.1.0
>> addpath('~/octave/msgpack')
>> data = {'life, the universe, and everything', struct('the_answer', 42)};
>> bytes = dumpmsgpack(data);
>> decode = parsemsgpack(bytes)
decode =
{
[1,1] = life, the universe, and everything
[1,2] =
<object containers.Map>
}
>> addpath('~/octave/jsonlab')
>> savejson( decode(1,2) )
ans = {
"root": [
"the_answer": 42
]
}
Cool, thank you very much for the heads-up!
If you'd like to contribute an additional switch in parsemsgpack for deserializing maps as structs instead of containers.Map, I'd be grateful for the pull request!
I know Maps are really clunky to use in Matlab/Octave. And that's a shame, because they are a much more useful and versatile data structure than structs (much like dicts/hashmaps/objects in Python/Ruby/Java/Lua/Javascript). Plus, not every msgpack map can be represented as a struct, but it can always be represented as a Map.
Just to follow up -- maps do seem to be clunkier than they should be, but my own ignorance of MATLAB/Octave is also at fault. I didn't realize that decode(1,2) is not a map, it's a cell containing a map.
I'm not sure of The Right Way, but this recovers the tuple in Octave with no JSON serialization needed:
>> (decode(1,2){1})('the_answer')
ans = 42
FWIW, I think Octave hurts its case with this misleading error message:
>> keys(decode(1,2))
warning: the 'keys' function is not yet implemented in Octave
Please read <https://www.octave.org/missing.html> to learn how you can
contribute missing functionality.
error: 'keys' undefined near line 1 column 1
>> keys(decode(1,2){1})
ans =
{
[1,1] = the_answer
}