<s> import uuid <EOL> import msgpack <EOL> CREATE_NODE = <NUM_LIT:10> <EOL> CREATE_NODE_RESPONSE = <NUM_LIT:11> <EOL> DELETE_NODE = <NUM_LIT:20> <EOL> DELETE_NODE_RESPONSE = <NUM_LIT> <EOL> GET_CHILDREN = <NUM_LIT:30> <EOL> GET_CHILDREN_RESPONSE = <NUM_LIT> <EOL> GET_DATA = <NUM_LIT:50> <EOL> GET_DATA_RESPONSE = <NUM_LIT> <EOL> SET_DATA = <NUM_LIT> <EOL> SET_DATA_RESPONSE = <NUM_LIT> <EOL> NO_OPERATION = <NUM_LIT> <EOL> _READ_COMMANDS = [ GET_CHILDREN , GET_DATA , NO_OPERATION ] <EOL> def build_create_node ( path , data ) : <EOL> command_id = str ( uuid . uuid4 ( ) ) <EOL> create_node = ( CREATE_NODE , command_id , path . encode ( "<STR_LIT:utf8>" ) , <EOL> data . encode ( "<STR_LIT:utf8>" ) ) <EOL> return command_id , msgpack . packb ( create_node ) <EOL> def build_delete_node ( path ) : <EOL> command_id = str ( uuid . uuid4 ( ) ) <EOL> delete_node = ( DELETE_NODE , command_id , path . encode ( "<STR_LIT:utf8>" ) ) <EOL> return command_id , msgpack . packb ( delete_node ) <EOL> def build_get_children ( path ) : <EOL> command_id = str ( uuid . uuid4 ( ) ) <EOL> get_children_request = ( GET_CHILDREN , command_id , path . encode ( "<STR_LIT:utf8>" ) ) <EOL> return command_id , msgpack . packb ( get_children_request ) <EOL> def build_get_data ( path ) : <EOL> command_id = str ( uuid . uuid4 ( ) ) <EOL> get_data_request = ( GET_DATA , command_id , path . encode ( "<STR_LIT:utf8>" ) ) <EOL> return command_id , msgpack . packb ( get_data_request ) <EOL> def build_set_data ( path , data ) : <EOL> command_id = str ( uuid . uuid4 ( ) ) <EOL> set_data = ( SET_DATA , command_id , path . encode ( "<STR_LIT:utf8>" ) , data . encode ( "<STR_LIT:utf8>" ) ) <EOL> return command_id , msgpack . packb ( set_data ) <EOL> def build_no_operation ( ) : <EOL> command_id = str ( uuid . uuid4 ( ) ) <EOL> no_operation = ( NO_OPERATION , command_id ) <EOL> return command_id , msgpack . packb ( no_operation ) <EOL> def is_read_command ( command_type ) : <EOL> return command_type in _READ_COMMANDS <EOL> def build_response ( command_type , command_id , status , * args ) : <EOL> response = ( command_type , command_id , status ) + args <EOL> return msgpack . packb ( response ) <EOL> def decode_command ( command ) : <EOL> decoded_command = msgpack . unpackb ( command , use_list = False ) <EOL> return decoded_command [ <NUM_LIT:0> ] , decoded_command [ <NUM_LIT:1> ] , decoded_command [ <NUM_LIT:2> : ] </s>
