-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made changes necessary to serialize/deserialize ABI (for EOSIO/eos#354):
* Modularized `intialize_types` to allow more than one subset of the types available to the program to be initialized into their own ABI. This was needed to bootstrap serializing the ABI itself, but also will be helpful in later unit tests. * Changed deserializer for custom builtins to use conversion constructor (and copy/move assignment operator) rather than the custom assignment operator I was initially using to allow the same code to work with enumerations as well. * Added support to reflect pairs/tuples which are just treated as structs (using mangled C++ type name) with anonymous fields (in ABI the fields are named f0, f1, ... ). * With the above changes, I had the necessary tools to reflect `ABI`. Now the `ABI` struct is reflected with the same type system which it can describe, and so a serialized version of a contracts ABI can be included in a transaction (as a possible alternative to using `fc::pack` and `fc::unpack`). I also demonstrated constructing the `types_manager` from a serialized ABI by modifying the `reflection_test1` example.
- Loading branch information
Showing
13 changed files
with
429 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,11 @@ | ||
#pragma once | ||
|
||
#include <eos/types/type_id.hpp> | ||
#include <string> | ||
#include <vector> | ||
#include <utility> | ||
|
||
namespace eos { namespace types { | ||
|
||
using std::string; | ||
using std::vector; | ||
using std::pair; | ||
|
||
struct ABI | ||
{ | ||
enum type_specification : uint8_t | ||
{ | ||
struct_type, | ||
array_type, | ||
vector_type, | ||
optional_type, | ||
variant_type | ||
}; | ||
|
||
struct type_definition | ||
{ | ||
uint32_t first; | ||
int32_t second; | ||
type_specification ts; | ||
}; | ||
|
||
struct struct_t | ||
{ | ||
string name; | ||
vector<pair<string, type_id>> fields; | ||
vector<int16_t> sort_order; | ||
}; | ||
|
||
struct table_index | ||
{ | ||
type_id key_type; | ||
bool unique; | ||
bool ascending; | ||
vector<uint16_t> mapping; | ||
}; | ||
|
||
struct table | ||
{ | ||
type_id::index_t object_index; | ||
vector<table_index> indices; | ||
}; | ||
|
||
|
||
vector<type_definition> types; | ||
vector<struct_t> structs; | ||
vector<type_id> variant_cases; | ||
vector<table> tables; | ||
}; | ||
|
||
} } | ||
|
||
/* | ||
EOS_TYPES_REFLECT_STRUCT( type_definition, (first)(second)(ts) ); | ||
EOS_TYPES_REFLECT_STRUCT( struct_t, (name)(fields)(sort_order) ); | ||
EOS_TYPES_REFLECT_STRUCT( table_index, (key_type)(unique)(ascending)(mapping) ); | ||
EOS_TYPES_REFLECT_STRUCT( table, (name)(object_index)(indices) ); | ||
EOS_TYPES_REFLECT_STRUCT( ABI, (types)(structs)(variant_cases)(tables) ); | ||
*/ | ||
#include <eos/types/abi_definition.hpp> | ||
#include <eos/types/reflect.hpp> | ||
|
||
EOS_TYPES_REFLECT_BUILTIN( eos::types::ABI::type_specification, builtin_uint8 ) | ||
EOS_TYPES_REFLECT_STRUCT( eos::types::ABI::type_definition, (first)(second)(ts) ) | ||
EOS_TYPES_REFLECT_STRUCT( eos::types::ABI::struct_t, (name)(fields)(sort_order) ) | ||
EOS_TYPES_REFLECT_STRUCT( eos::types::ABI::table_index, (key_type)(unique)(ascending)(mapping) ) | ||
EOS_TYPES_REFLECT_STRUCT( eos::types::ABI::table, (object_index)(indices) ) | ||
EOS_TYPES_REFLECT_STRUCT( eos::types::ABI, (types)(structs)(variant_cases)(tables) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#pragma once | ||
|
||
#include <eos/types/abi.hpp> | ||
#include <eos/types/abi_definition.hpp> | ||
|
||
#include <set> | ||
#include <map> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#include <eos/types/type_id.hpp> | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <utility> | ||
|
||
namespace eos { namespace types { | ||
|
||
using std::string; | ||
using std::vector; | ||
using std::pair; | ||
|
||
struct ABI | ||
{ | ||
enum type_specification : uint8_t | ||
{ | ||
struct_type, | ||
array_type, | ||
vector_type, | ||
optional_type, | ||
variant_type | ||
}; | ||
|
||
struct type_definition | ||
{ | ||
uint32_t first; | ||
int32_t second; | ||
type_specification ts; | ||
}; | ||
|
||
struct struct_t | ||
{ | ||
string name; | ||
vector<pair<string, type_id>> fields; | ||
vector<int16_t> sort_order; | ||
}; | ||
|
||
struct table_index | ||
{ | ||
type_id key_type; | ||
bool unique; | ||
bool ascending; | ||
vector<uint16_t> mapping; | ||
}; | ||
|
||
struct table | ||
{ | ||
type_id::index_t object_index; | ||
vector<table_index> indices; | ||
}; | ||
|
||
|
||
vector<type_definition> types; | ||
vector<struct_t> structs; | ||
vector<type_id> variant_cases; | ||
vector<table> tables; | ||
}; | ||
|
||
} } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.