4 ms·
Do you not allow \n inside your JSON or encode your JSON as base64? If not you might have problems with disambiguating frame ends from line breaks inside frames
by Matthias247 9y ago
Do you not allow \n inside your JSON or encode your JSON as base64? If not you might have problems with disambiguating frame ends from line breaks inside frames.
A common way for framing is to prepend each frame with it's encoded length. That's easier, faster and less error-prone than searching for ASCII delimeters.
- AgentME 9y agoIf you do the JSON serialization yourself, there's no reason for newlines to be in the JSON. (Newlines within strings are encoded as \n.)
- deleted 9y ago[deleted]
- justinsaccount 9y agoa newline is encoded as the two characters "\n" in json and would not be confused with a literal \n (aka \x0a) character
- dungle6 9y agoErm...JSON allows whitespace last I checked. \n (ie the actual \x0a) is a whitespace character, and so can appear as a discarded token in JSON. So you would basically have to restrict to a subset of JSON -- it's not actually JSON anymore at that point.
- tlb 9y agoI'm generating the JSON, either with custom C++ marshaling routines or with JSON.stringify which doesn't include newlines unless you give it extra arguments. I believe that any valid JSON can be converted to a single line by changing any '\n' bytes to ' '. Literal '\n' bytes are not allowed inside strings, and outside strings any whitespace is equivalent.