ubjson / universal-binary-json

Community workspace for the Universal Binary JSON Specification.
115 stars 12 forks source link

Optimized nested containers #57

Closed dmitry-ra closed 9 years ago

dmitry-ra commented 9 years ago

In page http://ubjson.org/type-reference/container-types/#optimized-format we have note "Yes it is possible for an array or object to define their type as ‘[' or '{' to signal that they themselves contain additional containers!".

Question: nested containers must be in optimized format or not? Can you provide some examples?

kxepal commented 9 years ago

Currently they don't. There are several issues about how to handle this problem more better: #48 #50 #51 (?)

Steve132 commented 9 years ago

@kxepal

It's not a problem that needs to be 'handled'. Seems incredibly straightforward to me. A typed container can contain other containers. Those containers are parsed as all containers are. Simple.

@dmitry-ra:

nested containers must be in optimized format or not?

Currently, no.

Can you provide some examples?

Sure.

[[][$][[][#][i][5]      //An array of 5 arrays
    [[]         //array 0.  No type.  Dynamic array
        [i][3]
        [Z]
        [T]
        [F]
        [l][4782345193]
        [d][153.132]
        [S][i][3][ham]
    []]
    [[][$][d][#][i][5]  //Array 1. An array of 5 float32 elements.
        [29.97] 
        [31.13]
        [67.0]
        [2.113]
        [23.8889]
    [[]         //Array 2. Empty array
    []]
    [[][$][{][#][i][3]  //Array 3. Array of 3 objects
        [{]
        [}]     //first object is empty
        [{]     //second object is dynamic
            [i][5][Hello][d][3.14]
            [i][3][Foo][S][i][3][Bar]
        [}]
        [{][$][S][#][i][4]      //third object is typed and counted
            [i][3][Dog][i][4][Woof]
            [i][3][Cow][i][3][Moo]
            [i][4][Duck][i][5][Quack]
            [i][5][Horse][i][5][Neigh]

    [[][$][l]       //Array 4.  Dynamic-sized array of 32-bit ints
        [423122]
        [331122]
        [744033]
        [231122]
    []]
kxepal commented 9 years ago

@Steve132 I didn't mean that this isn't possible at all (: Just as for Draft-10 doesn't define such behavior and there are few proposals about how to change and improve it - that was the idea in my comment.

UPDATE: oh really, I miss that point:

NOTE: Yes it is possible for an array or object to define their type as ‘[' or '{' to signal that they themselves contain additional containers!

Well...then there are few proposals around to make it better! P:

Steve132 commented 9 years ago

I didn't mean that this isn't possible at all (: Just as for Draft-10 doesn't define such behavior and there are few proposals about how to change and improve it - that was the idea in my comment.

Ok :) Sorry for the slightly hostile tone then, I just thought that it was mostly sufficiently resolved for Draft 11 (which you can see it was :)) and I was frustrated that it was coming up again as an issue.

Miosss commented 9 years ago

I believe that all the discussion about STC containters now concludes with the example that @Steve132 gave in this thread, am I right? If so, there does not seem to be any complications regarding containers in optimized containers? Or did the status of this discussion (mostly #48 's N-dimensional array optimization) change in the meantime?

ghost commented 9 years ago

@Miosss sorry for not catching the question - you are right, currently there are not problems with mixed optimized/unoptimized containers. @Steve132 example is a good pathological example :)