From e3fbddca2a312742660890200f6807bf8ad7283d Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Tue, 1 Aug 2017 04:36:19 -0300 Subject: [PATCH 1/2] Refactor AbiSerializer --- libraries/types/AbiSerializer.cpp | 254 +++++++++++++----- .../types/include/eos/types/AbiSerializer.hpp | 10 +- 2 files changed, 197 insertions(+), 67 deletions(-) diff --git a/libraries/types/AbiSerializer.cpp b/libraries/types/AbiSerializer.cpp index 863592a2d28..09de9db8e60 100644 --- a/libraries/types/AbiSerializer.cpp +++ b/libraries/types/AbiSerializer.cpp @@ -4,10 +4,189 @@ namespace eos { namespace types { + template + inline fc::variant variantFromStream(fc::datastream& stream) { + T temp; + fc::raw::unpack( stream, temp ); + return fc::variant(temp); + } + AbiSerializer::AbiSerializer( const Abi& abi ) { + configureTypes(); setAbi(abi); } + void AbiSerializer::configureTypes() { + + native_types.emplace("UInt8", std::make_pair( []( auto& stream ) -> auto { + return variantFromStream(stream); + }, + []( const fc::variant& var, fc::datastream& ds ){ + fc::raw::pack( ds, var.as() ); + } + )); + + native_types.emplace("UInt16", std::make_pair( []( auto& stream ) -> auto { + return variantFromStream(stream); + }, + []( const fc::variant& var, fc::datastream& ds ){ + fc::raw::pack( ds, var.as() ); + } + )); + + native_types.emplace("UInt32", std::make_pair( []( auto& stream ) -> auto { + return variantFromStream(stream); + }, + []( const fc::variant& var, fc::datastream& ds ){ + fc::raw::pack( ds, var.as() ); + } + )); + + native_types.emplace("UInt64", std::make_pair( + []( auto& stream ) -> auto { + return variantFromStream(stream); + }, + []( const fc::variant& var, fc::datastream& ds ){ + fc::raw::pack( ds, var.as() ); + } + )); + + native_types.emplace("UInt128", std::make_pair( + []( auto& stream ) -> auto { + return variantFromStream(stream); + }, + []( const fc::variant& var, fc::datastream& ds ){ + fc::raw::pack( ds, var.as() ); + } + )); + + native_types.emplace("UInt256", std::make_pair( + []( auto& stream ) -> auto { + return variantFromStream(stream); + }, + []( const fc::variant& var, fc::datastream& ds ){ + fc::raw::pack( ds, var.as() ); + } + )); + + native_types.emplace("Int8", std::make_pair( + []( auto& stream ) -> auto { + return variantFromStream(stream); + }, + []( const fc::variant& var, fc::datastream& ds ){ + fc::raw::pack( ds, var.as() ); + } + )); + + native_types.emplace("Int16", std::make_pair( + []( auto& stream ) -> auto { + return variantFromStream(stream); + }, + []( const fc::variant& var, fc::datastream& ds ){ + fc::raw::pack( ds, var.as() ); + } + )); + + native_types.emplace("Int32", std::make_pair( + []( auto& stream ) -> auto { + return variantFromStream(stream); + }, + []( const fc::variant& var, fc::datastream& ds ){ + fc::raw::pack( ds, var.as() ); + } + )); + + native_types.emplace("Int64", std::make_pair( + []( auto& stream ) -> auto { + return variantFromStream(stream); + }, + []( const fc::variant& var, fc::datastream& ds ){ + fc::raw::pack( ds, var.as() ); + } + )); + + // native_types.emplace("Int128", std::make_pair( + // []( auto& stream ) -> auto { + // return variantFromStream<__int128>(stream); + // }, + // []( const fc::variant& var, fc::datastream& ds ){ + // fc::raw::pack( ds, var.as<__int128>() ); + // } + // )); + + // native_types.emplace("Int256", std::make_pair( + // []( auto& stream ) -> auto { + // return variantFromStream(stream); + // }, + // []( const fc::variant& var, fc::datastream& ds ){ + // fc::raw::pack( ds, var.as() ); + // } + // )); + + native_types.emplace("Name", std::make_pair( + []( auto& stream ) -> auto { + return variantFromStream(stream); + }, + []( const fc::variant& var, fc::datastream& ds ){ + fc::raw::pack( ds, var.as() ); + } + )); + + native_types.emplace("Time", std::make_pair( + []( auto& stream ) -> auto { + return variantFromStream