Hi,
On Wed, May 8, 2019 at 10:04 PM Boris Petrov <
bo...@profuzdigital.com> wrote:
> I haven't thought this through very much but shouldn't this be handled by the library itself (CometD)? Isn't it possible to have a configuration option that specifies at what size to split messages and then to assemble them again on the client side? Otherwise every application will have to implement their own solutions which will pretty much be all the same. What am I missing?
>
CometD cannot split a user-generated JSON, because it does not know
the JSON structure.
Imagine a simple structure of you application data that you want to
send on a Bayeux message, like:
{ "image": "<long base64 of the image>" }
CometD cannot obviously split it on the byte because it will be:
{ "image": "<first half base64>
and
<second half base64>" }
and neither is a valid JSON structure.
In general, CometD cannot split user-provided JSON structures, only
your application can do it.
For example, your application can split the previous example in this way:
{
"chunk": 1,
"chunks": 2,
"image": "<first chunk of base64>"
}
{
"chunk": 2,
"chunks": 2,
"image": "<second chunk of base64>"
}
Then your client can put the 2 chunks of base64 together and get the image.
As you can see the application has to put some additional metadata
(how many total chunks and what chunk is the current one), and format
the message into proper JSON.
Then it can make Bayeux messages out of those splitted JSONs, batch
them together so that the client receives them in sequence.