7 #ifndef ATLAS_CODECS_PACKED_H 8 #define ATLAS_CODECS_PACKED_H 11 #include <Atlas/Codec.h> 16 namespace Atlas {
namespace Codecs {
45 void poll(
bool can_read)
override;
53 void mapIntItem(std::string name,
long)
override;
67 std::istream& m_istream;
68 std::ostream& m_ostream;
85 std::stack<State> m_state;
103 void parsingBegins(
char);
104 void parseStream(
char);
106 void parseList(
char);
107 void parseMapBegin(
char);
108 void parseListBegin(
char);
110 void parseFloat(
char);
111 void parseString(
char);
112 void parseName(
char);
114 inline std::string hexEncode(std::string data)
117 for (
size_t i = 0; i < data.size(); i++) {
118 char currentChar = data[i];
120 switch(currentChar) {
132 m_encoded.reserve(data.size() + (data.size() / 4));
133 m_encoded.assign(data, 0, i);
134 for (; i < data.size(); i++) {
135 currentChar = data[i];
137 switch(currentChar) {
152 m_encoded += currentChar;
157 return std::move(m_encoded);
167 inline const std::string hexDecode(std::string data)
170 for (
size_t i = 0; i < data.size(); i++) {
171 char currentChar = data[i];
172 if (currentChar ==
'+') {
175 m_decoded.reserve(data.size());
176 m_decoded.assign(data, 0, i);
178 for (; i < data.size(); i++) {
179 currentChar = data[i];
180 if (currentChar ==
'+') {
181 m_hex[0] = data[++i];
182 m_hex[1] = data[++i];
186 m_decoded += currentChar;
190 return std::move(m_decoded);
const std::string charToHex(char c)
Convert an ASCII char to its hexadecimal value.
Definition: Utility.h:26
std::string m_encoded
Preallocated to increase performance.
Definition: Packed.h:93
Atlas stream bridge.
Definition: Bridge.h:35
void listListItem() override
Starts a list object in the currently streamed list.
char m_hex[3]
Preallocated to increase performance.
Definition: Packed.h:101
Various utility functions for codec implementation.
void mapListItem(std::string name) override
Starts a list object to the currently streamed map.
void listFloatItem(double) override
Adds a float to the currently streamed list.
void streamMessage() override
Start a message in an Atlas stream.
void listEnd() override
Ends the currently streamed list.
void mapEnd() override
Ends the currently streamed map.
The Atlas namespace.
Definition: Bridge.h:20
Atlas stream codec.
Definition: Codec.h:27
void mapFloatItem(std::string name, double) override
Adds a float to the currently streamed map.
std::string m_decoded
Preallocated to increase performance.
Definition: Packed.h:97
void listStringItem(std::string) override
Adds a string to the currently streamed list.
void listMapItem() override
Starts a map object in the currently streamed list.
void streamBegin() override
Begin an Atlas stream.
char hexToChar(const char *hex)
Convert a string with a hexadecimal value (2 characters) to an ASCII char.
Definition: Utility.h:38
void mapMapItem(std::string name) override
Starts a map object to the currently streamed map.
void mapStringItem(std::string name, std::string) override
Adds a string to the currently streamed map.
void mapIntItem(std::string name, long) override
Adds an integer to the currently streames map.
void streamEnd() override
Ends the Atlas stream.
void listIntItem(long) override
Adds an integer to the currently streames list.