feat(util/serializer): add write_char and read_char
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
b72937c02c
commit
cbe0b8532a
1 changed files with 4 additions and 0 deletions
|
@ -24,6 +24,7 @@ public:
|
|||
void write_string(std::string const & str) { m_out.write(str.c_str(), str.size() + 1); }
|
||||
void write_unsigned(unsigned i) { m_out.write(reinterpret_cast<char*>(&i), sizeof(i)); }
|
||||
void write_int(int i) { m_out.write(reinterpret_cast<char*>(&i), sizeof(i)); }
|
||||
void write_char(char c) { m_out.put(c); }
|
||||
void write_bool(bool b) { m_out.put(b ? 1 : 0); }
|
||||
};
|
||||
|
||||
|
@ -33,6 +34,7 @@ inline serializer & operator<<(serializer & s, char const * str) { s.write_strin
|
|||
inline serializer & operator<<(serializer & s, std::string const & str) { s.write_string(str); return s; }
|
||||
inline serializer & operator<<(serializer & s, unsigned i) { s.write_unsigned(i); return s; }
|
||||
inline serializer & operator<<(serializer & s, int i) { s.write_int(i); return s; }
|
||||
inline serializer & operator<<(serializer & s, char c) { s.write_char(c); return s; }
|
||||
inline serializer & operator<<(serializer & s, bool b) { s.write_bool(b); return s; }
|
||||
|
||||
/**
|
||||
|
@ -46,6 +48,7 @@ public:
|
|||
std::string read_string();
|
||||
int read_int() { int r; m_in.read(reinterpret_cast<char*>(&r), sizeof(r)); return r; }
|
||||
unsigned read_unsigned() { unsigned r; m_in.read(reinterpret_cast<char*>(&r), sizeof(r)); return r; }
|
||||
char read_char() { return m_in.get(); }
|
||||
bool read_bool() { return m_in.get() != 0; }
|
||||
};
|
||||
|
||||
|
@ -54,5 +57,6 @@ typedef extensible_object<deserializer_core> deserializer;
|
|||
inline deserializer & operator>>(deserializer & d, std::string & str) { str = d.read_string(); return d; }
|
||||
inline deserializer & operator>>(deserializer & d, unsigned & i) { i = d.read_unsigned(); return d; }
|
||||
inline deserializer & operator>>(deserializer & d, int & i) { i = d.read_int(); return d; }
|
||||
inline deserializer & operator>>(deserializer & d, char & c) { c = d.read_char(); return d; }
|
||||
inline deserializer & operator>>(deserializer & d, bool & b) { b = d.read_bool(); return d; }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue