Convert DrivenEngine rlog/wlog to use BaseWriter
This commit is contained in:
@@ -31,14 +31,13 @@
|
||||
// void write_length(size_t data)
|
||||
// void write_string(std::string_view data)
|
||||
//
|
||||
// In order to derive from BaseWriter, you must use the CRTP pattern:
|
||||
// You should derive from BaseWriter using the CRTP pattern:
|
||||
//
|
||||
// class DerivedWriter : public BaseWriter<DerivedWriter>
|
||||
//
|
||||
// And you must provide two methods in the derived class:
|
||||
// You must provide two methods in the derived class:
|
||||
//
|
||||
// write_bytes(const char *n, size_t size)
|
||||
//
|
||||
// raise_truncated()
|
||||
//
|
||||
///////////////////////////////////////////////////////////////
|
||||
@@ -111,15 +110,16 @@ public:
|
||||
// String read_string_limit(uint64_t size);
|
||||
// String read_string();
|
||||
//
|
||||
// In order to derive from BaseReader, you must use the CRTP pattern:
|
||||
// You should derive from BaseReader using the CRTP pattern:
|
||||
//
|
||||
// class DerivedReader : public BaseReader<DerivedReader>
|
||||
//
|
||||
// The derived class must provide:
|
||||
//
|
||||
// using read_string_type = std::string; // or similar
|
||||
// using read_string_type = std::string; // or compatible
|
||||
// void read_bytes_into(char *n, size_t size)
|
||||
// void raise_string_too_long();
|
||||
// bool read_beyond_eof();
|
||||
//
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -129,7 +129,9 @@ protected:
|
||||
template<class T>
|
||||
T read_value_core() {
|
||||
T result;
|
||||
static_cast<Derived*>(this)->read_bytes_into((char *)(&result), sizeof(result));
|
||||
Derived *dthis = static_cast<Derived*>(this);
|
||||
dthis->read_bytes_into((char *)(&result), sizeof(result));
|
||||
if (dthis->read_beyond_eof()) result = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -159,9 +161,11 @@ public:
|
||||
|
||||
auto read_string_limit(uint64_t limit) {
|
||||
size_t len = read_length();
|
||||
if (len > limit) static_cast<Derived*>(this)->raise_string_too_long();
|
||||
Derived *dthis = static_cast<Derived*>(this);
|
||||
if (len > limit) dthis->raise_string_too_long();
|
||||
typename Derived::read_string_type result(len, ' ');
|
||||
static_cast<Derived*>(this)->read_bytes_into(&(result[0]), len);
|
||||
dthis->read_bytes_into(&(result[0]), len);
|
||||
if (dthis->read_beyond_eof()) result.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user