jamulussoftware / jamulussoftware/jamulus

Add non line by line JSON-RPC parsing for clients which do not send line by line

Open
#3,421 1 comment 0 reactions 1 assignee Claimed by @ann0see View on GitHub
feature request JSON-RPC
Dominant language
C
Stars
1.1k
Forks
248
Avg merge
2d 3h
Merged PRs (30d)
9

Description

**What is the current behaviour and why should it be changed?**

Currently, a new JSON-RPC message is only interpreted if the JSON-RPC client sends a new line. However, there seem to be clients which do not send a new line per new message. An example would be e.g. https://github.com/tesseract-one/JsonRPC.swift

**Describe possible approaches**

in rpcserver.cpp, parse for "{" and "}" alongside "\n" - maybe we also need to check for windows line endings.

Something like:

```
- while ( pSocket->canReadLine() )
+ while ( pSocket->bytesAvailable() > 0 )
{
- QByteArray line = pSocket->readLine();
+ // read line or until we reach the same number of closing "}" as opening "{" which represents one message.
+ // Some clients may not send line by line
+
+ QByteArray line;
+ int numBrackets = 0;
+ while ( pSocket->bytesAvailable() > 0 )
+ {
+ QByteArray readByte = pSocket->read ( 1 );
+ if ( readByte.at ( 0 ) == '{' )
+ {
+ numBrackets++;
+ }
+ else if ( readByte.at ( 0 ) == '}' && numBrackets > 0 )
+ {
+ numBrackets--;
+ }
+
+ if ( readByte.at ( 0 ) == '}' && numBrackets == 1 )
+ {
+ // message most likely ended
+ numBrackets = 0;
+ line.append ( '}' );
+ break;
+ }
+ else if ( readByte.at ( 0 ) == '\n' )
+ {
+ // new line character means we are finished with this transmission by definition
+ break;
+ }
+ line.append ( readByte );
+ }

```

**Has this feature been discussed and generally agreed?**

No.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.