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

Improve performance for high-overhead clients #91

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions aJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ aJsonStream::write(uint8_t ch)
return stream()->write(ch);
}

size_t
aJsonStream::write(const uint8_t *str, size_t len)
{
return stream()->write(str, len);
}

size_t
aJsonStream::readBytes(uint8_t *buffer, size_t len)
{
Expand Down Expand Up @@ -432,10 +438,30 @@ aJsonStream::parseString(aJsonObject *item)
int
aJsonStream::printStringPtr(const char *str)
{
this->print("\"");
this->print('"');
char* ptr = (char*) str;
if (ptr != NULL)
if (ptr != NULL && *ptr != '\0')
{
char* check = ptr;
bool hasEscapes = false;
while (*check != 0)
{
if ((unsigned char) *check > 31 && *check != '\"' && *check != '\\')
{
}
else
{
hasEscapes = true;
break;
}
check++;
}
if (!hasEscapes)
{
this->print(ptr);
this->print('\"');
return 0;
}
while (*ptr != 0)
{
if ((unsigned char) *ptr > 31 && *ptr != '\"' && *ptr != '\\')
Expand Down
1 change: 1 addition & 0 deletions aJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class aJsonStream : public Print {

/* Inherited from class Print. */
virtual size_t write(uint8_t ch);
virtual size_t write(const uint8_t *str, size_t len);

/* stream attribute is used only from virtual functions,
* therefore an object inheriting aJsonStream may avoid
Expand Down