13 #ifndef __STOUT_RECORDIO_HPP__ 14 #define __STOUT_RECORDIO_HPP__ 63 inline std::string
encode(
const std::string& record)\
65 return stringify(record.size()) +
"\n" + record;
91 if (state == FAILED) {
92 return Error(
"Decoder is in a FAILED state");
95 std::deque<std::string> records;
97 foreach (
char c, data) {
98 if (state == HEADER) {
112 return Error(
"Failed to decode length '" + buffer +
"': " +
116 length = numify.
get();
121 if (numify.
get() <= 0) {
122 records.push_back(buffer);
125 }
else if (state == RECORD) {
127 CHECK_LT(buffer.size(), length.
get());
131 if (buffer.size() == length.
get()) {
132 records.push_back(std::move(buffer));
158 #endif // __STOUT_RECORDIO_HPP__ Definition: errorbase.hpp:36
Provides facilities for "Record-IO" encoding of data.
Definition: recordio.hpp:55
T & get()&
Definition: try.hpp:80
std::string encode(const std::string &record)
Returns the "Record-IO" encoded record.
Definition: recordio.hpp:63
Try< std::deque< std::string > > decode(const std::string &data)
Decodes another chunk of data from the "Record-IO" stream and returns the attempted decoding of any a...
Definition: recordio.hpp:89
Try< T > numify(const std::string &s)
Definition: numify.hpp:29
#define CHECK_SOME(expression)
Definition: check.hpp:50
const T & get() const &
Definition: option.hpp:119
Decoder()
Definition: recordio.hpp:75
static Try error(const E &e)
Definition: try.hpp:43
bool isError() const
Definition: try.hpp:78
std::string stringify(int flags)
Decodes records from "Record-IO" data (see above).
Definition: recordio.hpp:72