Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 657c6d3

Browse files
committed
All examples are working
1 parent 2dd9598 commit 657c6d3

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

modem/push-command.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22

33
namespace firebase {
44
namespace modem {
5+
namespace {
6+
// TODO(edcoyne): We should use a json library to escape.
7+
String EncodeForJson(String input) {
8+
input.replace("\\", "\\\\");
9+
input.replace("\"", "\\\"");
10+
return "\"" + input + "\"";
11+
}
12+
} // namespace
513

614
bool PushCommand::execute(const String& command,
715
InputStream* in, OutputStream* out) {
816
if (in == nullptr || out == nullptr) {
917
return false;
1018
}
1119

12-
if (command != "SET") {
20+
if (command != "PUSH") {
1321
return false;
1422
}
1523

1624
String path(in->readStringUntil(' '));
1725
String data(in->readLine());
1826

19-
// First char will be a ' ', drop it.
20-
data = data.substring(1);
21-
22-
// TODO(ed7coyne): encode data as json.
23-
24-
std::unique_ptr<FirebasePush> push(fbase().pushPtr(path, data));
27+
std::unique_ptr<FirebasePush> push(
28+
fbase().pushPtr(path, EncodeForJson(data)));
2529

2630
if (push->error()) {
2731
out->print("-FAIL ");

modem/remove-command.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool RemoveCommand::execute(const String& command,
2222
return false;
2323
}
2424

25-
out->print("+OK");
25+
out->println("+OK");
2626
return true;
2727
}
2828

modem/set-command.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
namespace firebase {
44
namespace modem {
5+
namespace {
6+
// TODO(edcoyne): We should use a json library to escape.
7+
String EncodeForJson(String input) {
8+
input.replace("\\", "\\\\");
9+
input.replace("\"", "\\\"");
10+
return "\"" + input + "\"";
11+
}
12+
} // namespace
513

614
bool SetCommand::execute(const String& command,
715
InputStream* in, OutputStream* out) {
@@ -16,12 +24,8 @@ bool SetCommand::execute(const String& command,
1624
String path(in->readStringUntil(' '));
1725
String data(in->readLine());
1826

19-
// First char will be a ' ', drop it.
20-
data = data.substring(1);
21-
22-
// TODO(ed7coyne): encode data as json.
23-
24-
std::unique_ptr<FirebaseSet> set(fbase().setPtr(path, data));
27+
std::unique_ptr<FirebaseSet> set(fbase().setPtr(path,
28+
EncodeForJson(data)));
2529

2630
if (set->error()) {
2731
out->print("-FAIL ");

0 commit comments

Comments
 (0)