diff options
author | Krzysztof Jackiewicz <k.jackiewicz@samsung.com> | 2024-10-16 09:27:56 +0200 |
---|---|---|
committer | Krzysztof Jackiewicz <k.jackiewicz@samsung.com> | 2024-10-16 09:40:52 +0200 |
commit | 5f6205232b2fec644fce74cd73e79ba89c449d06 (patch) | |
tree | ab3f2006c808ee77d90dfae99d90402d15ffa113 | |
parent | 0a5819a74896aaf41a63cf1f9575d123002ef4ec (diff) | |
download | webauthn-5f6205232b2fec644fce74cd73e79ba89c449d06.tar.gz webauthn-5f6205232b2fec644fce74cd73e79ba89c449d06.tar.bz2 webauthn-5f6205232b2fec644fce74cd73e79ba89c449d06.zip |
Remove unused code
Change-Id: I9a80b733501470176a65209dbae9e6f6f6dd42cd
-rw-r--r-- | srcs/common/serialization.cpp | 4 | ||||
-rw-r--r-- | srcs/common/serialization.h | 408 |
2 files changed, 3 insertions, 409 deletions
diff --git a/srcs/common/serialization.cpp b/srcs/common/serialization.cpp index 2ed0af2..dea982c 100644 --- a/srcs/common/serialization.cpp +++ b/srcs/common/serialization.cpp @@ -20,9 +20,9 @@ */ #include <cstring> -#include <iostream> +#include <utility> + #include "serialization.h" -#include "message-buffer.h" namespace WA { diff --git a/srcs/common/serialization.h b/srcs/common/serialization.h index a297999..88b0ea9 100644 --- a/srcs/common/serialization.h +++ b/srcs/common/serialization.h @@ -20,12 +20,8 @@ */ #pragma once -#include <string> -#include <vector> -#include <list> -#include <map> #include <memory> -#include <tuple> +#include <string> #include <exception.h> #include <webauthn-types.h> @@ -460,80 +456,12 @@ struct Serialization { { object.Serialize(stream); } - static void Serialize(IStream& stream, const ISerializable* const object) - { - object->Serialize(stream); - } - - // char - static void Serialize(IStream& stream, const char value) - { - stream.Write(sizeof(value), &value); - } - static void Serialize(IStream& stream, const char* const value) - { - stream.Write(sizeof(*value), value); - } - - // unsigned char - static void Serialize(IStream& stream, const unsigned char value) - { - stream.Write(sizeof(value), &value); - } - static void Serialize(IStream& stream, const unsigned char* const value) - { - stream.Write(sizeof(*value), value); - } - - // unsigned int - static void Serialize(IStream& stream, const unsigned value) - { - stream.Write(sizeof(value), &value); - } - static void Serialize(IStream& stream, const unsigned* const value) - { - stream.Write(sizeof(*value), value); - } // int static void Serialize(IStream& stream, const int value) { stream.Write(sizeof(value), &value); } - static void Serialize(IStream& stream, const int* const value) - { - stream.Write(sizeof(*value), value); - } - - // bool - static void Serialize(IStream& stream, const bool value) - { - stream.Write(sizeof(value), &value); - } - static void Serialize(IStream& stream, const bool* const value) - { - stream.Write(sizeof(*value), value); - } - - // unsigned long - static void Serialize(IStream& stream, const unsigned long value) - { - stream.Write(sizeof(value), &value); - } - static void Serialize(IStream& stream, const unsigned long* const value) - { - stream.Write(sizeof(*value), value); - } - - // long - static void Serialize(IStream& stream, const long value) - { - stream.Write(sizeof(value), &value); - } - static void Serialize(IStream& stream, const long* const value) - { - stream.Write(sizeof(*value), value); - } // std::string static void Serialize(IStream& stream, const std::string& str) @@ -542,119 +470,6 @@ struct Serialization { stream.Write(sizeof(length), &length); stream.Write(length, str.c_str()); } - static void Serialize(IStream& stream, const std::string* const str) - { - int length = str->size(); - stream.Write(sizeof(length), &length); - stream.Write(length, str->c_str()); - } - - // STL templates - - // std::list - template <typename T> - static void Serialize(IStream& stream, const std::list<T>& list) - { - int length = list.size(); - stream.Write(sizeof(length), &length); - for (typename std::list<T>::const_iterator list_iter = list.begin(); - list_iter != list.end(); list_iter++) - { - Serialize(stream, *list_iter); - } - } - template <typename T> - static void Serialize(IStream& stream, const std::list<T>* const list) - { - Serialize(stream, *list); - } - - // std::vector - template <typename T> - static void Serialize(IStream& stream, const std::vector<T>& vec) - { - int length = vec.size(); - stream.Write(sizeof(length), &length); - for (typename std::vector<T>::const_iterator vec_iter = vec.begin(); - vec_iter != vec.end(); vec_iter++) - { - Serialize(stream, *vec_iter); - } - } - template <typename T> - static void Serialize(IStream& stream, const std::vector<T>* const vec) - { - Serialize(stream, *vec); - } - - // std::pair - template <typename A, typename B> - static void Serialize(IStream& stream, const std::pair<A, B>& p) - { - Serialize(stream, p.first); - Serialize(stream, p.second); - } - template <typename A, typename B> - static void Serialize(IStream& stream, const std::pair<A, B>* const p) - { - Serialize(stream, *p); - } - - // std::tuple - template <std::size_t I = 0, typename... Tp> - static inline typename std::enable_if<I == sizeof...(Tp), void>::type - Serialize(IStream&, const std::tuple<Tp...>&) - {} - - - template <std::size_t I = 0, typename... Tp> - static inline typename std::enable_if<I < sizeof...(Tp), void>::type - Serialize(IStream &stream, const std::tuple<Tp...>& t) { - Serialize(stream, std::get<I>(t)); - Serialize<I+1>(stream, t); - } - - template <typename... Tp> - static void Serialize(IStream& stream, const std::tuple<Tp...>* const t) - { - Serialize(stream, *t); - } - - // std::map - template <typename K, typename T> - static void Serialize(IStream& stream, const std::map<K, T>& map) - { - int length = map.size(); - stream.Write(sizeof(length), &length); - typename std::map<K, T>::const_iterator it; - for (it = map.begin(); it != map.end(); ++it) { - Serialize(stream, (*it).first); - Serialize(stream, (*it).second); - } - } - template <typename K, typename T> - static void Serialize(IStream& stream, const std::map<K, T>* const map) - { - Serialize(stream, *map); - } - - // SerializeKeysAsVector<std::map> as vector - template <typename K, typename T> - static void Serialize(IStream& stream, SerializeKeysAsVector<std::map<K, T>> mapKeysOnly) - { - const auto &map = mapKeysOnly.get(); - int length = map.size(); - stream.Write(sizeof(length), &length); - for (auto it = map.begin(); it != map.end(); ++it) - Serialize(stream, it->first); - } - - // std::unique_ptr - template <typename T> - static void Serialize(IStream& stream, const std::unique_ptr<T>& p) - { - Serialize(stream, *p); - } // serialize 'em all template<typename T1, typename T2, typename... Tail> @@ -681,101 +496,12 @@ struct Deserialization { { object.Deserialize(buffer); } - static void Deserialize(MessageBuffer& buffer, IDeserializable*& object) - { - object->Deserialize(buffer); - } - - // char - static void Deserialize(MessageBuffer& buffer, char& value) - { - buffer.Read(sizeof(value), &value); - } - static void Deserialize(MessageBuffer& buffer, char*& value) - { - value = new char; - std::unique_ptr<char> ptr(value); - buffer.Read(sizeof(*value), value); - ptr.reset(); - } - - // unsigned char - static void Deserialize(MessageBuffer& buffer, unsigned char& value) - { - buffer.Read(sizeof(value), &value); - } - static void Deserialize(MessageBuffer& buffer, unsigned char*& value) - { - value = new unsigned char; - std::unique_ptr<unsigned char> ptr(value); - buffer.Read(sizeof(*value), value); - ptr.reset(); - } - - // unsigned int - static void Deserialize(MessageBuffer& buffer, unsigned& value) - { - buffer.Read(sizeof(value), &value); - } - static void Deserialize(MessageBuffer& buffer, unsigned*& value) - { - value = new unsigned; - std::unique_ptr<unsigned> ptr(value); - buffer.Read(sizeof(*value), value); - ptr.reset(); - } // int static void Deserialize(MessageBuffer& buffer, int& value) { buffer.Read(sizeof(value), &value); } - static void Deserialize(MessageBuffer& buffer, int*& value) - { - value = new int; - std::unique_ptr<int> ptr(value); - buffer.Read(sizeof(*value), value); - ptr.reset(); - } - - // bool - static void Deserialize(MessageBuffer& buffer, bool& value) - { - buffer.Read(sizeof(value), &value); - } - static void Deserialize(MessageBuffer& buffer, bool*& value) - { - value = new bool; - std::unique_ptr<bool> ptr(value); - buffer.Read(sizeof(*value), value); - ptr.reset(); - } - - // unsigned long - static void Deserialize(MessageBuffer& buffer, unsigned long& value) - { - buffer.Read(sizeof(value), &value); - } - static void Deserialize(MessageBuffer& buffer, unsigned long*& value) - { - value = new unsigned long; - std::unique_ptr<unsigned long> ptr(value); - buffer.Read(sizeof(*value), value); - ptr.reset(); - } - - // long - static void Deserialize(MessageBuffer& buffer, long& value) - { - buffer.Read(sizeof(value), &value); - } - static void Deserialize(MessageBuffer& buffer, long*& value) - { - value = new long; - std::unique_ptr<long> ptr(value); - buffer.Read(sizeof(*value), value); - ptr.reset(); - } // std::string static void Deserialize(MessageBuffer& buffer, std::string& str) @@ -792,138 +518,6 @@ struct Deserialization { buf[length] = 0; str = std::string(buf); } - static void Deserialize(MessageBuffer& buffer, std::string*& str) - { - int length; - buffer.Read(sizeof(length), &length); - if (length < 0) { - ThrowMsg(SerializationException::InvalidStreamData, - "Invalid length of std::string (less than 0)"); - } - char * buf = new char[length + 1]; - std::unique_ptr<char[]> ptr(buf); - buffer.Read(length, buf); - buf[length] = 0; - str = new std::string(buf); - } - - // STL templates - - // std::list - template <typename T> - static void Deserialize(MessageBuffer& buffer, std::list<T>& list) - { - int length; - buffer.Read(sizeof(length), &length); - if (length < 0) { - ThrowMsg(SerializationException::InvalidStreamData, - "Invalid length of std::list (less than 0)"); - } - for (int i = 0; i < length; ++i) { - T obj; - Deserialize(buffer, obj); - list.push_back(std::move(obj)); - } - } - template <typename T> - static void Deserialize(MessageBuffer& buffer, std::list<T>*& list) - { - list = new std::list<T>; - std::unique_ptr<std::list<T>> ptr(list); - Deserialize(buffer, *list); - ptr.reset(); - } - - // std::vector - template <typename T> - static void Deserialize(MessageBuffer& buffer, std::vector<T>& vec) - { - int length; - buffer.Read(sizeof(length), &length); - if (length < 0) { - ThrowMsg(SerializationException::InvalidStreamData, - "Invalid length of std::vector (less than 0)"); - } - for (int i = 0; i < length; ++i) { - T obj; - Deserialize(buffer, obj); - vec.push_back(std::move(obj)); - } - } - template <typename T> - static void Deserialize(MessageBuffer& buffer, std::vector<T>*& vec) - { - vec = new std::vector<T>; - std::unique_ptr<std::vector<T>> ptr(vec); - Deserialize(buffer, *vec); - ptr.reset(); - } - - // std::pair - template <typename A, typename B> - static void Deserialize(MessageBuffer& buffer, std::pair<A, B>& p) - { - Deserialize(buffer, p.first); - Deserialize(buffer, p.second); - } - template <typename A, typename B> - static void Deserialize(MessageBuffer& buffer, std::pair<A, B>*& p) - { - p = new std::pair<A, B>; - std::unique_ptr<std::pair<A, B>> ptr(p); - Deserialize(buffer, *p); - ptr.reset(); - } - - // std::tuple - template <std::size_t I = 0, typename... Tp> - static inline typename std::enable_if<I == sizeof...(Tp), void>::type - Deserialize(IStream&, std::tuple<Tp...>&) - {} - - template <std::size_t I = 0, typename... Tp> - static inline typename std::enable_if<I < sizeof...(Tp), void>::type - Deserialize(MessageBuffer& buffer, std::tuple<Tp...>& t) - { - Deserialize(buffer, std::get<I>(t)); - Deserialize<I+1>(buffer, t); - } - - template <typename... Tp> - static void Deserialize(MessageBuffer& buffer, std::tuple<Tp...>*& t) - { - t = new std::tuple<Tp...>; - std::unique_ptr<std::tuple<Tp...>> ptr(t); - Deserialize(buffer, *t); - ptr.reset(); - } - - // std::map - template <typename K, typename T> - static void Deserialize(MessageBuffer& buffer, std::map<K, T>& map) - { - int length; - buffer.Read(sizeof(length), &length); - if (length < 0) { - ThrowMsg(SerializationException::InvalidStreamData, - "Invalid size of std::map (less than 0)"); - } - for (int i = 0; i < length; ++i) { - K key; - T obj; - Deserialize(buffer, key); - Deserialize(buffer, obj); - map[key] = std::move(obj); - } - } - template <typename K, typename T> - static void Deserialize(MessageBuffer& buffer, std::map<K, T>*& map) - { - map = new std::map<K, T>; - std::unique_ptr<std::map<K, T>> ptr(map); - Deserialize(buffer, *map); - ptr.reset(); - } template<typename T1, typename T2, typename... Tail> static void Deserialize(MessageBuffer& buffer, T1 &&first, T2 &&second, Tail&&... tail) |