Electroneum
Loading...
Searching...
No Matches
epee::levin Namespace Reference

Classes

struct  bucket_head
struct  bucket_head2
struct  levin_commands_handler
class  levin_client_impl
class  levin_client_impl2
class  levin_client_async
struct  protocl_handler_config
class  protocol_handler
class  async_protocol_handler
class  async_protocol_handler_config

Functions

const char * get_err_descr (int err)
template<class t_struct>
bool pack_struct_to_levin_message (const t_struct &t, std::string &buff, int command_id)
bool pack_data_to_levin_message (const std::string &data, std::string &buff, int command_id)
bool load_levin_data_from_levin_message (std::string &levin_data, const std::string &buff, int &command)
template<class t_struct>
bool load_struct_from_levin_message (t_struct &t, const std::string &buff, int &command)

Function Documentation

◆ get_err_descr()

const char * epee::levin::get_err_descr ( int err)
inline

Definition at line 104 of file levin_base.h.

105 {
106 switch(err)
107 {
116 default:
117 return "unknown code";
118 }
119 }
#define DESCRIBE_RET_CODE(code)
Definition levin_base.h:102
#define LEVIN_ERROR_CONNECTION
Definition levin_base.h:94
#define LEVIN_ERROR_CONNECTION_NO_DUPLEX_PROTOCOL
Definition levin_base.h:98
#define LEVIN_OK
Definition levin_base.h:93
#define LEVIN_ERROR_CONNECTION_DESTROYED
Definition levin_base.h:96
#define LEVIN_ERROR_CONNECTION_HANDLER_NOT_DEFINED
Definition levin_base.h:99
#define LEVIN_ERROR_CONNECTION_NOT_FOUND
Definition levin_base.h:95
#define LEVIN_ERROR_FORMAT
Definition levin_base.h:100
#define LEVIN_ERROR_CONNECTION_TIMEDOUT
Definition levin_base.h:97

◆ load_levin_data_from_levin_message()

bool epee::levin::load_levin_data_from_levin_message ( std::string & levin_data,
const std::string & buff,
int & command )

Definition at line 82 of file levin_helper.h.

83 {
84 if(buff.size() < sizeof(levin::bucket_head) )
85 {
86 LOG_PRINT_L3("size of buff(" << buff.size() << ") is too small, at load_struct_from_levin_message");
87 return false;
88 }
89
90#if BYTE_ORDER == LITTLE_ENDIAN
92#else
94 head.m_signature = SWAP64LE(head.m_signature);
95 head.m_cb = SWAP64LE(head.m_cb);
96 head.m_command = SWAP32LE(head.m_command);
97 head.m_return_code = SWAP32LE(head.m_return_code);
98 head.m_reservedA = SWAP32LE(head.m_reservedA);
99 head.m_reservedB = SWAP32LE(head.m_reservedB);
100#endif
101 if(head.m_signature != LEVIN_SIGNATURE)
102 {
103 LOG_PRINT_L3("Failed to read signature in levin message, at load_struct_from_levin_message");
104 return false;
105 }
106 if(head.m_cb != buff.size()-sizeof(levin::bucket_head))
107 {
108 LOG_PRINT_L3("sizes mismatch, at load_struct_from_levin_message");
109 return false;
110 }
111
112 //std::string buff_strg;
113 levin_data.assign(&buff[sizeof(levin::bucket_head)], buff.size()-sizeof(levin::bucket_head));
114 command = head.m_command;
115 return true;
116 }
#define SWAP64LE
Definition int-util.h:232
#define SWAP32LE
Definition int-util.h:224
#define LEVIN_SIGNATURE
Definition levin_base.h:34
#define LOG_PRINT_L3(x)
struct rule_list head

◆ load_struct_from_levin_message()

template<class t_struct>
bool epee::levin::load_struct_from_levin_message ( t_struct & t,
const std::string & buff,
int & command )

Definition at line 119 of file levin_helper.h.

120 {
121 if(buff.size() < sizeof(levin::bucket_head) )
122 {
123 LOG_ERROR("size of buff(" << buff.size() << ") is too small, at load_struct_from_levin_message");
124 return false;
125 }
126
127#if BYTE_ORDER == LITTLE_ENDIAN
129#else
131 head.m_signature = SWAP64LE(head.m_signature);
132 head.m_cb = SWAP64LE(head.m_cb);
133 head.m_command = SWAP32LE(head.m_command);
134 head.m_return_code = SWAP32LE(head.m_return_code);
135 head.m_reservedA = SWAP32LE(head.m_reservedA);
136 head.m_reservedB = SWAP32LE(head.m_reservedB);
137#endif
138 if(head.m_signature != LEVIN_SIGNATURE)
139 {
140 LOG_ERROR("Failed to read signature in levin message, at load_struct_from_levin_message");
141 return false;
142 }
143 if(head.m_cb != buff.size()-sizeof(levin::bucket_head))
144 {
145 LOG_ERROR("sizes mismatch, at load_struct_from_levin_message");
146 return false;
147 }
148
149 std::string buff_strg;
150 buff_strg.assign(&buff[sizeof(levin::bucket_head)], buff.size()-sizeof(levin::bucket_head));
151
152 if(!StorageNamed::load_struct_from_storage_buff_t<t_struct, StorageNamed::DefaultStorageType>(t, buff_strg))
153 {
154 LOG_ERROR("Failed to read storage, at load_struct_from_levin_message");
155 return false;
156 }
157 command = head.m_command;
158 return true;
159 }
#define LOG_ERROR(x)
Definition misc_log_ex.h:98

◆ pack_data_to_levin_message()

bool epee::levin::pack_data_to_levin_message ( const std::string & data,
std::string & buff,
int command_id )

Definition at line 65 of file levin_helper.h.

66 {
67 buff.resize(sizeof(levin::bucket_head));
69 head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
70 head.m_cb = 0;
71 head.m_have_to_return_data = true;
72 head.m_command = SWAP32LE(command_id);
73 head.m_return_code = SWAP32LE(1);
74 head.m_reservedA = rand(); //probably some flags in future
75 head.m_reservedB = rand(); //probably some check summ in future
76
77 head.m_cb = SWAP64LE(data.size());
78 buff.append(data);
79 return true;
80 }

◆ pack_struct_to_levin_message()

template<class t_struct>
bool epee::levin::pack_struct_to_levin_message ( const t_struct & t,
std::string & buff,
int command_id )

Definition at line 43 of file levin_helper.h.

44 {
45 buff.resize(sizeof(levin::bucket_head));
47 head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
48 head.m_cb = 0;
49 head.m_have_to_return_data = true;
50 head.m_command = SWAP32LE(command_id);
51 head.m_return_code = SWAP32LE(1);
52 head.m_reservedA = rand(); //probably some flags in future
53 head.m_reservedB = rand(); //probably some check summ in future
54
55 std::string buff_strg;
56 if(!StorageNamed::save_struct_as_storage_to_buff_t<t_struct, StorageNamed::DefaultStorageType>(t, buff_strg))
57 return false;
58
59 head.m_cb = SWAP64LE(buff_strg.size());
60 buff.append(buff_strg);
61 return true;
62 }