diff --git a/src/serializer.cc b/src/serializer.cc index 041f1cea..c88d28d5 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -12,7 +12,8 @@ namespace { bool gTestOutputMode = false; } // namespace -// uint8_t +//// Elementary types + void Reflect(Reader& visitor, uint8_t& value) { value = (uint8_t)visitor.GetInt(); } @@ -20,7 +21,6 @@ void Reflect(Writer& visitor, uint8_t& value) { visitor.Int(value); } -// int16_t void Reflect(Reader& visitor, int16_t& value) { value = (int16_t)visitor.GetInt(); } @@ -28,7 +28,6 @@ void Reflect(Writer& visitor, int16_t& value) { visitor.Int(value); } -// int32_t void Reflect(Reader& visitor, int32_t& value) { value = visitor.GetInt(); } @@ -36,7 +35,13 @@ void Reflect(Writer& visitor, int32_t& value) { visitor.Int(value); } -// int64_t +void Reflect(Reader& visitor, uint32_t& value) { + value = visitor.GetUint32(); +} +void Reflect(Writer& visitor, uint32_t& value) { + visitor.Uint32(value); +} + void Reflect(Reader& visitor, int64_t& value) { value = visitor.GetInt64(); } @@ -44,7 +49,6 @@ void Reflect(Writer& visitor, int64_t& value) { visitor.Int64(value); } -// uint64_t void Reflect(Reader& visitor, uint64_t& value) { value = visitor.GetUint64(); } @@ -52,7 +56,6 @@ void Reflect(Writer& visitor, uint64_t& value) { visitor.Uint64(value); } -// double void Reflect(Reader& visitor, double& value) { value = visitor.GetDouble(); } @@ -60,7 +63,6 @@ void Reflect(Writer& visitor, double& value) { visitor.Double(value); } -// bool void Reflect(Reader& visitor, bool& value) { value = visitor.GetBool(); } diff --git a/src/serializer.h b/src/serializer.h index 2e66737f..dfe6252e 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -30,6 +30,7 @@ class Reader { virtual void GetNull() = 0; virtual bool GetBool() = 0; virtual int GetInt() = 0; + virtual uint32_t GetUint32() = 0; virtual int64_t GetInt64() = 0; virtual uint64_t GetUint64() = 0; virtual double GetDouble() = 0; @@ -50,6 +51,7 @@ class Writer { virtual void Null() = 0; virtual void Bool(bool x) = 0; virtual void Int(int x) = 0; + virtual void Uint32(uint32_t x) = 0; virtual void Int64(int64_t x) = 0; virtual void Uint64(uint64_t x) = 0; virtual void Double(double x) = 0; @@ -153,6 +155,9 @@ void Reflect(Writer& visitor, int16_t& value); void Reflect(Reader& visitor, int32_t& value); void Reflect(Writer& visitor, int32_t& value); +void Reflect(Reader& visitor, uint32_t& value); +void Reflect(Writer& visitor, uint32_t& value); + void Reflect(Reader& visitor, int64_t& value); void Reflect(Writer& visitor, int64_t& value); diff --git a/src/serializers/json.h b/src/serializers/json.h index 297e188f..67cb53b0 100644 --- a/src/serializers/json.h +++ b/src/serializers/json.h @@ -23,6 +23,7 @@ class JsonReader : public Reader { void GetNull() override {} bool GetBool() override { return m_->GetBool(); } int GetInt() override { return m_->GetInt(); } + uint32_t GetUint32() override { return uint32_t(m_->GetUint64()); } int64_t GetInt64() override { return m_->GetInt64(); } uint64_t GetUint64() override { return m_->GetUint64(); } double GetDouble() override { return m_->GetDouble(); } @@ -64,6 +65,7 @@ class JsonWriter : public Writer { void Null() override { m_->Null(); } void Bool(bool x) override { m_->Bool(x); } void Int(int x) override { m_->Int(x); } + void Uint32(uint32_t x) override { m_->Uint64(x); } void Int64(int64_t x) override { m_->Int64(x); } void Uint64(uint64_t x) override { m_->Uint64(x); } void Double(double x) override { m_->Double(x); } diff --git a/src/serializers/msgpack.h b/src/serializers/msgpack.h index df55a9da..91b08667 100644 --- a/src/serializers/msgpack.h +++ b/src/serializers/msgpack.h @@ -33,6 +33,7 @@ class MessagePackReader : public Reader { void GetNull() override { pk_->next(oh_); } bool GetBool() override { return Get(); } int GetInt() override { return Get(); } + uint32_t GetUint32() override { return Get(); } int64_t GetInt64() override { return Get(); } uint64_t GetUint64() override { return Get(); } double GetDouble() override { return Get(); } @@ -64,6 +65,7 @@ class MessagePackWriter : public Writer { void Null() override { m_->pack_nil(); } void Bool(bool x) override { m_->pack(x); } void Int(int x) override { m_->pack(x); } + void Uint32(uint32_t x) override { m_->pack(x); } void Int64(int64_t x) override { m_->pack(x); } void Uint64(uint64_t x) override { m_->pack(x); } void Double(double x) override { m_->pack(x); }