mirror of
https://github.com/fraillt/bitsery.git
synced 2026-09-26 03:56:06 +00:00
added -growable- function
This commit is contained in:
@@ -24,8 +24,8 @@
|
||||
#ifndef BITSERY_BITSERY_H
|
||||
#define BITSERY_BITSERY_H
|
||||
|
||||
#define BITSERY_MAJOR_VERSION 2
|
||||
#define BITSERY_MINOR_VERSION 1
|
||||
#define BITSERY_MAJOR_VERSION 3
|
||||
#define BITSERY_MINOR_VERSION 0
|
||||
#define BITSERY_PATCH_VERSION 0
|
||||
|
||||
#define BITSERY_QUOTE_MACRO(name) #name
|
||||
|
||||
@@ -27,18 +27,23 @@
|
||||
|
||||
#include "common.h"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
namespace bitsery {
|
||||
|
||||
template<typename Config>
|
||||
struct BasicBufferReader {
|
||||
|
||||
using BufferType = typename Config::BufferType;
|
||||
using ValueType = typename BufferType::value_type;
|
||||
using IteratorType = typename BufferType::iterator;
|
||||
using BufferIteratorType = typename BufferType::iterator;
|
||||
using ScratchType = typename details::SCRATCH_TYPE<ValueType>::type;
|
||||
|
||||
BasicBufferReader(IteratorType begin, IteratorType end)
|
||||
:_pos{begin}, _end{end} {
|
||||
BasicBufferReader(ValueType* begin, ValueType* end)
|
||||
:_pos{begin},
|
||||
_end{end},
|
||||
_session{*this, _pos, _end}
|
||||
{
|
||||
static_assert(std::is_unsigned<ValueType>(), "Config::BufferValueType must be unsigned");
|
||||
static_assert(std::is_unsigned<ScratchType>(), "Config::BufferScrathType must be unsigned");
|
||||
static_assert(sizeof(ValueType) * 2 == sizeof(ScratchType),
|
||||
@@ -46,8 +51,13 @@ namespace bitsery {
|
||||
static_assert(sizeof(ValueType) == 1, "currently only supported BufferValueType is 1 byte");
|
||||
}
|
||||
|
||||
BasicBufferReader(BufferRange<IteratorType> range)
|
||||
:BasicBufferReader(range.begin(), range.end()) {}
|
||||
BasicBufferReader(BufferRange<BufferIteratorType> range)
|
||||
:BasicBufferReader(std::addressof(*range.begin()), std::addressof(*range.end())) {
|
||||
static_assert(std::is_same<
|
||||
typename std::iterator_traits<BufferIteratorType>::iterator_category,
|
||||
std::random_access_iterator_tag>::value,
|
||||
"BufferReader only accepts random access iterators");
|
||||
}
|
||||
|
||||
BasicBufferReader(const BasicBufferReader &) = delete;
|
||||
|
||||
@@ -61,82 +71,115 @@ namespace bitsery {
|
||||
|
||||
|
||||
template<size_t SIZE, typename T>
|
||||
bool readBytes(T &v) {
|
||||
void readBytes(T &v) {
|
||||
static_assert(std::is_integral<T>(), "");
|
||||
static_assert(sizeof(T) == SIZE, "");
|
||||
using UT = typename std::make_unsigned<T>::type;
|
||||
return !m_scratch
|
||||
? directRead(&v, 1)
|
||||
: readBits(reinterpret_cast<UT &>(v), details::BITS_SIZE<T>);
|
||||
if (!m_scratchBits)
|
||||
directRead(&v, 1);
|
||||
else
|
||||
readBits(reinterpret_cast<UT &>(v), details::BITS_SIZE<T>);
|
||||
}
|
||||
|
||||
template<size_t SIZE, typename T>
|
||||
bool readBuffer(T *buf, size_t count) {
|
||||
void readBuffer(T *buf, size_t count) {
|
||||
static_assert(std::is_integral<T>(), "");
|
||||
static_assert(sizeof(T) == SIZE, "");
|
||||
|
||||
if (!m_scratchBits)
|
||||
return directRead(buf, count);
|
||||
|
||||
using UT = typename std::make_unsigned<T>::type;
|
||||
//todo improve implementation
|
||||
const auto end = buf + count;
|
||||
for (auto it = buf; it != end; ++it) {
|
||||
if (!readBits(reinterpret_cast<UT &>(*it), details::BITS_SIZE<T>))
|
||||
return false;
|
||||
if (!m_scratchBits) {
|
||||
directRead(buf, count);
|
||||
} else {
|
||||
using UT = typename std::make_unsigned<T>::type;
|
||||
//todo improve implementation
|
||||
const auto end = buf + count;
|
||||
for (auto it = buf; it != end; ++it)
|
||||
readBits(reinterpret_cast<UT &>(*it), details::BITS_SIZE<T>);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
bool readBits(T &v, size_t bitsCount) {
|
||||
void readBits(T &v, size_t bitsCount) {
|
||||
static_assert(std::is_integral<T>() && std::is_unsigned<T>(), "");
|
||||
|
||||
const auto bytesRequired = bitsCount > m_scratchBits
|
||||
? ((bitsCount - 1 - m_scratchBits) >> 3) + 1u
|
||||
: 0u;
|
||||
if (static_cast<size_t>(std::distance(_pos, _end)) < bytesRequired)
|
||||
return false;
|
||||
readBitsInternal(v, bitsCount);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool align() {
|
||||
void align() {
|
||||
if (m_scratchBits) {
|
||||
ScratchType tmp{};
|
||||
readBitsInternal(tmp, m_scratchBits);
|
||||
return tmp == 0;
|
||||
if (tmp)
|
||||
setError(BufferReaderError::INVALID_BUFFER_DATA);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isCompleted() const {
|
||||
return _pos == _end;
|
||||
bool isCompletedSuccessfully() const {
|
||||
return _pos == _end && !_session.hasActiveSessions();
|
||||
}
|
||||
|
||||
BufferReaderError getError() const {
|
||||
auto res = std::distance(_end, _pos);
|
||||
if (res > 0) {
|
||||
auto err = static_cast<BufferReaderError>(res);
|
||||
if (_session.hasActiveSessions() && err == BufferReaderError::BUFFER_OVERFLOW)
|
||||
return BufferReaderError::NO_ERROR;
|
||||
return err;
|
||||
}
|
||||
return BufferReaderError::NO_ERROR;
|
||||
}
|
||||
|
||||
void setError(BufferReaderError error) {
|
||||
_end = _pos;
|
||||
//to avoid creating temporary for error state, mark an error by passing _pos after the _end
|
||||
std::advance(_pos, static_cast<size_t>(error));
|
||||
}
|
||||
|
||||
void beginSession() {
|
||||
align();
|
||||
if (getError() != BufferReaderError::INVALID_BUFFER_DATA) {
|
||||
_session.begin();
|
||||
}
|
||||
}
|
||||
|
||||
void endSession() {
|
||||
align();
|
||||
if (getError() != BufferReaderError::INVALID_BUFFER_DATA) {
|
||||
_session.end();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
IteratorType _pos;
|
||||
IteratorType _end;
|
||||
ValueType* _pos;
|
||||
ValueType* _end;
|
||||
details::BufferSessionsReader<BasicBufferReader<Config>, ValueType*> _session;
|
||||
ScratchType m_scratch{};
|
||||
size_t m_scratchBits{}; ///< Number of bits currently in the scratch buffer. If the user wants to read more bits than this, we have to go fetch another dword from memory.
|
||||
|
||||
template<typename T>
|
||||
bool directRead(T *v, size_t count) {
|
||||
void directRead(T *v, size_t count) {
|
||||
static_assert(!std::is_const<T>::value, "");
|
||||
const auto bytesCount = sizeof(T) * count;
|
||||
if (static_cast<size_t>(std::distance(_pos, _end)) < bytesCount)
|
||||
return false;
|
||||
//read from buffer, to data ptr,
|
||||
std::copy_n(_pos, bytesCount, reinterpret_cast<ValueType *>(v));
|
||||
std::advance(_pos, bytesCount);
|
||||
//swap each byte if nessesarry
|
||||
_swapDataBits(v, count, std::integral_constant<bool,
|
||||
Config::NetworkEndianness != details::getSystemEndianness()>{});
|
||||
return true;
|
||||
|
||||
if (std::distance(_pos, _end) >= static_cast<typename BufferType::difference_type>(bytesCount)) {
|
||||
|
||||
std::memcpy(reinterpret_cast<ValueType *>(v), _pos, bytesCount);
|
||||
_pos += bytesCount;
|
||||
|
||||
//swap each byte if nessesarry
|
||||
_swapDataBits(v, count, std::integral_constant<bool,
|
||||
Config::NetworkEndianness != details::getSystemEndianness()>{});
|
||||
} else {
|
||||
//set everything to zeros
|
||||
std::memset(v, 0, bytesCount);
|
||||
|
||||
if (getError() == BufferReaderError::NO_ERROR)
|
||||
setError(BufferReaderError::BUFFER_OVERFLOW);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void _swapDataBits(T *v, size_t count, std::true_type) {
|
||||
std::for_each(v, std::next(v, count), [this](T &v) { v = details::swap(v); });
|
||||
std::for_each(v, std::next(v, count), [this](T &x) { x = details::swap(x); });
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -166,9 +209,6 @@ namespace bitsery {
|
||||
v = res;
|
||||
}
|
||||
|
||||
ScratchType m_scratch{};
|
||||
size_t m_scratchBits{}; ///< Number of bits currently in the scratch buffer. If the user wants to read more bits than this, we have to go fetch another dword from memory.
|
||||
|
||||
};
|
||||
//helper type
|
||||
using BufferReader = BasicBufferReader<DefaultConfig>;
|
||||
|
||||
@@ -55,11 +55,31 @@ namespace bitsery {
|
||||
}
|
||||
|
||||
void align() {
|
||||
_bitsCount += 8 - (_bitsCount % 8);
|
||||
auto _scratch = (_bitsCount % 8);
|
||||
_bitsCount += (8 - _scratch) % 8;
|
||||
}
|
||||
|
||||
void flush() {
|
||||
_bitsCount += (8 - (_bitsCount % 8)) % 8;
|
||||
align();
|
||||
//flush sessions count
|
||||
if (_sessionsBytesCount > 0) {
|
||||
auto sessionsDataSizeBytesCount = (_sessionsBytesCount < 0x8000u ? 2 : 4);
|
||||
_bitsCount += (_sessionsBytesCount + sessionsDataSizeBytesCount) * 8;
|
||||
_sessionsBytesCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void beginSession() {
|
||||
|
||||
}
|
||||
|
||||
void endSession() {
|
||||
auto endPos = getWrittenBytesCount();
|
||||
details::writeSize(*this, endPos);
|
||||
auto sessionEndBytesCount = getWrittenBytesCount() - endPos;
|
||||
//remove written bytes, because we'll write them at the end
|
||||
_bitsCount -= sessionEndBytesCount * 8;
|
||||
_sessionsBytesCount += sessionEndBytesCount;
|
||||
}
|
||||
|
||||
//get size in bytes
|
||||
@@ -69,7 +89,7 @@ namespace bitsery {
|
||||
|
||||
private:
|
||||
size_t _bitsCount{};
|
||||
|
||||
size_t _sessionsBytesCount{};
|
||||
};
|
||||
|
||||
template<typename Config>
|
||||
@@ -79,7 +99,9 @@ namespace bitsery {
|
||||
using ScratchType = typename details::SCRATCH_TYPE<ValueType>::type;
|
||||
using BufferContext = details::WriteBufferContext<BufferType, Config::FixedBufferSize>;
|
||||
|
||||
explicit BasicBufferWriter(BufferType &buffer) : _bufferContext{buffer} {
|
||||
explicit BasicBufferWriter(BufferType &buffer)
|
||||
: _bufferContext{buffer}
|
||||
{
|
||||
static_assert(std::is_unsigned<ValueType>(), "Config::BufferType::value_type must be unsigned");
|
||||
static_assert(std::is_unsigned<ScratchType>(), "Config::BufferScrathType must be unsigned");
|
||||
static_assert(sizeof(ValueType) * 2 == sizeof(ScratchType),
|
||||
@@ -134,23 +156,29 @@ namespace bitsery {
|
||||
}
|
||||
|
||||
void align() {
|
||||
if (_scratchBits)
|
||||
writeBitsInternal(ValueType{}, details::BITS_SIZE<ValueType> - _scratchBits);
|
||||
writeBitsInternal(ValueType{}, (details::BITS_SIZE<ValueType> - _scratchBits) % 8);
|
||||
}
|
||||
|
||||
void flush() {
|
||||
if (_scratchBits) {
|
||||
auto tmp = static_cast<ValueType>( _scratch & _MASK );
|
||||
directWrite(&tmp, 1);
|
||||
_scratch >>= _scratchBits;
|
||||
_scratchBits -= _scratchBits;
|
||||
}
|
||||
align();
|
||||
_session.flushSessions(*this);
|
||||
}
|
||||
|
||||
BufferRange<typename BufferType::iterator> getWrittenRange() const {
|
||||
return _bufferContext.getWrittenRange();
|
||||
}
|
||||
|
||||
void beginSession() {
|
||||
align();
|
||||
_session.begin();
|
||||
}
|
||||
|
||||
void endSession() {
|
||||
align();
|
||||
auto range = _bufferContext.getWrittenRange();
|
||||
_session.end(static_cast<size_t>(std::distance(range.begin(), range.end())));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template<typename T>
|
||||
@@ -212,6 +240,7 @@ namespace bitsery {
|
||||
BufferContext _bufferContext;
|
||||
ScratchType _scratch{};
|
||||
size_t _scratchBits{};
|
||||
details::BufferSessionsWriter _session{};
|
||||
};
|
||||
|
||||
//helper type
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
#include "details/buffer_common.h"
|
||||
#include <vector>
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace bitsery {
|
||||
|
||||
struct DefaultConfig {
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
//MIT License
|
||||
//
|
||||
//Copyright (c) 2017 Mindaugas Vinkelis
|
||||
//
|
||||
//Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
//of this software and associated documentation files (the "Software"), to deal
|
||||
//in the Software without restriction, including without limitation the rights
|
||||
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
//copies of the Software, and to permit persons to whom the Software is
|
||||
//furnished to do so, subject to the following conditions:
|
||||
//
|
||||
//The above copyright notice and this permission notice shall be included in all
|
||||
//copies or substantial portions of the Software.
|
||||
//
|
||||
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
//SOFTWARE.
|
||||
|
||||
|
||||
|
||||
#ifndef BITSERY_DELTADESERIALIZER_H
|
||||
#define BITSERY_DELTADESERIALIZER_H
|
||||
|
||||
#include <array>
|
||||
#include <stack>
|
||||
#include <algorithm>
|
||||
#include "deserializer.h"
|
||||
|
||||
namespace bitsery {
|
||||
|
||||
template<typename Reader, typename TObj>
|
||||
class DeltaDeserializer {
|
||||
public:
|
||||
DeltaDeserializer(Reader &r, const TObj &oldObj, const TObj &newObj)
|
||||
: _deserializer{r},
|
||||
_reader{r},
|
||||
_oldObj{oldObj},
|
||||
_newObj{newObj},
|
||||
_objMemPos(std::deque<details::ObjectMemoryPosition>(1, details::ObjectMemoryPosition{oldObj, newObj})),
|
||||
_isNewElement{false} {
|
||||
};
|
||||
|
||||
template<size_t SIZE = 0, typename T, typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
|
||||
DeltaDeserializer &value(T &v) {
|
||||
if (getChangedState(v)) {
|
||||
constexpr size_t ValueSize = SIZE == 0 ? sizeof(T) : SIZE;
|
||||
_reader.template readBytes<ValueSize>(v);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
DeltaDeserializer &object(T &&obj) {
|
||||
if (getChangedState(obj))
|
||||
serialize(*this, std::forward<T>(obj));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<size_t VSIZE = 1, typename T>
|
||||
DeltaDeserializer &text(std::basic_string<T> &str, size_t maxSize) {
|
||||
if (getChangedState(str)) {
|
||||
_deserializer.template text<VSIZE>(str, maxSize);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<size_t VSIZE = 1, typename T, size_t N>
|
||||
DeltaDeserializer &text(T (&str)[N]) {
|
||||
if (getChangedState(str)) {
|
||||
_deserializer.template text<VSIZE>(str);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<typename T, size_t N, typename Fnc>
|
||||
DeltaDeserializer &array(std::array<T, N> &arr, Fnc &&fnc) {
|
||||
if (getChangedState(arr)) {
|
||||
if (!_isNewElement) {
|
||||
const auto old = *_objMemPos.top().getOldObjectField(arr);
|
||||
processContainer(std::begin(old), std::end(old), std::begin(arr), std::end(arr), fnc);
|
||||
} else {
|
||||
for (auto &v:arr)
|
||||
fnc(*this, v);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<typename T, size_t N, typename Fnc>
|
||||
DeltaDeserializer &array(T (&arr)[N], Fnc &&fnc) {
|
||||
if (getChangedState(arr)) {
|
||||
if (!_isNewElement) {
|
||||
const auto old = *_objMemPos.top().getOldObjectField(arr);
|
||||
T *tmp = arr;
|
||||
processContainer(old, old + N, tmp, tmp + N, fnc);
|
||||
} else {
|
||||
T *tmp = arr;
|
||||
for (auto i = 0u; i < N; ++i, ++tmp)
|
||||
fnc(*this, *tmp);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T, typename Fnc>
|
||||
DeltaDeserializer &container(T &obj, size_t maxSize, Fnc &&fnc) {
|
||||
if (getChangedState(obj)) {
|
||||
size_t newSize{};
|
||||
_reader.readBits(newSize, 32);
|
||||
if (!_isNewElement) {
|
||||
auto old = *_objMemPos.top().getOldObjectField(obj);
|
||||
if (old.size() != newSize)
|
||||
obj.resize(newSize);
|
||||
processContainer(std::begin(old), std::end(old), std::begin(obj), std::end(obj),
|
||||
std::forward<Fnc>(fnc));
|
||||
} else {
|
||||
obj.resize(newSize);
|
||||
for (auto &v:obj)
|
||||
fnc(*this, v);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
Deserializer <Reader> _deserializer;
|
||||
Reader &_reader;
|
||||
|
||||
const TObj &_oldObj;
|
||||
const TObj &_newObj;
|
||||
std::stack<details::ObjectMemoryPosition> _objMemPos;
|
||||
bool _isNewElement;
|
||||
|
||||
template<typename T>
|
||||
bool getChangedState(T &obj) {
|
||||
if (!_isNewElement) {
|
||||
if (!readChangedState()) {
|
||||
obj = *_objMemPos.top().getOldObjectField(obj);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
bool getChangedState(T (&arr)[N]) {
|
||||
if (!_isNewElement) {
|
||||
if (!readChangedState()) {
|
||||
auto old = *_objMemPos.top().getOldObjectField(arr);
|
||||
auto end = arr + N;
|
||||
auto pOld = old;
|
||||
for (auto p = arr; p != end; ++p, ++pOld)
|
||||
*p = *pOld;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename TConstIt, typename TIt, typename Fnc>
|
||||
bool processContainer(TConstIt oldBegin, TConstIt oldEnd, TIt begin, TIt end, Fnc &&fnc) {
|
||||
auto offset = readIndexOffset();
|
||||
auto p = begin;
|
||||
auto pOld = oldBegin;
|
||||
for (; p != end && pOld != oldEnd; ++p, ++pOld) {
|
||||
if (offset) {
|
||||
*p = *pOld;
|
||||
--offset;
|
||||
} else {
|
||||
_objMemPos.emplace(details::ObjectMemoryPosition{*pOld, *p});
|
||||
fnc(*this, *p);
|
||||
_objMemPos.pop();
|
||||
offset = readIndexOffset();
|
||||
}
|
||||
}
|
||||
if (offset != 0 && pOld != oldEnd)
|
||||
return false;
|
||||
_isNewElement = true;
|
||||
for (; p != end; ++p, --offset)
|
||||
fnc(*this, *p);
|
||||
_isNewElement = false;
|
||||
return offset == 0;
|
||||
|
||||
}
|
||||
|
||||
bool readChangedState() {
|
||||
unsigned char res{};
|
||||
_reader.readBits(res, 1);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
size_t readIndexOffset() {
|
||||
//special case, if items are updated sequentialy
|
||||
unsigned char tmp{};
|
||||
_reader.readBits(tmp, 1);
|
||||
if (tmp) {
|
||||
return 0u;
|
||||
} else {
|
||||
size_t res{};
|
||||
_reader.readBits(tmp, 1);
|
||||
if (tmp > 0)
|
||||
_reader.readBits(res, 4);
|
||||
else
|
||||
_reader.readBits(res, 32);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif //BITSERY_DELTADESERIALIZER_H
|
||||
@@ -1,220 +0,0 @@
|
||||
//MIT License
|
||||
//
|
||||
//Copyright (c) 2017 Mindaugas Vinkelis
|
||||
//
|
||||
//Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
//of this software and associated documentation files (the "Software"), to deal
|
||||
//in the Software without restriction, including without limitation the rights
|
||||
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
//copies of the Software, and to permit persons to whom the Software is
|
||||
//furnished to do so, subject to the following conditions:
|
||||
//
|
||||
//The above copyright notice and this permission notice shall be included in all
|
||||
//copies or substantial portions of the Software.
|
||||
//
|
||||
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
//SOFTWARE.
|
||||
|
||||
|
||||
|
||||
#ifndef BITSERY_DELTASERIALIZER_H
|
||||
#define BITSERY_DELTASERIALIZER_H
|
||||
|
||||
#include <array>
|
||||
#include <stack>
|
||||
#include <algorithm>
|
||||
#include "serializer.h"
|
||||
|
||||
namespace bitsery {
|
||||
|
||||
template<typename Writter, typename TObj>
|
||||
class DeltaSerializer {
|
||||
public:
|
||||
DeltaSerializer(Writter &w, const TObj &oldObj, const TObj &newObj)
|
||||
: _serializer{w},
|
||||
_writter{w},
|
||||
_oldObj{oldObj},
|
||||
_newObj{newObj},
|
||||
_objMemPos(std::deque<details::ObjectMemoryPosition>(1, details::ObjectMemoryPosition{oldObj, newObj})),
|
||||
_isNewElement{false} {
|
||||
|
||||
};
|
||||
|
||||
template<size_t SIZE = 0, typename T, typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
|
||||
DeltaSerializer &value(const T &v) {
|
||||
if (setChangedState(v)) {
|
||||
constexpr size_t ValueSize = SIZE == 0 ? sizeof(T) : SIZE;
|
||||
_writter.template writeBytes<ValueSize>(v);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
DeltaSerializer &object(T &&obj) {
|
||||
if (setChangedState(obj)) {
|
||||
serialize(*this, std::forward<T>(obj));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<size_t VSIZE = 1, typename T>
|
||||
DeltaSerializer &text(const std::basic_string<T> &str, size_t maxSize) {
|
||||
if (setChangedState(str)) {
|
||||
_serializer.template text<VSIZE>(str, maxSize);
|
||||
}
|
||||
return *this;
|
||||
|
||||
}
|
||||
|
||||
template<size_t VSIZE = 1, typename T, size_t N>
|
||||
DeltaSerializer &text(const T (&str)[N]) {
|
||||
if (setChangedState(str)) {
|
||||
_serializer.template text<VSIZE>(str);
|
||||
}
|
||||
return *this;
|
||||
|
||||
}
|
||||
|
||||
template<typename T, size_t N, typename Fnc>
|
||||
DeltaSerializer &array(const std::array<T, N> &arr, Fnc &&fnc) {
|
||||
if (setChangedState(arr)) {
|
||||
if (!_isNewElement) {
|
||||
const auto &old = *_objMemPos.top().getOldObjectField(arr);
|
||||
processContainer(std::begin(old), std::end(old), std::begin(arr), std::end(arr), fnc);
|
||||
} else {
|
||||
for (auto &v:arr)
|
||||
fnc(*this, v);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<typename T, size_t N, typename Fnc>
|
||||
DeltaSerializer &array(const T (&arr)[N], Fnc &&fnc) {
|
||||
if (setChangedState(arr)) {
|
||||
if (!_isNewElement) {
|
||||
auto old = *_objMemPos.top().getOldObjectField(arr);
|
||||
const T *tmp = arr;
|
||||
processContainer(old, old + N, tmp, tmp + N, fnc);
|
||||
} else {
|
||||
const T *tmp = arr;
|
||||
for (auto i = 0u; i < N; ++i, ++tmp)
|
||||
fnc(*this, *tmp);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T, typename Fnc>
|
||||
DeltaSerializer &container(T &&obj, size_t maxSize, Fnc &&fnc) {
|
||||
if (setChangedState(obj)) {
|
||||
_writter.writeBits(obj.size(), 32);
|
||||
if (!_isNewElement) {
|
||||
auto old = *_objMemPos.top().getOldObjectField(obj);
|
||||
processContainer(std::begin(old), std::end(old), std::begin(obj), std::end(obj),
|
||||
std::forward<Fnc>(fnc));
|
||||
} else {
|
||||
for (auto &v:obj)
|
||||
fnc(*this, v);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
Serializer <Writter> _serializer;
|
||||
Writter &_writter;
|
||||
const TObj &_oldObj;
|
||||
const TObj &_newObj;
|
||||
std::stack<details::ObjectMemoryPosition> _objMemPos;
|
||||
bool _isNewElement;
|
||||
|
||||
template<typename T>
|
||||
bool setChangedState(const T &obj) {
|
||||
if (!_isNewElement) {
|
||||
auto res = !_objMemPos.top().isFieldsEquals(obj);
|
||||
writeChangedState(res);
|
||||
return res;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
bool setChangedState(const T (&arr)[N]) {
|
||||
if (!_isNewElement) {
|
||||
auto old = *_objMemPos.top().getOldObjectField(arr);
|
||||
auto end = arr + N;
|
||||
bool changed{};
|
||||
for (auto p = arr, pOld = old; p != end; ++p, ++pOld) {
|
||||
if (!(*p == *pOld)) {
|
||||
changed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
writeChangedState(changed);
|
||||
return changed;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<typename T, typename Fnc>
|
||||
void processContainer(const T oldBegin, const T oldEnd, const T begin, const T end, Fnc &&fnc) {
|
||||
auto misMatch = std::mismatch(oldBegin, oldEnd, begin, end);
|
||||
auto lastChanged = begin;
|
||||
while (misMatch.first != oldEnd && misMatch.second != end) {
|
||||
writeIndexOffset(std::distance(lastChanged, misMatch.second));
|
||||
_objMemPos.emplace(details::ObjectMemoryPosition{*misMatch.first, *misMatch.second});
|
||||
fnc(*this, *misMatch.second);
|
||||
_objMemPos.pop();
|
||||
++misMatch.first;
|
||||
++misMatch.second;
|
||||
lastChanged = misMatch.second;
|
||||
misMatch = std::mismatch(misMatch.first, oldEnd, misMatch.second, end);
|
||||
}
|
||||
auto p = misMatch.second;
|
||||
//write items left
|
||||
writeIndexOffset(std::distance(lastChanged, end));
|
||||
//write old elements
|
||||
for (auto pOld = misMatch.first; p != end && pOld != oldEnd; ++p, ++pOld) {
|
||||
_objMemPos.emplace(details::ObjectMemoryPosition{*pOld, *p});
|
||||
fnc(*this, *p);
|
||||
_objMemPos.pop();
|
||||
}
|
||||
|
||||
//write new elements
|
||||
_isNewElement = true;
|
||||
for (; p != end; ++p)
|
||||
fnc(*this, *p);
|
||||
_isNewElement = false;
|
||||
}
|
||||
|
||||
void writeChangedState(bool state) {
|
||||
_writter.writeBits(state ? 1u : 0u, 1);
|
||||
}
|
||||
|
||||
void writeIndexOffset(const size_t offset) {
|
||||
//special case, if items are updated sequentialy
|
||||
if (offset == 0) {
|
||||
_writter.writeBits(1u, 1);
|
||||
} else {
|
||||
_writter.writeBits(0u, 1);
|
||||
auto smallOffset = offset < 16;
|
||||
_writter.writeBits(smallOffset ? 1u : 0u, 1);
|
||||
if (smallOffset)
|
||||
_writter.writeBits(offset, 4);
|
||||
else
|
||||
_writter.writeBits(offset, 32);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif //BITSERY_DELTASERIALIZER_H
|
||||
@@ -35,7 +35,15 @@ namespace bitsery {
|
||||
template<typename Reader>
|
||||
class Deserializer {
|
||||
public:
|
||||
Deserializer(Reader &r) : _reader{r}, _isValid{true} {};
|
||||
Deserializer(Reader &r, void* context = nullptr) : _reader{r}, _context{context} {};
|
||||
|
||||
/*
|
||||
* get serialization context.
|
||||
* this is optional, but might be required for some specific deserialization flows.
|
||||
*/
|
||||
void* getContext() {
|
||||
return _context;
|
||||
}
|
||||
|
||||
/*
|
||||
* object function
|
||||
@@ -43,10 +51,14 @@ namespace bitsery {
|
||||
|
||||
template<typename T>
|
||||
void object(T &&obj) {
|
||||
if (_isValid)
|
||||
details::SerializeFunction<Deserializer, T>::invoke(*this, std::forward<T>(obj));
|
||||
details::SerializeFunction<Deserializer, T>::invoke(*this, std::forward<T>(obj));
|
||||
}
|
||||
|
||||
template<typename T, typename Fnc>
|
||||
void object(T &&obj, Fnc &&fnc) {
|
||||
fnc(*this, std::forward<T>(obj));
|
||||
};
|
||||
|
||||
/*
|
||||
* value overloads
|
||||
*/
|
||||
@@ -54,53 +66,48 @@ namespace bitsery {
|
||||
template<size_t VSIZE, typename T, typename std::enable_if<std::is_floating_point<T>::value>::type * = nullptr>
|
||||
void value(T &v) {
|
||||
static_assert(std::numeric_limits<T>::is_iec559, "");
|
||||
if (_isValid)
|
||||
_isValid = _reader.template readBytes<VSIZE>(reinterpret_cast<details::SAME_SIZE_UNSIGNED<T> &>(v));
|
||||
_reader.template readBytes<VSIZE>(reinterpret_cast<details::SAME_SIZE_UNSIGNED<T> &>(v));
|
||||
}
|
||||
|
||||
template<size_t VSIZE, typename T, typename std::enable_if<std::is_enum<T>::value>::type * = nullptr>
|
||||
void value(T &v) {
|
||||
using UT = std::underlying_type_t<T>;
|
||||
if (_isValid)
|
||||
_isValid = _reader.template readBytes<VSIZE>(reinterpret_cast<UT &>(v));
|
||||
_reader.template readBytes<VSIZE>(reinterpret_cast<UT &>(v));
|
||||
}
|
||||
|
||||
template<size_t VSIZE, typename T, typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
|
||||
void value(T &v) {
|
||||
if (_isValid)
|
||||
_isValid = _reader.template readBytes<VSIZE>(v);
|
||||
_reader.template readBytes<VSIZE>(v);
|
||||
}
|
||||
|
||||
/*
|
||||
* custom function
|
||||
* growable function
|
||||
*/
|
||||
|
||||
template<typename T, typename Fnc>
|
||||
void custom(T &&obj, Fnc &&fnc) {
|
||||
if (_isValid)
|
||||
fnc(*this, std::forward<T>(obj));
|
||||
template <typename T, typename Fnc>
|
||||
void growable(T&& obj, Fnc&& fnc) {
|
||||
_reader.beginSession();
|
||||
fnc(*this, std::forward<T>(obj));
|
||||
_reader.endSession();
|
||||
};
|
||||
|
||||
/*
|
||||
* extension functions
|
||||
* extend functions
|
||||
*/
|
||||
|
||||
template<typename T, typename Ext, typename Fnc>
|
||||
void extension(T &obj, Ext &&ext, Fnc &&fnc) {
|
||||
if (_isValid)
|
||||
ext.deserialize(obj, *this, std::forward<Fnc>(fnc));
|
||||
void extend(T &obj, Ext &&ext, Fnc &&fnc) {
|
||||
ext.deserialize(*this, _reader, obj, std::forward<Fnc>(fnc));
|
||||
};
|
||||
|
||||
template<size_t VSIZE, typename T, typename Ext>
|
||||
void extension(T &obj, Ext &&ext) {
|
||||
if (_isValid)
|
||||
ext.deserialize(obj, *this, [](auto &s, auto &v) { s.template value<VSIZE>(v); });
|
||||
void extend(T &obj, Ext &&ext) {
|
||||
ext.deserialize(*this, _reader, obj, [](auto &s, auto &v) { s.template value<VSIZE>(v); });
|
||||
};
|
||||
|
||||
template<typename T, typename Ext>
|
||||
void extension(T &obj, Ext &&ext) {
|
||||
if (_isValid)
|
||||
ext.deserialize(obj, *this, [](auto &s, auto &v) { s.object(v); });
|
||||
void extend(T &obj, Ext &&ext) {
|
||||
ext.deserialize(*this, _reader, obj, [](auto &s, auto &v) { s.object(v); });
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -108,21 +115,17 @@ namespace bitsery {
|
||||
*/
|
||||
|
||||
void boolBit(bool &v) {
|
||||
if (_isValid) {
|
||||
unsigned char tmp;
|
||||
_isValid = _reader.readBits(tmp, 1);
|
||||
v = tmp == 1;
|
||||
}
|
||||
uint8_t tmp{};
|
||||
_reader.readBits(tmp, 1);
|
||||
v = tmp == 1;
|
||||
}
|
||||
|
||||
void boolByte(bool &v) {
|
||||
if (_isValid) {
|
||||
unsigned char tmp;
|
||||
_isValid = _reader.template readBytes<1>(tmp);
|
||||
if (_isValid)
|
||||
_isValid = tmp < 2;
|
||||
v = tmp == 1;
|
||||
}
|
||||
unsigned char tmp;
|
||||
_reader.template readBytes<1>(tmp);
|
||||
if (tmp > 1)
|
||||
_reader.setError(BufferReaderError::INVALID_BUFFER_DATA);
|
||||
v = tmp == 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -131,51 +134,45 @@ namespace bitsery {
|
||||
|
||||
template<typename T>
|
||||
void range(T &v, const RangeSpec<T> &range) {
|
||||
if (_isValid) {
|
||||
_isValid = _reader.readBits(reinterpret_cast<details::SAME_SIZE_UNSIGNED<T> &>(v), range.bitsRequired);
|
||||
details::setRangeValue(v, range);
|
||||
if (_isValid)
|
||||
_isValid = details::isRangeValid(v, range);
|
||||
_reader.readBits(reinterpret_cast<details::SAME_SIZE_UNSIGNED<T> &>(v), range.bitsRequired);
|
||||
details::setRangeValue(v, range);
|
||||
if (!details::isRangeValid(v, range)) {
|
||||
_reader.setError(BufferReaderError::INVALID_BUFFER_DATA);
|
||||
v = range.min;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* substitution overloads
|
||||
* entropy overloads
|
||||
*/
|
||||
template<typename T, size_t N, typename Fnc>
|
||||
void substitution(T &v, const std::array<T, N> &expectedValues, Fnc &&fnc) {
|
||||
void entropy(T &v, const T (&expectedValues)[N], Fnc &&fnc) {
|
||||
size_t index;
|
||||
range(index, {{}, N + 1});
|
||||
if (_isValid) {
|
||||
if (index)
|
||||
v = expectedValues[index - 1];
|
||||
else
|
||||
fnc(*this, v);
|
||||
}
|
||||
if (index)
|
||||
v = expectedValues[index - 1];
|
||||
else
|
||||
fnc(*this, v);
|
||||
};
|
||||
|
||||
template<size_t VSIZE, typename T, size_t N>
|
||||
void substitution(T &v, const std::array<T, N> &expectedValues) {
|
||||
void entropy(T &v, const T (&expectedValues)[N]) {
|
||||
size_t index;
|
||||
range(index, {{}, N + 1});
|
||||
if (_isValid) {
|
||||
if (index)
|
||||
v = expectedValues[index - 1];
|
||||
else
|
||||
value<VSIZE>(v);
|
||||
}
|
||||
if (index)
|
||||
v = expectedValues[index - 1];
|
||||
else
|
||||
value<VSIZE>(v);
|
||||
};
|
||||
|
||||
template<typename T, size_t N>
|
||||
void substitution(T &v, const std::array<T, N> &expectedValues) {
|
||||
void entropy(T &v, const T (&expectedValues)[N]) {
|
||||
size_t index;
|
||||
range(index, {{}, N + 1});
|
||||
if (_isValid) {
|
||||
if (index)
|
||||
v = expectedValues[index - 1];
|
||||
else
|
||||
object(v);
|
||||
}
|
||||
if (index)
|
||||
v = expectedValues[index - 1];
|
||||
else
|
||||
object(v);
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -183,96 +180,96 @@ namespace bitsery {
|
||||
*/
|
||||
|
||||
template<size_t VSIZE, typename T>
|
||||
void text(std::basic_string<T> &str, size_t maxSize) {
|
||||
void text(T &str, size_t maxSize) {
|
||||
size_t size;
|
||||
readSize(size, maxSize);
|
||||
if (_isValid) {
|
||||
str.resize(size);
|
||||
procContainer<VSIZE>(std::begin(str), std::end(str), std::true_type{});
|
||||
}
|
||||
str.resize(size);
|
||||
procContainer<VSIZE>(std::begin(str), std::end(str), std::true_type{});
|
||||
}
|
||||
|
||||
template<size_t VSIZE, typename T, size_t N>
|
||||
void text(T (&str)[N]) {
|
||||
size_t size;
|
||||
readSize(size, N - 1);
|
||||
if (_isValid) {
|
||||
auto first = std::begin(str);
|
||||
procContainer<VSIZE>(first, std::next(first, size), std::true_type{});
|
||||
//null-terminated string
|
||||
str[size] = {};
|
||||
}
|
||||
auto first = std::begin(str);
|
||||
procContainer<VSIZE>(first, std::next(first, size), std::true_type{});
|
||||
//null-terminated string
|
||||
str[size] = {};
|
||||
}
|
||||
|
||||
/*
|
||||
* container overloads
|
||||
*/
|
||||
|
||||
//dynamic size containers
|
||||
|
||||
template<typename T, typename Fnc>
|
||||
void container(T &&obj, size_t maxSize, Fnc &&fnc) {
|
||||
static_assert(details::IsResizable<T>::value,
|
||||
"use container(const T&) overload without `maxSize` for static containers");
|
||||
decltype(obj.size()) size{};
|
||||
readSize(size, maxSize);
|
||||
if (_isValid) {
|
||||
obj.resize(size);
|
||||
procContainer(std::begin(obj), std::end(obj), std::forward<Fnc>(fnc));
|
||||
}
|
||||
obj.resize(size);
|
||||
procContainer(std::begin(obj), std::end(obj), std::forward<Fnc>(fnc));
|
||||
}
|
||||
|
||||
template<size_t VSIZE, typename T>
|
||||
void container(T &obj, size_t maxSize) {
|
||||
static_assert(details::IsResizable<T>::value,
|
||||
"use container(const T&) overload without `maxSize` for static containers");
|
||||
decltype(obj.size()) size{};
|
||||
readSize(size, maxSize);
|
||||
if (_isValid) {
|
||||
obj.resize(size);
|
||||
procContainer<VSIZE>(std::begin(obj), std::end(obj), std::false_type{});
|
||||
}
|
||||
obj.resize(size);
|
||||
procContainer<VSIZE>(std::begin(obj), std::end(obj), std::false_type{});
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void container(T &obj, size_t maxSize) {
|
||||
static_assert(details::IsResizable<T>::value,
|
||||
"use container(const T&) overload without `maxSize` for static containers");
|
||||
decltype(obj.size()) size{};
|
||||
readSize(size, maxSize);
|
||||
if (_isValid) {
|
||||
obj.resize(size);
|
||||
procContainer(std::begin(obj), std::end(obj));
|
||||
}
|
||||
obj.resize(size);
|
||||
procContainer(std::begin(obj), std::end(obj));
|
||||
}
|
||||
//fixed size containers
|
||||
|
||||
template<typename T, typename Fnc, typename std::enable_if<!std::is_integral<Fnc>::value>::type * = nullptr>
|
||||
void container(T &&obj, Fnc &&fnc) {
|
||||
static_assert(!details::IsResizable<T>::value,
|
||||
"use container(T&, size_t, Fnc) overload with `maxSize` for dynamic containers");
|
||||
procContainer(std::begin(obj), std::end(obj), std::forward<Fnc>(fnc));
|
||||
}
|
||||
|
||||
/*
|
||||
* array overloads (fixed size array (std::array, and c-style array))
|
||||
*/
|
||||
|
||||
//std::array overloads
|
||||
|
||||
template<typename T, size_t N, typename Fnc>
|
||||
void array(std::array<T, N> &arr, Fnc &&fnc) {
|
||||
procContainer(std::begin(arr), std::end(arr), std::forward<Fnc>(fnc));
|
||||
template<size_t VSIZE, typename T>
|
||||
void container(T &obj) {
|
||||
static_assert(!details::IsResizable<T>::value,
|
||||
"use container(T&, size_t) overload with `maxSize` for dynamic containers");
|
||||
static_assert(VSIZE > 0);
|
||||
procContainer<VSIZE>(std::begin(obj), std::end(obj), std::false_type{});
|
||||
}
|
||||
|
||||
template<size_t VSIZE, typename T, size_t N>
|
||||
void array(std::array<T, N> &arr) {
|
||||
procContainer<VSIZE>(std::begin(arr), std::end(arr), std::true_type{});
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array(std::array<T, N> &arr) {
|
||||
procContainer(std::begin(arr), std::end(arr));
|
||||
template<typename T>
|
||||
void container(T &obj) {
|
||||
static_assert(!details::IsResizable<T>::value,
|
||||
"use container(T&, size_t) overload with `maxSize` for dynamic containers");
|
||||
procContainer(std::begin(obj), std::end(obj));
|
||||
}
|
||||
|
||||
//c-style array overloads
|
||||
|
||||
template<typename T, size_t N, typename Fnc>
|
||||
void array(T (&arr)[N], Fnc &&fnc) {
|
||||
void container(T (&arr)[N], Fnc &&fnc) {
|
||||
procContainer(std::begin(arr), std::end(arr), std::forward<Fnc>(fnc));
|
||||
}
|
||||
|
||||
template<size_t VSIZE, typename T, size_t N>
|
||||
void array(T (&arr)[N]) {
|
||||
void container(T (&arr)[N]) {
|
||||
procContainer<VSIZE>(std::begin(arr), std::end(arr), std::true_type{});
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array(T (&arr)[N]) {
|
||||
void container(T (&arr)[N]) {
|
||||
procContainer(std::begin(arr), std::end(arr));
|
||||
}
|
||||
|
||||
@@ -280,128 +277,108 @@ namespace bitsery {
|
||||
_reader.align();
|
||||
}
|
||||
|
||||
bool isValid() const {
|
||||
return _isValid;
|
||||
}
|
||||
|
||||
//overloads for functions with explicit type size
|
||||
|
||||
template<typename T>
|
||||
void value1(T &&v) { value<1>(std::forward<T>(v)); }
|
||||
void value1b(T &&v) { value<1>(std::forward<T>(v)); }
|
||||
|
||||
template<typename T>
|
||||
void value2(T &&v) { value<2>(std::forward<T>(v)); }
|
||||
void value2b(T &&v) { value<2>(std::forward<T>(v)); }
|
||||
|
||||
template<typename T>
|
||||
void value4(T &&v) { value<4>(std::forward<T>(v)); }
|
||||
void value4b(T &&v) { value<4>(std::forward<T>(v)); }
|
||||
|
||||
template<typename T>
|
||||
void value8(T &&v) { value<8>(std::forward<T>(v)); }
|
||||
void value8b(T &&v) { value<8>(std::forward<T>(v)); }
|
||||
|
||||
template<typename T, typename Ext>
|
||||
void extension1(T &v, Ext &&ext) { extension<1>(v, std::forward<Ext>(ext)); };
|
||||
void extend1b(T &v, Ext &&ext) { extend<1>(v, std::forward<Ext>(ext)); };
|
||||
|
||||
template<typename T, typename Ext>
|
||||
void extension2(T &v, Ext &&ext) { extension<2>(v, std::forward<Ext>(ext)); };
|
||||
void extend2b(T &v, Ext &&ext) { extend<2>(v, std::forward<Ext>(ext)); };
|
||||
|
||||
template<typename T, typename Ext>
|
||||
void extension4(T &v, Ext &&ext) { extension<4>(v, std::forward<Ext>(ext)); };
|
||||
void extend4b(T &v, Ext &&ext) { extend<4>(v, std::forward<Ext>(ext)); };
|
||||
|
||||
template<typename T, typename Ext>
|
||||
void extension8(T &v, Ext &&ext) { extension<8>(v, std::forward<Ext>(ext)); };
|
||||
void extend8b(T &v, Ext &&ext) { extend<8>(v, std::forward<Ext>(ext)); };
|
||||
|
||||
template<typename T, size_t N>
|
||||
void substitution1(T &v, const std::array<T, N> &expectedValues) { substitution<1>(v, expectedValues); };
|
||||
void entropy1b(T &v, const T (&expectedValues)[N]) { entropy<1>(v, expectedValues); };
|
||||
|
||||
template<typename T, size_t N>
|
||||
void substitution2(T &v, const std::array<T, N> &expectedValues) { substitution<2>(v, expectedValues); };
|
||||
void entropy2b(T &v, const T (&expectedValues)[N]) { entropy<2>(v, expectedValues); };
|
||||
|
||||
template<typename T, size_t N>
|
||||
void substitution4(T &v, const std::array<T, N> &expectedValues) { substitution<4>(v, expectedValues); };
|
||||
void entropy4b(T &v, const T (&expectedValues)[N]) { entropy<4>(v, expectedValues); };
|
||||
|
||||
template<typename T, size_t N>
|
||||
void substitution8(T &v, const std::array<T, N> &expectedValues) { substitution<8>(v, expectedValues); };
|
||||
void entropy8b(T &v, const T (&expectedValues)[N]) { entropy<8>(v, expectedValues); };
|
||||
|
||||
template<typename T>
|
||||
void text1(std::basic_string<T> &str, size_t maxSize) { text<1>(str, maxSize); }
|
||||
void text1b(T &str, size_t maxSize) { text<1>(str, maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void text2(std::basic_string<T> &str, size_t maxSize) { text<2>(str, maxSize); }
|
||||
void text2b(T &str, size_t maxSize) { text<2>(str, maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void text4(std::basic_string<T> &str, size_t maxSize) { text<4>(str, maxSize); }
|
||||
void text4b(T &str, size_t maxSize) { text<4>(str, maxSize); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void text1(T (&str)[N]) { text<1>(str); }
|
||||
void text1b(T (&str)[N]) { text<1>(str); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void text2(T (&str)[N]) { text<2>(str); }
|
||||
void text2b(T (&str)[N]) { text<2>(str); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void text4(T (&str)[N]) { text<4>(str); }
|
||||
void text4b(T (&str)[N]) { text<4>(str); }
|
||||
|
||||
template<typename T>
|
||||
void container1(T &&obj, size_t maxSize) { container<1>(std::forward<T>(obj), maxSize); }
|
||||
void container1b(T &&obj, size_t maxSize) { container<1>(std::forward<T>(obj), maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void container2(T &&obj, size_t maxSize) { container<2>(std::forward<T>(obj), maxSize); }
|
||||
void container2b(T &&obj, size_t maxSize) { container<2>(std::forward<T>(obj), maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void container4(T &&obj, size_t maxSize) { container<4>(std::forward<T>(obj), maxSize); }
|
||||
void container4b(T &&obj, size_t maxSize) { container<4>(std::forward<T>(obj), maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void container8(T &&obj, size_t maxSize) { container<8>(std::forward<T>(obj), maxSize); }
|
||||
void container8b(T &&obj, size_t maxSize) { container<8>(std::forward<T>(obj), maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void container1b(T &&obj) { container<1>(std::forward<T>(obj)); }
|
||||
|
||||
template<typename T>
|
||||
void container2b(T &&obj) { container<2>(std::forward<T>(obj)); }
|
||||
|
||||
template<typename T>
|
||||
void container4b(T &&obj) { container<4>(std::forward<T>(obj)); }
|
||||
|
||||
template<typename T>
|
||||
void container8b(T &&obj) { container<8>(std::forward<T>(obj)); }
|
||||
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array1(std::array<T, N> &arr) { array<1>(arr); }
|
||||
void container1b(T (&arr)[N]) { container<1>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array2(std::array<T, N> &arr) { array<2>(arr); }
|
||||
void container2b(T (&arr)[N]) { container<2>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array4(std::array<T, N> &arr) { array<4>(arr); }
|
||||
void container4b(T (&arr)[N]) { container<4>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array8(std::array<T, N> &arr) { array<8>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array1(T (&arr)[N]) { array<1>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array2(T (&arr)[N]) { array<2>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array4(T (&arr)[N]) { array<4>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array8(T (&arr)[N]) { array<8>(arr); }
|
||||
void container8b(T (&arr)[N]) { container<8>(arr); }
|
||||
|
||||
private:
|
||||
Reader &_reader;
|
||||
bool _isValid;
|
||||
void* _context;
|
||||
|
||||
void readSize(size_t &size, size_t maxSize) {
|
||||
size = {};
|
||||
if (_isValid) {
|
||||
unsigned char firstBit;
|
||||
_isValid = _reader.readBits(firstBit, 1);
|
||||
if (_isValid) {
|
||||
if (firstBit) {
|
||||
_isValid = _reader.readBits(size, 7);
|
||||
} else {
|
||||
unsigned char secondBit;
|
||||
_isValid = _reader.readBits(secondBit, 1);
|
||||
if (_isValid) {
|
||||
if (secondBit) {
|
||||
_isValid = _reader.readBits(size, 14);
|
||||
} else {
|
||||
_isValid = _reader.readBits(size, 30);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_isValid)
|
||||
_isValid = size <= maxSize;
|
||||
details::readSize(_reader, size);
|
||||
if (size > maxSize) {
|
||||
_reader.setError(BufferReaderError::INVALID_BUFFER_DATA);
|
||||
size = {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,7 +386,7 @@ namespace bitsery {
|
||||
//false_type means that we must process all elements individually
|
||||
template<size_t VSIZE, typename It>
|
||||
void procContainer(It first, It last, std::false_type) {
|
||||
for (; _isValid && first != last; ++first)
|
||||
for (; first != last; ++first)
|
||||
value<VSIZE>(*first);
|
||||
};
|
||||
|
||||
@@ -417,21 +394,21 @@ namespace bitsery {
|
||||
//true_type means, that we can copy whole buffer
|
||||
template<size_t VSIZE, typename It>
|
||||
void procContainer(It first, It last, std::true_type) {
|
||||
if (_isValid && first != last)
|
||||
_isValid = _reader.template readBuffer<VSIZE>(&(*first), std::distance(first, last));
|
||||
if (first != last)
|
||||
_reader.template readBuffer<VSIZE>(&(*first), std::distance(first, last));
|
||||
};
|
||||
|
||||
//process by calling functions
|
||||
template<typename It, typename Fnc>
|
||||
void procContainer(It first, It last, Fnc fnc) {
|
||||
for (; _isValid && first != last; ++first)
|
||||
for (; first != last; ++first)
|
||||
fnc(*this, *first);
|
||||
};
|
||||
|
||||
//process object types
|
||||
template<typename It>
|
||||
void procContainer(It first, It last) {
|
||||
for (; _isValid && first != last; ++first)
|
||||
for (; first != last; ++first)
|
||||
object(*first);
|
||||
};
|
||||
|
||||
|
||||
73
include/bitsery/details/both_common.h
Normal file
73
include/bitsery/details/both_common.h
Normal file
@@ -0,0 +1,73 @@
|
||||
//MIT License
|
||||
//
|
||||
//Copyright (c) 2017 Mindaugas Vinkelis
|
||||
//
|
||||
//Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
//of this software and associated documentation files (the "Software"), to deal
|
||||
//in the Software without restriction, including without limitation the rights
|
||||
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
//copies of the Software, and to permit persons to whom the Software is
|
||||
//furnished to do so, subject to the following conditions:
|
||||
//
|
||||
//The above copyright notice and this permission notice shall be included in all
|
||||
//copies or substantial portions of the Software.
|
||||
//
|
||||
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
//SOFTWARE.
|
||||
|
||||
#ifndef BITSERY_DETAILS_BOTH_COMMON_H
|
||||
#define BITSERY_DETAILS_BOTH_COMMON_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace bitsery {
|
||||
namespace details {
|
||||
/*
|
||||
* size read/write functions
|
||||
*/
|
||||
template <typename Reader>
|
||||
void readSize(Reader& r, size_t& size) {
|
||||
uint8_t hb{};
|
||||
r.template readBytes<1>(hb);
|
||||
if (hb < 0x80u) {
|
||||
size = hb;
|
||||
} else {
|
||||
uint8_t lb{};
|
||||
r.template readBytes<1>(lb);
|
||||
if (hb & 0x40u) {
|
||||
uint16_t lw{};
|
||||
r.template readBytes<2>(lw);
|
||||
size = ((((hb & 0x3Fu) << 8) | lb) << 16) | lw;
|
||||
} else {
|
||||
size = ((hb & 0x7Fu) << 8) | lb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Writter>
|
||||
void writeSize(Writter& w, const size_t size) {
|
||||
if (size < 0x80u) {
|
||||
w.template writeBytes<1>(static_cast<uint8_t>(size));
|
||||
} else {
|
||||
if (size < 0x4000u) {
|
||||
w.template writeBytes<1>(static_cast<uint8_t>((size >> 8) | 0x80u));
|
||||
w.template writeBytes<1>(static_cast<uint8_t>(size));
|
||||
} else {
|
||||
assert(size < 0x40000000u);
|
||||
w.template writeBytes<1>(static_cast<uint8_t>((size >> 24) | 0xC0u));
|
||||
w.template writeBytes<1>(static_cast<uint8_t>(size >> 16));
|
||||
w.template writeBytes<2>(static_cast<uint16_t>(size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif //BITSERY_DETAILS_BOTH_COMMON_H
|
||||
@@ -20,15 +20,17 @@
|
||||
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
//SOFTWARE.
|
||||
|
||||
#ifndef BITSERY_BUFFER_COMMON_H
|
||||
#define BITSERY_BUFFER_COMMON_H
|
||||
#ifndef BITSERY_DETAILS_BUFFER_COMMON_H
|
||||
#define BITSERY_DETAILS_BUFFER_COMMON_H
|
||||
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
#include <cstring>
|
||||
#include "both_common.h"
|
||||
|
||||
namespace bitsery {
|
||||
|
||||
@@ -47,6 +49,11 @@ namespace bitsery {
|
||||
I end() const { return this->second; }
|
||||
};
|
||||
|
||||
enum class BufferReaderError {
|
||||
NO_ERROR,
|
||||
BUFFER_OVERFLOW,
|
||||
INVALID_BUFFER_DATA
|
||||
};
|
||||
|
||||
namespace details {
|
||||
template<typename T>
|
||||
@@ -124,36 +131,218 @@ namespace bitsery {
|
||||
using type = uint64_t;
|
||||
};
|
||||
|
||||
// struct BufferSessionInfo {
|
||||
// size_t depth;
|
||||
// size_t offset;
|
||||
// };
|
||||
|
||||
class BufferSessionsWriter {
|
||||
public:
|
||||
void begin() {
|
||||
//write position
|
||||
_sessionIndex.push(_sessions.size());
|
||||
_sessions.emplace_back(0);
|
||||
}
|
||||
void end(size_t pos) {
|
||||
assert(!_sessionIndex.empty());
|
||||
//change position to session end
|
||||
auto sessionIt = std::next(std::begin(_sessions), _sessionIndex.top());
|
||||
_sessionIndex.pop();
|
||||
*sessionIt = pos;
|
||||
}
|
||||
template <typename TWriter>
|
||||
void flushSessions(TWriter& writer) {
|
||||
if (_sessions.size()) {
|
||||
assert(_sessionIndex.empty());
|
||||
auto range = writer.getWrittenRange();
|
||||
auto dataSize = static_cast<size_t>(std::distance(range.begin(), range.end()));
|
||||
for(auto& s:_sessions) {
|
||||
details::writeSize(writer, s);
|
||||
}
|
||||
_sessions.clear();
|
||||
|
||||
range = writer.getWrittenRange();
|
||||
auto totalSize = static_cast<size_t>(std::distance(range.begin(), range.end()));
|
||||
//write offset where actual data ends
|
||||
auto sessionsOffset = totalSize - dataSize + 2;//2 bytes for offset data
|
||||
if (sessionsOffset < 0x8000u) {
|
||||
writer.template writeBytes<2>(static_cast<uint16_t>(sessionsOffset));
|
||||
} else {
|
||||
//size doesnt fit in 2 bytes, write 4 bytes instead
|
||||
sessionsOffset+=2;
|
||||
uint16_t low = static_cast<uint16_t>(sessionsOffset);
|
||||
//mark most significant bit, that size is 4 bytes
|
||||
uint16_t high = static_cast<uint16_t>(0x8000u | (sessionsOffset >> 16));
|
||||
writer.template writeBytes<2>(low);
|
||||
writer.template writeBytes<2>(high);
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
std::vector<size_t> _sessions{};
|
||||
std::stack<size_t> _sessionIndex;
|
||||
};
|
||||
|
||||
template <typename TReader, typename TIterator>
|
||||
struct BufferSessionsReader {
|
||||
TIterator _bufBegin;
|
||||
BufferSessionsReader(TReader& r, TIterator& begin, TIterator& end)
|
||||
:_reader{r},
|
||||
_pos{begin},
|
||||
_end{end}
|
||||
{
|
||||
_bufBegin = begin;
|
||||
}
|
||||
void begin() {
|
||||
if (_sessions.empty())
|
||||
initializeSessions();
|
||||
//save end position for current session
|
||||
_sessionsStack.push(_end);
|
||||
if (_nextSessionIt != std::end(_sessions)) {
|
||||
if (std::distance(_pos, _end) > 0) {
|
||||
//set end position for new session
|
||||
auto newEnd = std::next(_bufBegin, *_nextSessionIt);
|
||||
if (std::distance(newEnd, _end) < 0)
|
||||
{
|
||||
//new session cannot end further than current end
|
||||
_reader.setError(BufferReaderError::INVALID_BUFFER_DATA);
|
||||
return;
|
||||
}
|
||||
_end = newEnd;
|
||||
++_nextSessionIt;
|
||||
}
|
||||
//if we reached the end, means that there is no more data to read, hence there is no more sessions to advance to
|
||||
} else {
|
||||
//there is no data to read anymore
|
||||
//pos == end or buffer overflow while session is active
|
||||
if (!(_pos == _end || _reader.getError() == BufferReaderError::NO_ERROR)) {
|
||||
_reader.setError(BufferReaderError::INVALID_BUFFER_DATA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void end() {
|
||||
if (!_sessionsStack.empty()) {
|
||||
//move position to the end of session
|
||||
//can additionaly be checked for session data versioning
|
||||
//_pos == _end : same versions
|
||||
//distance(_pos,_end) > 0: reading newer version
|
||||
//getError() == BUFFER_OVERFLOW: reading older version
|
||||
auto dist = std::distance(_pos, _end);
|
||||
if (dist > 0) {
|
||||
//newer version might have some inner sessions, try to find the one after current ends
|
||||
auto currPos = static_cast<size_t>(std::distance(_bufBegin, _end));
|
||||
for (; _nextSessionIt != std::end(_sessions); ++_nextSessionIt) {
|
||||
if (*_nextSessionIt > currPos)
|
||||
break;
|
||||
}
|
||||
}
|
||||
_pos = _end;
|
||||
//restore end position
|
||||
_end = _sessionsStack.top();
|
||||
_sessionsStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
bool hasActiveSessions() const {
|
||||
return _sessionsStack.size() > 0;
|
||||
}
|
||||
|
||||
private:
|
||||
TReader& _reader;
|
||||
TIterator& _pos;
|
||||
TIterator& _end;
|
||||
|
||||
std::vector<size_t> _sessions{};
|
||||
std::vector<size_t>::iterator _nextSessionIt{};
|
||||
std::stack<TIterator> _sessionsStack{};
|
||||
|
||||
void initializeSessions() {
|
||||
//save current position
|
||||
auto currPos = _pos;
|
||||
auto bufferSizeLeft = std::distance(_pos, _end);
|
||||
//read size
|
||||
if (bufferSizeLeft < 2) {
|
||||
_reader.setError(BufferReaderError::INVALID_BUFFER_DATA);
|
||||
return;
|
||||
}
|
||||
auto endSessionsSizesIt = std::next(_end, -2);
|
||||
_pos = endSessionsSizesIt;
|
||||
size_t sessionsOffset{};
|
||||
uint16_t high;
|
||||
_reader.template readBytes<2>(high);
|
||||
|
||||
|
||||
if (high >= 0x8000u) {
|
||||
if (bufferSizeLeft < 4) {
|
||||
_reader.setError(BufferReaderError::INVALID_BUFFER_DATA);
|
||||
return;
|
||||
}
|
||||
endSessionsSizesIt = std::next(endSessionsSizesIt, -2);
|
||||
_pos = endSessionsSizesIt;
|
||||
uint16_t low;
|
||||
_reader.template readBytes<2>(low);
|
||||
//mask out last bit
|
||||
high &= 0x7FFFu;
|
||||
sessionsOffset = static_cast<size_t>((high << 16) | low);
|
||||
|
||||
} else
|
||||
sessionsOffset = high;
|
||||
if (static_cast<size_t>(bufferSizeLeft) < sessionsOffset) {
|
||||
_reader.setError(BufferReaderError::INVALID_BUFFER_DATA);
|
||||
return;
|
||||
}
|
||||
//we can initialy resizes to this value, and we'll shrink it after reading
|
||||
//read session sizes
|
||||
auto sessionsIt = std::back_inserter(_sessions);
|
||||
_pos = std::next(_end, -sessionsOffset);
|
||||
while (std::distance(_pos, endSessionsSizesIt) > 0) {
|
||||
//todo try to read into iterator directly
|
||||
size_t size;
|
||||
details::readSize(_reader, size);
|
||||
*sessionsIt++ = size;
|
||||
}
|
||||
_sessions.shrink_to_fit();
|
||||
//set iterators to data
|
||||
_pos = currPos;
|
||||
_end = std::next(_end, -sessionsOffset);
|
||||
_nextSessionIt = std::begin(_sessions);//set before first session;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Buffer, bool isFixed>
|
||||
class WriteBufferContext {
|
||||
|
||||
};
|
||||
|
||||
template<typename Buffer>
|
||||
class WriteBufferContext<Buffer, true> {
|
||||
class WriteBufferContext<Buffer, true>{
|
||||
public:
|
||||
using ValueType = typename Buffer::value_type;
|
||||
using IteratorType = typename Buffer::iterator;
|
||||
|
||||
explicit WriteBufferContext(Buffer &buffer)
|
||||
: _buffer{buffer},
|
||||
_outIt{buffer.begin()},
|
||||
_end{buffer.end()}
|
||||
_outIt{std::addressof(*std::begin(buffer))},
|
||||
_end{std::addressof(*std::end(buffer))}
|
||||
{
|
||||
}
|
||||
|
||||
void write(const ValueType *data, size_t size) {
|
||||
assert(std::distance(_outIt, _end) >= static_cast<typename Buffer::difference_type>(size));
|
||||
_outIt = std::copy_n(data, size, _outIt);
|
||||
memcpy(_outIt, data, size);
|
||||
_outIt += size;
|
||||
}
|
||||
|
||||
BufferRange<IteratorType> getWrittenRange() const {
|
||||
return BufferRange<IteratorType>{_buffer.begin(), _outIt};
|
||||
auto begin = std::begin(_buffer);
|
||||
return BufferRange<IteratorType>{begin, std::next(begin, _outIt - std::addressof(*begin))};
|
||||
}
|
||||
|
||||
private:
|
||||
Buffer &_buffer;
|
||||
IteratorType _outIt;
|
||||
IteratorType _end;
|
||||
ValueType* _outIt;
|
||||
ValueType* _end;
|
||||
};
|
||||
|
||||
template<typename Buffer>
|
||||
@@ -169,11 +358,12 @@ namespace bitsery {
|
||||
}
|
||||
|
||||
void write(const ValueType *data, size_t size) {
|
||||
if (std::distance(_outIt, _end) >= static_cast<typename Buffer::difference_type>(size)) {
|
||||
_outIt = std::copy_n(data, size, _outIt);
|
||||
if ((_end - _outIt) >= static_cast<typename Buffer::difference_type>(size)) {
|
||||
std::memcpy(_outIt, data, size);
|
||||
_outIt += size;
|
||||
} else {
|
||||
//get current position before invalidating iterators
|
||||
auto pos = std::distance(_buffer.begin(), _outIt);
|
||||
auto pos = std::distance(std::addressof(*std::begin(_buffer)), _outIt);
|
||||
//make dummy call to back insert iterator to resize buffer
|
||||
*(std::back_insert_iterator<Buffer>(_buffer)) = {};
|
||||
resizeToCapacity(pos);
|
||||
@@ -182,24 +372,26 @@ namespace bitsery {
|
||||
}
|
||||
|
||||
BufferRange<IteratorType> getWrittenRange() const {
|
||||
return BufferRange<IteratorType>{_buffer.begin(), _outIt};
|
||||
auto begin = std::begin(_buffer);
|
||||
return BufferRange<IteratorType>{begin, std::next(begin, _outIt - std::addressof(*begin))};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void resizeToCapacity(typename Buffer::difference_type writePos) {
|
||||
if (_buffer.capacity() != _buffer.size()) {
|
||||
_buffer.resize(_buffer.capacity());
|
||||
}
|
||||
_end = _buffer.end();
|
||||
_outIt = std::next(_buffer.begin(), writePos);
|
||||
_end = std::addressof(*std::end(_buffer));
|
||||
_outIt = std::addressof(*std::next(std::begin(_buffer), writePos));
|
||||
}
|
||||
Buffer &_buffer;
|
||||
IteratorType _outIt;
|
||||
IteratorType _end;
|
||||
ValueType* _outIt;
|
||||
ValueType* _end;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //BITSERY_BUFFER_COMMON_H
|
||||
#endif //BITSERY_DETAILS_BUFFER_COMMON_H
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
//SOFTWARE.
|
||||
|
||||
#ifndef BITSERY_SERIALIZATION_COMMON_H
|
||||
#define BITSERY_SERIALIZATION_COMMON_H
|
||||
#ifndef BITSERY_DETAILS_SERIALIZATION_COMMON_H
|
||||
#define BITSERY_DETAILS_SERIALIZATION_COMMON_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <array>
|
||||
#include "both_common.h"
|
||||
|
||||
namespace bitsery {
|
||||
|
||||
@@ -60,8 +60,20 @@ namespace bitsery {
|
||||
return getSize(max - min, 0);
|
||||
}
|
||||
|
||||
template <typename T, typename = int>
|
||||
struct IsResizable : std::false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct IsResizable <T, decltype((void)std::declval<T>().resize(1u), 0)> : std::true_type {};
|
||||
}
|
||||
|
||||
/*
|
||||
* serialization/deserialization context
|
||||
*/
|
||||
struct Context {
|
||||
void* getCustomPtr();
|
||||
};
|
||||
|
||||
/*
|
||||
* range functions in bitsery namespace because these are used by user
|
||||
*/
|
||||
@@ -138,7 +150,8 @@ namespace bitsery {
|
||||
|
||||
template<typename T, typename std::enable_if<std::is_enum<T>::value>::type * = nullptr>
|
||||
auto getRangeValue(const T &v, const RangeSpec<T> &r) {
|
||||
return static_cast<SAME_SIZE_UNSIGNED<T>>(v) - static_cast<SAME_SIZE_UNSIGNED<T>>(r.min);
|
||||
using VT = SAME_SIZE_UNSIGNED<T>;
|
||||
return static_cast<VT>(static_cast<VT>(v) - static_cast<VT>(r.min));
|
||||
};
|
||||
|
||||
template<typename T, typename std::enable_if<std::is_floating_point<T>::value>::type * = nullptr>
|
||||
@@ -181,11 +194,11 @@ namespace bitsery {
|
||||
}
|
||||
|
||||
/*
|
||||
* functions for substitution
|
||||
* functions for entropy encoding
|
||||
*/
|
||||
|
||||
template<typename T, size_t N>
|
||||
size_t findSubstitutionIndex(const T &v, const std::array<T, N> &defValues) {
|
||||
size_t findEntropyIndex(const T &v, const T (&defValues)[N]) {
|
||||
auto index{1u};
|
||||
for (auto &d:defValues) {
|
||||
if (d == v)
|
||||
@@ -215,6 +228,7 @@ namespace bitsery {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* delta functions
|
||||
*/
|
||||
@@ -256,4 +270,4 @@ namespace bitsery {
|
||||
|
||||
}
|
||||
|
||||
#endif //BITSERY_SERIALIZATION_COMMON_H
|
||||
#endif //BITSERY_DETAILS_SERIALIZATION_COMMON_H
|
||||
|
||||
@@ -48,16 +48,16 @@ namespace bitsery {
|
||||
static_assert(std::is_default_constructible<TVal>::value, "");
|
||||
};
|
||||
|
||||
template<typename T, typename Ser, typename Fnc>
|
||||
void serialize(const T &obj, Ser &ser, Fnc &&fnc) const {
|
||||
template<typename Ser, typename Writer, typename T, typename Fnc>
|
||||
void serialize(Ser &ser, Writer &, const T &obj, Fnc &&fnc) const {
|
||||
assertType<T>();
|
||||
ser.boolByte(static_cast<bool>(obj));
|
||||
if (obj)
|
||||
fnc(ser, *obj);
|
||||
}
|
||||
|
||||
template<typename T, typename Des, typename Fnc>
|
||||
void deserialize(T &obj, Des &des, Fnc &&fnc) const {
|
||||
template<typename Des, typename Reader, typename T, typename Fnc>
|
||||
void deserialize(Des &des, Reader& , T &obj, Fnc &&fnc) const {
|
||||
assertType<T>();
|
||||
bool exists{};
|
||||
des.boolByte(exists);
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
//SOFTWARE.
|
||||
|
||||
|
||||
|
||||
#ifndef BITSERY_SERIALIZER_H
|
||||
#define BITSERY_SERIALIZER_H
|
||||
|
||||
@@ -29,14 +28,21 @@
|
||||
#include "details/serialization_common.h"
|
||||
#include <cassert>
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
namespace bitsery {
|
||||
|
||||
template<typename Writter>
|
||||
class Serializer {
|
||||
public:
|
||||
Serializer(Writter &w) : _writter{w} {};
|
||||
Serializer(Writter &w, void* context = nullptr) : _writter{w}, _context{context} {};
|
||||
|
||||
/*
|
||||
* get serialization context.
|
||||
* this is optional, but might be required for some specific serialization flows.
|
||||
*/
|
||||
void* getContext() {
|
||||
return _context;
|
||||
}
|
||||
|
||||
/*
|
||||
* object function
|
||||
@@ -46,6 +52,11 @@ namespace bitsery {
|
||||
details::SerializeFunction<Serializer, T>::invoke(*this, std::forward<T>(obj));
|
||||
}
|
||||
|
||||
template<typename T, typename Fnc>
|
||||
void object(T &&obj, Fnc &&fnc) {
|
||||
fnc(*this, std::forward<T>(obj));
|
||||
};
|
||||
|
||||
/*
|
||||
* value overloads
|
||||
*/
|
||||
@@ -67,33 +78,35 @@ namespace bitsery {
|
||||
}
|
||||
|
||||
/*
|
||||
* custom function
|
||||
* growable function
|
||||
*/
|
||||
|
||||
template<typename T, typename Fnc>
|
||||
void custom(T &&obj, Fnc &&fnc) {
|
||||
fnc(*this, std::forward<T>(obj));
|
||||
void growable(const T &obj, Fnc &&fnc) {
|
||||
_writter.beginSession();
|
||||
fnc(*this, obj);
|
||||
_writter.endSession();
|
||||
};
|
||||
|
||||
/*
|
||||
* extension functions
|
||||
* extend functions
|
||||
*/
|
||||
|
||||
template<typename T, typename Ext, typename Fnc>
|
||||
void extension(const T &obj, Ext &&ext, Fnc &&fnc) {
|
||||
ext.serialize(obj, *this, std::forward<Fnc>(fnc));
|
||||
void extend(const T &obj, Ext &&ext, Fnc &&fnc) {
|
||||
ext.serialize(*this, _writter, obj, std::forward<Fnc>(fnc));
|
||||
|
||||
};
|
||||
|
||||
template<size_t VSIZE, typename T, typename Ext>
|
||||
void extension(const T &obj, Ext &&ext) {
|
||||
ext.serialize(obj, *this, [](auto &s, auto &v) { s.template value<VSIZE>(v); });
|
||||
void extend(const T &obj, Ext &&ext) {
|
||||
ext.serialize(*this, _writter, obj, [](auto &s, auto &v) { s.template value<VSIZE>(v); });
|
||||
|
||||
};
|
||||
|
||||
template<typename T, typename Ext>
|
||||
void extension(const T &obj, Ext &&ext) {
|
||||
ext.serialize(obj, *this, [](auto &s, auto &v) { s.object(v); });
|
||||
void extend(const T &obj, Ext &&ext) {
|
||||
ext.serialize(*this, _writter, obj, [](auto &s, auto &v) { s.object(v); });
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -120,27 +133,27 @@ namespace bitsery {
|
||||
}
|
||||
|
||||
/*
|
||||
* substitution overloads
|
||||
* entropy overloads
|
||||
*/
|
||||
template<typename T, size_t N, typename Fnc>
|
||||
void substitution(const T &v, const std::array<T, N> &expectedValues, Fnc &&fnc) {
|
||||
auto index = details::findSubstitutionIndex(v, expectedValues);
|
||||
void entropy(const T &v, const T (&expectedValues)[N], Fnc &&fnc) {
|
||||
auto index = details::findEntropyIndex(v, expectedValues);
|
||||
range(index, {{}, N + 1});
|
||||
if (!index)
|
||||
fnc(*this, v);
|
||||
};
|
||||
|
||||
template<size_t VSIZE, typename T, size_t N>
|
||||
void substitution(const T &v, const std::array<T, N> &expectedValues) {
|
||||
auto index = details::findSubstitutionIndex(v, expectedValues);
|
||||
void entropy(const T &v, const T (&expectedValues)[N]) {
|
||||
auto index = details::findEntropyIndex(v, expectedValues);
|
||||
range(index, {{}, N + 1});
|
||||
if (!index)
|
||||
value<VSIZE>(v);
|
||||
};
|
||||
|
||||
template<typename T, size_t N>
|
||||
void substitution(const T &v, const std::array<T, N> &expectedValues) {
|
||||
auto index = details::findSubstitutionIndex(v, expectedValues);
|
||||
void entropy(const T &v, const T (&expectedValues)[N]) {
|
||||
auto index = details::findEntropyIndex(v, expectedValues);
|
||||
range(index, {{}, N + 1});
|
||||
if (!index)
|
||||
object(v);
|
||||
@@ -151,11 +164,12 @@ namespace bitsery {
|
||||
*/
|
||||
|
||||
template<size_t VSIZE, typename T>
|
||||
void text(const std::basic_string<T> &str, size_t maxSize) {
|
||||
assert(str.size() <= maxSize);
|
||||
void text(const T &str, size_t maxSize) {
|
||||
auto first = std::begin(str);
|
||||
auto last = std::end(str);
|
||||
writeSize(std::distance(first, last));
|
||||
auto size = static_cast<size_t>(std::distance(first, last));
|
||||
assert(size <= maxSize);
|
||||
writeSize(size);
|
||||
procContainer<VSIZE>(first, last, std::true_type{});
|
||||
}
|
||||
|
||||
@@ -171,8 +185,12 @@ namespace bitsery {
|
||||
* container overloads
|
||||
*/
|
||||
|
||||
//dynamic size containers
|
||||
|
||||
template<typename T, typename Fnc>
|
||||
void container(const T &obj, size_t maxSize, Fnc &&fnc) {
|
||||
static_assert(details::IsResizable<T>::value,
|
||||
"use container(const T&, Fnc) overload without `maxSize` for static containers");
|
||||
assert(obj.size() <= maxSize);
|
||||
writeSize(obj.size());
|
||||
procContainer(std::begin(obj), std::end(obj), std::forward<Fnc>(fnc));
|
||||
@@ -180,6 +198,8 @@ namespace bitsery {
|
||||
|
||||
template<size_t VSIZE, typename T>
|
||||
void container(const T &obj, size_t maxSize) {
|
||||
static_assert(details::IsResizable<T>::value,
|
||||
"use container(const T&) overload without `maxSize` for static containers");
|
||||
static_assert(VSIZE > 0, "");
|
||||
assert(obj.size() <= maxSize);
|
||||
writeSize(obj.size());
|
||||
@@ -189,48 +209,53 @@ namespace bitsery {
|
||||
|
||||
template<typename T>
|
||||
void container(const T &obj, size_t maxSize) {
|
||||
static_assert(details::IsResizable<T>::value,
|
||||
"use container(const T&) overload without `maxSize` for static containers");
|
||||
assert(obj.size() <= maxSize);
|
||||
writeSize(obj.size());
|
||||
procContainer(std::begin(obj), std::end(obj));
|
||||
}
|
||||
|
||||
/*
|
||||
* array overloads (fixed size array (std::array, and c-style array))
|
||||
*/
|
||||
//fixed size containers
|
||||
|
||||
//std::array overloads
|
||||
|
||||
template<typename T, size_t N, typename Fnc>
|
||||
void array(const std::array<T, N> &arr, Fnc &&fnc) {
|
||||
procContainer(std::begin(arr), std::end(arr), std::forward<Fnc>(fnc));
|
||||
template<typename T, typename Fnc, typename std::enable_if<!std::is_integral<Fnc>::value>::type * = nullptr>
|
||||
void container(const T &obj, Fnc &&fnc) {
|
||||
static_assert(!details::IsResizable<T>::value,
|
||||
"use container(const T&, size_t, Fnc) overload with `maxSize` for dynamic containers");
|
||||
procContainer(std::begin(obj), std::end(obj), std::forward<Fnc>(fnc));
|
||||
}
|
||||
|
||||
template<size_t VSIZE, typename T, size_t N>
|
||||
void array(const std::array<T, N> &arr) {
|
||||
template<size_t VSIZE, typename T>
|
||||
void container(const T &obj) {
|
||||
static_assert(!details::IsResizable<T>::value,
|
||||
"use container(const T&, size_t) overload with `maxSize` for dynamic containers");
|
||||
static_assert(VSIZE > 0, "");
|
||||
procContainer<VSIZE>(std::begin(arr), std::end(arr), std::true_type{});
|
||||
//todo optimisation is possible for contigous containers, but currently there is no compile-time check for this
|
||||
procContainer<VSIZE>(std::begin(obj), std::end(obj), std::false_type{});
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array(const std::array<T, N> &arr) {
|
||||
procContainer(std::begin(arr), std::end(arr));
|
||||
template<typename T>
|
||||
void container(const T &obj) {
|
||||
static_assert(!details::IsResizable<T>::value,
|
||||
"use container(const T&, size_t) overload with `maxSize` for dynamic containers");
|
||||
procContainer(std::begin(obj), std::end(obj));
|
||||
}
|
||||
|
||||
//c-style array overloads
|
||||
|
||||
template<typename T, size_t N, typename Fnc>
|
||||
void array(const T (&arr)[N], Fnc &&fnc) {
|
||||
void container(const T (&arr)[N], Fnc &&fnc) {
|
||||
procContainer(std::begin(arr), std::end(arr), std::forward<Fnc>(fnc));
|
||||
}
|
||||
|
||||
template<size_t VSIZE, typename T, size_t N>
|
||||
void array(const T (&arr)[N]) {
|
||||
void container(const T (&arr)[N]) {
|
||||
static_assert(VSIZE > 0, "");
|
||||
procContainer<VSIZE>(std::begin(arr), std::end(arr), std::true_type{});
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array(const T (&arr)[N]) {
|
||||
void container(const T (&arr)[N]) {
|
||||
procContainer(std::begin(arr), std::end(arr));
|
||||
}
|
||||
|
||||
@@ -238,127 +263,112 @@ namespace bitsery {
|
||||
_writter.align();
|
||||
}
|
||||
|
||||
bool isValid() const {
|
||||
//serialization cannot fail, it doesn't handle out of memory exception
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//overloads for functions with explicit type size
|
||||
|
||||
template<typename T>
|
||||
void value1(T &&v) { value<1>(std::forward<T>(v)); }
|
||||
void value1b(T &&v) { value<1>(std::forward<T>(v)); }
|
||||
|
||||
template<typename T>
|
||||
void value2(T &&v) { value<2>(std::forward<T>(v)); }
|
||||
void value2b(T &&v) { value<2>(std::forward<T>(v)); }
|
||||
|
||||
template<typename T>
|
||||
void value4(T &&v) { value<4>(std::forward<T>(v)); }
|
||||
void value4b(T &&v) { value<4>(std::forward<T>(v)); }
|
||||
|
||||
template<typename T>
|
||||
void value8(T &&v) { value<8>(std::forward<T>(v)); }
|
||||
void value8b(T &&v) { value<8>(std::forward<T>(v)); }
|
||||
|
||||
template<typename T, typename Ext>
|
||||
void extension1(const T &v, Ext &&ext) { extension<1>(v, std::forward<Ext>(ext)); };
|
||||
void extend1b(const T &v, Ext &&ext) { extend<1>(v, std::forward<Ext>(ext)); };
|
||||
|
||||
template<typename T, typename Ext>
|
||||
void extension2(const T &v, Ext &&ext) { extension<2>(v, std::forward<Ext>(ext)); };
|
||||
void extend2b(const T &v, Ext &&ext) { extend<2>(v, std::forward<Ext>(ext)); };
|
||||
|
||||
template<typename T, typename Ext>
|
||||
void extension4(const T &v, Ext &&ext) { extension<4>(v, std::forward<Ext>(ext)); };
|
||||
void extend4b(const T &v, Ext &&ext) { extend<4>(v, std::forward<Ext>(ext)); };
|
||||
|
||||
template<typename T, typename Ext>
|
||||
void extension8(const T &v, Ext &&ext) { extension<8>(v, std::forward<Ext>(ext)); };
|
||||
void extend8b(const T &v, Ext &&ext) { extend<8>(v, std::forward<Ext>(ext)); };
|
||||
|
||||
template<typename T, size_t N>
|
||||
void substitution1(const T &v, const std::array<T, N> &expectedValues) {
|
||||
substitution<1>(v, expectedValues);
|
||||
void entropy1b(const T &v, const T (&expectedValues)[N]) {
|
||||
entropy<1>(v, expectedValues);
|
||||
};
|
||||
|
||||
template<typename T, size_t N>
|
||||
void substitution2(const T &v, const std::array<T, N> &expectedValues) {
|
||||
substitution<2>(v, expectedValues);
|
||||
void entropy2b(const T &v, const T (&expectedValues)[N]) {
|
||||
entropy<2>(v, expectedValues);
|
||||
};
|
||||
|
||||
template<typename T, size_t N>
|
||||
void substitution4(const T &v, const std::array<T, N> &expectedValues) {
|
||||
substitution<4>(v, expectedValues);
|
||||
void entropy4b(const T &v, const T (&expectedValues)[N]) {
|
||||
entropy<4>(v, expectedValues);
|
||||
};
|
||||
|
||||
template<typename T, size_t N>
|
||||
void substitution8(const T &v, const std::array<T, N> &expectedValues) {
|
||||
substitution<8>(v, expectedValues);
|
||||
void entropy8b(const T &v, const T (&expectedValues)[N]) {
|
||||
entropy<8>(v, expectedValues);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void text1(const std::basic_string<T> &str, size_t maxSize) { text<1>(str, maxSize); }
|
||||
void text1b(const T &str, size_t maxSize) { text<1>(str, maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void text2(const std::basic_string<T> &str, size_t maxSize) { text<2>(str, maxSize); }
|
||||
void text2b(const T &str, size_t maxSize) { text<2>(str, maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void text4(const std::basic_string<T> &str, size_t maxSize) { text<4>(str, maxSize); }
|
||||
void text4b(const T &str, size_t maxSize) { text<4>(str, maxSize); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void text1(const T (&str)[N]) { text<1>(str); }
|
||||
void text1b(const T (&str)[N]) { text<1>(str); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void text2(const T (&str)[N]) { text<2>(str); }
|
||||
void text2b(const T (&str)[N]) { text<2>(str); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void text4(const T (&str)[N]) { text<4>(str); }
|
||||
void text4b(const T (&str)[N]) { text<4>(str); }
|
||||
|
||||
template<typename T>
|
||||
void container1(T &&obj, size_t maxSize) { container<1>(std::forward<T>(obj), maxSize); }
|
||||
void container1b(T &&obj, size_t maxSize) { container<1>(std::forward<T>(obj), maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void container2(T &&obj, size_t maxSize) { container<2>(std::forward<T>(obj), maxSize); }
|
||||
void container2b(T &&obj, size_t maxSize) { container<2>(std::forward<T>(obj), maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void container4(T &&obj, size_t maxSize) { container<4>(std::forward<T>(obj), maxSize); }
|
||||
void container4b(T &&obj, size_t maxSize) { container<4>(std::forward<T>(obj), maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void container8(T &&obj, size_t maxSize) { container<8>(std::forward<T>(obj), maxSize); }
|
||||
void container8b(T &&obj, size_t maxSize) { container<8>(std::forward<T>(obj), maxSize); }
|
||||
|
||||
template<typename T>
|
||||
void container1b(T &&obj) { container<1>(std::forward<T>(obj)); }
|
||||
|
||||
template<typename T>
|
||||
void container2b(T &&obj) { container<2>(std::forward<T>(obj)); }
|
||||
|
||||
template<typename T>
|
||||
void container4b(T &&obj) { container<4>(std::forward<T>(obj)); }
|
||||
|
||||
template<typename T>
|
||||
void container8b(T &&obj) { container<8>(std::forward<T>(obj)); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array1(const std::array<T, N> &arr) { array<1>(arr); }
|
||||
void container1b(const T (&arr)[N]) { container<1>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array2(const std::array<T, N> &arr) { array<2>(arr); }
|
||||
void container2b(const T (&arr)[N]) { container<2>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array4(const std::array<T, N> &arr) { array<4>(arr); }
|
||||
void container4b(const T (&arr)[N]) { container<4>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array8(const std::array<T, N> &arr) { array<8>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array1(const T (&arr)[N]) { array<1>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array2(const T (&arr)[N]) { array<2>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array4(const T (&arr)[N]) { array<4>(arr); }
|
||||
|
||||
template<typename T, size_t N>
|
||||
void array8(const T (&arr)[N]) { array<8>(arr); }
|
||||
void container8b(const T (&arr)[N]) { container<8>(arr); }
|
||||
|
||||
private:
|
||||
Writter &_writter;
|
||||
void* _context;
|
||||
|
||||
void writeSize(const size_t size) {
|
||||
if (size < 0x80u) {
|
||||
_writter.writeBits(1u, 1);
|
||||
_writter.writeBits(size, 7);
|
||||
} else if (size < 0x4000u) {
|
||||
_writter.writeBits(2u, 2);
|
||||
_writter.writeBits(size, 14);
|
||||
} else {
|
||||
assert(size < 0x40000000u);
|
||||
_writter.writeBits(0u, 2);
|
||||
_writter.writeBits(size, 30);
|
||||
}
|
||||
details::writeSize(_writter, size);
|
||||
}
|
||||
|
||||
//process value types
|
||||
|
||||
Reference in New Issue
Block a user