jsonrpc.h 695 B

123456789101112131415161718192021222324252627
  1. #ifndef HV_JSON_RPC_H_
  2. #define HV_JSON_RPC_H_
  3. // flags:1byte + length:4bytes = 5bytes
  4. #define JSONRPC_HEAD_LENGTH 5
  5. typedef struct {
  6. unsigned char flags;
  7. unsigned int length;
  8. } jsonrpc_head;
  9. typedef const char* jsonrpc_body;
  10. typedef struct {
  11. jsonrpc_head head;
  12. jsonrpc_body body;
  13. } jsonrpc_message;
  14. static inline unsigned int jsonrpc_package_length(const jsonrpc_head* head) {
  15. return JSONRPC_HEAD_LENGTH + head->length;
  16. }
  17. // @retval >0 package_length, <0 error
  18. int jsonrpc_pack(const jsonrpc_message* msg, void* buf, int len);
  19. // @retval >0 package_length, <0 error
  20. int jsonrpc_unpack(jsonrpc_message* msg, const void* buf, int len);
  21. #endif // HV_JSON_RPC_H_