Split input stream according to JSON structure, not by newlines#14
Split input stream according to JSON structure, not by newlines#14onnokort wants to merge 1 commit intodeavid:masterfrom
Conversation
|
I understand you're trying to compatibilize bjsonrpc with jsonrpc4j, which is good. I suggest to create this as an option when starting bjsonrpc (as an option to connect, or a library-wide option). And that option should default to "split by lines". This way you (and others) can use this library to interface jsonrpc4j adding a simple line at the start of the program, and the rest of the users won't notice anything. If you know if the JSONRPC standard says anything about how to split the messages, please tell me. Thanks for your patch. It looks really good |
…lines Connection objects have a new field 'split' which is a function that will be used to split up the incoming JSON objects. The default behavior is to split by newline, but it can be switched to separate the stream by disassembling into JSON chunks by setting this field to 'Connection.split_by_json'. This makes bjsonrpc compatible with implementations that do not use newlines to separate JSON objects, such as jsonrpc4j.
|
Hey,
Understood. Yes, performance is better with the original code, for execution of 100x your test suite, I have:
Hmm, I was assuming that there is sane JSON structure expected on the wire anyways, so it should not do any harm as long as the JSON splitter works as well. Or are you saying that it will break in the HTTP-specific code path? In that case, I'd suggest that I add a corresponding warning 'JSON splitter won't work with HTTP' to the appropriate docs.
Yes, sounds good, I have just done that and updated the PR accordingly. I am not sure whether style this is in the spirit of your library, though. I also added an option to initialize all Connection objects thusly in the server code. These changes does not seem to impact speed of the newline-splitter at all, at least from my limited tests above.
I was reading into this a bit. I found similar thoughts to my own at http://www.simple-is-better.org/json-rpc/transport_sockets.html, where he goes into splitting by netstrings even. I did not find any reference to THE way how to split. The standard seems to be incomplete here, I guess? |
For example, jsonrpc4j will not output newlines for each JSON structure it
sends.