#pragma once #include #include "rpc_streams.h" #include "paatti.pb.h" typedef enum { RPC_OK = 0, RPC_ENCODE_FAILED = 1, // Encode failed before any data has been written RPC_PACKET_TOO_LARGE = 2, // Packet is too large to send RPC_MIDWAY_ERROR = 3 // Encode failed midway through, should close connection } rpc_result_t; // Serialize the given response message and send it. rpc_result_t rpc_sendpacket(rpc_ostream_t *stream, RPCCommand msgtype, const pb_field_t *fields, void *msg); // Serialize the given response message and send it. // Note: only for success messages. // Returns false if write fails, which means that the connection has // probably been closed. bool rpc_response(rpc_ostream_t *stream, RPCCommand msgtype, const pb_field_t *fields, void *msg); // This can be used for commands where empty response is valid. bool rpc_response_empty(rpc_ostream_t *stream, RPCCommand msgtype); // Send an error response. bool rpc_error(rpc_ostream_t *stream, ErrorResponse *error); // Send a protocol or resources error with the specified error message bool rpc_error_protocol(rpc_ostream_t *stream, const char *message); bool rpc_error_resources(rpc_ostream_t *stream, const char *message);