/* * protocol.cpp * * Created on: 28.11.2010 * Author: msloup */ #include #include #include "store.h" #include "protocol.h" struct protocol_header create_header(char operation, int count) { return create_header(operation, count, 0); } struct protocol_header create_header(char operation, int count, int client_id) { struct protocol_header header; header.operation = operation; header.count = htons(count); header.client_id = htonl(client_id); struct timeval curr_time; gettimeofday(&curr_time, NULL); header.send_at_sec = htonl(curr_time.tv_sec); header.send_at_usec = htonl(curr_time.tv_usec); return header; } struct item protocol_item_to_item(struct protocol_item source) { struct item destination; destination.value = ntohl(source.value); destination.ts = ntohl(source.ts); return destination; } struct protocol_item item_to_protocol_item(int index, struct item source) { struct protocol_item destination; destination.index = htonl(index); destination.value = htonl(source.value); destination.ts = htonl(source.ts); return destination; } int protocol_item_index(struct protocol_item source) { return ntohl(source.index); }