protorpc.h 794 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef HV_PROTO_RPC_H_
  2. #define HV_PROTO_RPC_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. // flags:1byte + length:4bytes = 5bytes
  7. #define PROTORPC_HEAD_LENGTH 5
  8. typedef struct {
  9. unsigned char flags;
  10. unsigned int length;
  11. } protorpc_head;
  12. typedef const char* protorpc_body;
  13. typedef struct {
  14. protorpc_head head;
  15. protorpc_body body;
  16. } protorpc_message;
  17. static inline unsigned int protorpc_package_length(const protorpc_head* head) {
  18. return PROTORPC_HEAD_LENGTH + head->length;
  19. }
  20. // @retval >0 package_length, <0 error
  21. int protorpc_pack(const protorpc_message* msg, void* buf, int len);
  22. // @retval >0 package_length, <0 error
  23. int protorpc_unpack(protorpc_message* msg, const void* buf, int len);
  24. #ifdef __cplusplus
  25. } // extern "C"
  26. #endif
  27. #endif // HV_PROTO_RPC_H_