summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@users.sourceforge.jp>2010-08-27 17:42:05 +0900
committerfrsyuki <frsyuki@users.sourceforge.jp>2010-08-27 17:42:05 +0900
commitfe2a0f5089ebfc5c03db783a1f85b1c7c217128a (patch)
tree007dc7dcf1f0f60cb1a455c7640c7c16cad9ac60 /cpp/src
parent59ba8dec4ee082e8777047e6ae72e8b6998cdc79 (diff)
downloadmsgpack-python-fe2a0f5089ebfc5c03db783a1f85b1c7c217128a.tar.gz
cpp: adds fixed length serialization for integers
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Makefile.am3
-rw-r--r--cpp/src/msgpack/pack.h12
-rw-r--r--cpp/src/msgpack/pack.hpp56
-rw-r--r--cpp/src/msgpack/type.hpp3
-rw-r--r--cpp/src/msgpack/type/fixint.hpp89
5 files changed, 161 insertions, 2 deletions
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am
index 31096f0..0979d23 100644
--- a/cpp/src/Makefile.am
+++ b/cpp/src/Makefile.am
@@ -58,10 +58,11 @@ nobase_include_HEADERS += \
msgpack/zone.hpp \
msgpack/type.hpp \
msgpack/type/bool.hpp \
+ msgpack/type/deque.hpp \
msgpack/type/float.hpp \
+ msgpack/type/fixint.hpp \
msgpack/type/int.hpp \
msgpack/type/list.hpp \
- msgpack/type/deque.hpp \
msgpack/type/map.hpp \
msgpack/type/nil.hpp \
msgpack/type/pair.hpp \
diff --git a/cpp/src/msgpack/pack.h b/cpp/src/msgpack/pack.h
index 9c4ce59..c156496 100644
--- a/cpp/src/msgpack/pack.h
+++ b/cpp/src/msgpack/pack.h
@@ -70,6 +70,15 @@ static int msgpack_pack_int16(msgpack_packer* pk, int16_t d);
static int msgpack_pack_int32(msgpack_packer* pk, int32_t d);
static int msgpack_pack_int64(msgpack_packer* pk, int64_t d);
+static int msgpack_pack_fix_uint8(msgpack_packer* pk, uint8_t d);
+static int msgpack_pack_fix_uint16(msgpack_packer* pk, uint16_t d);
+static int msgpack_pack_fix_uint32(msgpack_packer* pk, uint32_t d);
+static int msgpack_pack_fix_uint64(msgpack_packer* pk, uint64_t d);
+static int msgpack_pack_fix_int8(msgpack_packer* pk, int8_t d);
+static int msgpack_pack_fix_int16(msgpack_packer* pk, int16_t d);
+static int msgpack_pack_fix_int32(msgpack_packer* pk, int32_t d);
+static int msgpack_pack_fix_int64(msgpack_packer* pk, int64_t d);
+
static int msgpack_pack_float(msgpack_packer* pk, float d);
static int msgpack_pack_double(msgpack_packer* pk, double d);
@@ -99,6 +108,9 @@ int msgpack_pack_object(msgpack_packer* pk, msgpack_object d);
#define msgpack_pack_inline_func_cint(name) \
inline int msgpack_pack ## name
+#define msgpack_pack_inline_func_fixint(name) \
+ inline int msgpack_pack_fix ## name
+
#define msgpack_pack_user msgpack_packer*
#define msgpack_pack_append_buffer(user, buf, len) \
diff --git a/cpp/src/msgpack/pack.hpp b/cpp/src/msgpack/pack.hpp
index 2f7dfa0..0090b96 100644
--- a/cpp/src/msgpack/pack.hpp
+++ b/cpp/src/msgpack/pack.hpp
@@ -45,6 +45,15 @@ public:
packer<Stream>& pack_int32(int32_t d);
packer<Stream>& pack_int64(int64_t d);
+ packer<Stream>& pack_fix_uint8(uint8_t d);
+ packer<Stream>& pack_fix_uint16(uint16_t d);
+ packer<Stream>& pack_fix_uint32(uint32_t d);
+ packer<Stream>& pack_fix_uint64(uint64_t d);
+ packer<Stream>& pack_fix_int8(int8_t d);
+ packer<Stream>& pack_fix_int16(int16_t d);
+ packer<Stream>& pack_fix_int32(int32_t d);
+ packer<Stream>& pack_fix_int64(int64_t d);
+
packer<Stream>& pack_short(short d);
packer<Stream>& pack_int(int d);
packer<Stream>& pack_long(long d);
@@ -78,6 +87,15 @@ private:
static void _pack_int32(Stream& x, int32_t d);
static void _pack_int64(Stream& x, int64_t d);
+ static void _pack_fix_uint8(Stream& x, uint8_t d);
+ static void _pack_fix_uint16(Stream& x, uint16_t d);
+ static void _pack_fix_uint32(Stream& x, uint32_t d);
+ static void _pack_fix_uint64(Stream& x, uint64_t d);
+ static void _pack_fix_int8(Stream& x, int8_t d);
+ static void _pack_fix_int16(Stream& x, int16_t d);
+ static void _pack_fix_int32(Stream& x, int32_t d);
+ static void _pack_fix_int64(Stream& x, int64_t d);
+
static void _pack_short(Stream& x, short d);
static void _pack_int(Stream& x, int d);
static void _pack_long(Stream& x, long d);
@@ -133,6 +151,10 @@ inline void pack(Stream& s, const T& v)
template <typename Stream> \
inline void packer<Stream>::_pack ## name
+#define msgpack_pack_inline_func_fixint(name) \
+ template <typename Stream> \
+ inline void packer<Stream>::_pack_fix ## name
+
#define msgpack_pack_user Stream&
#define msgpack_pack_append_buffer append_buffer
@@ -149,6 +171,7 @@ packer<Stream>::packer(Stream& s) : m_stream(s) { }
template <typename Stream>
packer<Stream>::~packer() { }
+
template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_uint8(uint8_t d)
{ _pack_uint8(m_stream, d); return *this; }
@@ -183,6 +206,39 @@ inline packer<Stream>& packer<Stream>::pack_int64(int64_t d)
template <typename Stream>
+inline packer<Stream>& packer<Stream>::pack_fix_uint8(uint8_t d)
+{ _pack_fix_uint8(m_stream, d); return *this; }
+
+template <typename Stream>
+inline packer<Stream>& packer<Stream>::pack_fix_uint16(uint16_t d)
+{ _pack_fix_uint16(m_stream, d); return *this; }
+
+template <typename Stream>
+inline packer<Stream>& packer<Stream>::pack_fix_uint32(uint32_t d)
+{ _pack_fix_uint32(m_stream, d); return *this; }
+
+template <typename Stream>
+inline packer<Stream>& packer<Stream>::pack_fix_uint64(uint64_t d)
+{ _pack_fix_uint64(m_stream, d); return *this; }
+
+template <typename Stream>
+inline packer<Stream>& packer<Stream>::pack_fix_int8(int8_t d)
+{ _pack_fix_int8(m_stream, d); return *this; }
+
+template <typename Stream>
+inline packer<Stream>& packer<Stream>::pack_fix_int16(int16_t d)
+{ _pack_fix_int16(m_stream, d); return *this; }
+
+template <typename Stream>
+inline packer<Stream>& packer<Stream>::pack_fix_int32(int32_t d)
+{ _pack_fix_int32(m_stream, d); return *this; }
+
+template <typename Stream>
+inline packer<Stream>& packer<Stream>::pack_fix_int64(int64_t d)
+{ _pack_fix_int64(m_stream, d); return *this;}
+
+
+template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_short(short d)
{ _pack_short(m_stream, d); return *this; }
diff --git a/cpp/src/msgpack/type.hpp b/cpp/src/msgpack/type.hpp
index a55c68e..bca69bf 100644
--- a/cpp/src/msgpack/type.hpp
+++ b/cpp/src/msgpack/type.hpp
@@ -1,8 +1,9 @@
#include "type/bool.hpp"
+#include "type/deque.hpp"
+#include "type/fixint.hpp"
#include "type/float.hpp"
#include "type/int.hpp"
#include "type/list.hpp"
-#include "type/deque.hpp"
#include "type/map.hpp"
#include "type/nil.hpp"
#include "type/pair.hpp"
diff --git a/cpp/src/msgpack/type/fixint.hpp b/cpp/src/msgpack/type/fixint.hpp
new file mode 100644
index 0000000..da58415
--- /dev/null
+++ b/cpp/src/msgpack/type/fixint.hpp
@@ -0,0 +1,89 @@
+//
+// MessagePack for C++ static resolution routine
+//
+// Copyright (C) 2020 FURUHASHI Sadayuki
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#ifndef MSGPACK_TYPE_FIXINT_HPP__
+#define MSGPACK_TYPE_FIXINT_HPP__
+
+#include "msgpack/object.hpp"
+
+namespace msgpack {
+
+namespace type {
+
+
+template <typename T>
+struct fix_int {
+ fix_int() : value(0) { }
+ fix_int(T value) : value(value) { }
+ operator T() const { return value; }
+ T get() const { return value; }
+private:
+ const T value;
+};
+
+
+typedef fix_int<uint8_t> fix_uint8;
+typedef fix_int<uint16_t> fix_uint16;
+typedef fix_int<uint32_t> fix_uint32;
+typedef fix_int<uint64_t> fix_uint64;
+
+typedef fix_int<int8_t> fix_int8;
+typedef fix_int<int16_t> fix_int16;
+typedef fix_int<int32_t> fix_int32;
+typedef fix_int<int64_t> fix_int64;
+
+
+} // namespace type
+
+
+template <typename Stream>
+inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int8& v)
+ { o.pack_fix_int8(v); return o; }
+
+template <typename Stream>
+inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int16& v)
+ { o.pack_fix_int16(v); return o; }
+
+template <typename Stream>
+inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int32& v)
+ { o.pack_fix_int32(v); return o; }
+
+template <typename Stream>
+inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int64& v)
+ { o.pack_fix_int64(v); return o; }
+
+template <typename Stream>
+inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint8& v)
+ { o.pack_fix_uint8(v); return o; }
+
+template <typename Stream>
+inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint16& v)
+ { o.pack_fix_uint16(v); return o; }
+
+template <typename Stream>
+inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint32& v)
+ { o.pack_fix_uint32(v); return o; }
+
+template <typename Stream>
+inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint64& v)
+ { o.pack_fix_uint64(v); return o; }
+
+
+} // namespace msgpack
+
+#endif /* msgpack/type/fixint.hpp */
+