Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions platonlib/include/platon/txencode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@

#include <boost/endian/conversion.hpp>
#include "RLP.h"
#include <type_traits>
/**
* @brief Transaction coding operation
*
*/
namespace platon {
namespace platon{

/**
* @brief Specified type encoding
*
* @param stream RLP stream
* @param d int8_t type
*/
inline void txEncode(RLPStream &stream, int8_t d){
inline void txEncodeValue(RLPStream &stream, int8_t d){
d = boost::endian::endian_reverse(d);

bytesConstRef ref((byte*)&d, sizeof(d));
Expand All @@ -31,7 +32,7 @@ namespace platon {
* @param stream RLP stream
* @param d uint16_t type
*/
inline void txEncode(RLPStream &stream, uint16_t d){
inline void txEncodeValue(RLPStream &stream, uint16_t d){
d = boost::endian::endian_reverse(d);

bytesConstRef ref((byte*)&d, sizeof(d));
Expand All @@ -44,7 +45,7 @@ namespace platon {
* @param stream RLP stream
* @param d int16_t type
*/
inline void txEncode(RLPStream &stream, int16_t d){
inline void txEncodeValue(RLPStream &stream, int16_t d){
d = boost::endian::endian_reverse(d);

bytesConstRef ref((byte*)&d, sizeof(d));
Expand All @@ -57,7 +58,7 @@ namespace platon {
* @param stream RLP stream
* @param d uint32_t type
*/
inline void txEncode(RLPStream &stream, uint32_t d){
inline void txEncodeValue(RLPStream &stream, uint32_t d){
d = boost::endian::endian_reverse(d);

bytesConstRef ref((byte*)&d, sizeof(d));
Expand All @@ -70,35 +71,33 @@ namespace platon {
* @param stream RLP stream
* @param d int32_t type
*/
inline void txEncode(RLPStream &stream, int32_t d){
inline void txEncodeValue(RLPStream &stream, int32_t d){
d = boost::endian::endian_reverse(d);

bytesConstRef ref((byte*)&d, sizeof(d));
stream.append(ref);
}

#ifdef WASM_COMPILE
/**
* @brief Specified type encoding
*
* @param stream RLP stream
* @param d int type
*/
inline void txEncode(RLPStream &stream, int d){
inline void txEncodeValue(RLPStream &stream, int d){
d = boost::endian::endian_reverse((int32_t)d);

bytesConstRef ref((byte*)&d, sizeof(d));
stream.append(ref);
}
#endif

/**
* @brief Specified type encoding
*
* @param stream RLP stream
* @param d uint64_t type
*/
inline void txEncode(RLPStream &stream, uint64_t d){
inline void txEncodeValue(RLPStream &stream, uint64_t d){
d = boost::endian::endian_reverse(d);

bytesConstRef ref((byte*)&d, sizeof(d));
Expand All @@ -111,7 +110,7 @@ namespace platon {
* @param stream RLP stream
* @param d int64_t type
*/
inline void txEncode(RLPStream &stream, int64_t d){
inline void txEncodeValue(RLPStream &stream, int64_t d){
d = boost::endian::endian_reverse(d);

bytesConstRef ref((byte*)&d, sizeof(d));
Expand All @@ -124,7 +123,7 @@ namespace platon {
* @param stream RLP stream
* @param d std::string type
*/
inline void txEncode(RLPStream &stream, const std::string & d){
inline void txEncodeValue(RLPStream &stream, const std::string d){
stream.append(d);
}

Expand All @@ -134,7 +133,7 @@ namespace platon {
* @param stream RLP stream
* @param d Char pointer type
*/
inline void txEncode(RLPStream &stream, const char *d){
inline void txEncodeValue(RLPStream &stream, const char *d){
stream.append(std::string(d));
}

Expand All @@ -143,10 +142,13 @@ namespace platon {
*
* @param stream
*/
inline void txEncode(RLPStream &stream){
inline void txEncodeValue(RLPStream &stream){
}


template <typename T>
inline void txEncode(RLPStream &stream,T arg){
txEncodeValue(stream,arg);
}

/**
* @brief Serialize to RLPStream
Expand All @@ -159,7 +161,7 @@ namespace platon {
*/
template<typename Arg, typename... Args>
void txEncode(RLPStream &stream, Arg&& a, Args&&... args ) {
txEncode(stream, a);
txEncodeValue(stream, a);
txEncode(stream, args...);
}
}