From cbe0b8532aff921e07f81db2cd594e1c91a18bfa Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Fri, 27 Dec 2013 17:22:15 -0800 Subject: [PATCH] feat(util/serializer): add write_char and read_char Signed-off-by: Leonardo de Moura --- src/util/serializer.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/serializer.h b/src/util/serializer.h index 3fe1f6095..4d0833278 100644 --- a/src/util/serializer.h +++ b/src/util/serializer.h @@ -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(&i), sizeof(i)); } void write_int(int i) { m_out.write(reinterpret_cast(&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(&r), sizeof(r)); return r; } unsigned read_unsigned() { unsigned r; m_in.read(reinterpret_cast(&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; 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; } }