From b41215fa43a9a19f03712a94a332e2c565b94ce5 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 8 Feb 2012 18:58:52 +0300 Subject: [PATCH] Add vector serialization functions. --- coding/read_write_utils.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/coding/read_write_utils.hpp b/coding/read_write_utils.hpp index d1aa716b0e..e818809da3 100644 --- a/coding/read_write_utils.hpp +++ b/coding/read_write_utils.hpp @@ -84,4 +84,29 @@ namespace rw { impl::ReadCont(src, v); } + + template + void ReadRaw(TSource & src, TCont & v) + { + STATIC_ASSERT(sizeof(typename TCont::value_type) == 1); + + uint32_t const count = ReadVarUint(src); + if (count > 0) + { + v.resize(count); + src.Read(&v[0], count); + } + } + + template + void WriteRaw(TSink & sink, TCont const & v) + { + STATIC_ASSERT(sizeof(typename TCont::value_type) == 1); + + uint32_t const count = static_cast(v.size()); + WriteVarUint(sink, count); + + if (count > 0) + sink.Write(&v[0], count); + } }