Skip to content
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

decodeArrayStream vs decodeStream #89

Closed
grantila opened this issue Oct 31, 2019 · 3 comments
Closed

decodeArrayStream vs decodeStream #89

grantila opened this issue Oct 31, 2019 · 3 comments
Labels

Comments

@grantila
Copy link
Contributor

The documentation of decodeArrayStream and decodeStream is a bit vague, and the signatures and examples are identical.

Do we need both? And what's the exact difference? One accepts "an array of items" and the other "independent MessagePack items". Huh?

My exact question is this; Do any of these support byte streams (of arbitrary size) of data consisting of MsgPack items, or do the inputs have to be "complete"?

What I'm explicitly after is support for this:

Consider MsgPack-encoded objects:
+---------------------+ +----------------+ +----------------+
|    MsgPack enc 1    | | MsgPack enc 2  | | MsgPack enc 3  |
+---------------------+ +----------------+ +----------------+
Although split into Uint8Array chunks:
+-------+ +-------+ +-------+ +-------+ +--------+ +--------+ 
|   1   | |   2   | |   3   | |   4   | |   5    | |   6    |
+-------+ +-------+ +-------+ +-------+ +--------+ +--------+ 
When these chunks are provided to decode*Stream(), I get a stream of:
                       +---------------------+
                       |    MsgPack dec 1    |
                       +---------------------+
                                          +----------------+
                                          | MsgPack dec 2  |
                                          +----------------+
                                                             +----------------+
                                                             | MsgPack dec 3  |
                                                             +----------------+
               ------------ Time ----------->

Is this possible?

@gfx gfx added the Question label Oct 31, 2019
@gfx
Copy link
Member

gfx commented Oct 31, 2019

Those examples look not so good and should be improved.

In fact, both can handle chunk of encoded MessagePack binaries, but they handle different formats.

decodeStream handles {"name": "foo"}{"name":"bar"} (shown as JSON for readability), whereas decodeArrayStream handles [{"name": "foo"},{"name":"bar"}].

Does it make sense for you?

@grantila
Copy link
Contributor Author

grantila commented Nov 1, 2019

Kind of, clarifying that would surely be useful.

My question is rather, can I send a stream of individually incomplete chunks? Uint8Array's that are, say, at most n bytes large. This would be an input stream as your example of (n=6):

         +--------+
 Chunk 1 | {"name |
         +--------+
         +--------+
 Chunk 2 | ": "fo |
         +--------+
         +--------+
 Chunk 3 | o"}{"n |
         +--------+
         +--------+
 Chunk 4 | ame":" |
         +--------+
         +-------+
 Chunk 5 | bar"} |
         +-------+

Can I get this output stream of decoded:

           +---------------+
 Message 1 | {name: 'foo'} |
           +---------------+
           +---------------+
 Message 2 | {name: 'bar'} |
           +---------------+

Is this possible?

@gfx
Copy link
Member

gfx commented Nov 5, 2019

@grantila

Yes, it is possible and the default in all the async or stream decoders. For example, see tests for decodeAsync https://github.com/msgpack/msgpack-javascript/blob/master/test/decodeAsync.test.ts#L28-L37

@gfx gfx closed this as completed Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants