项目作者: whunmr

项目描述 :
async RPC implemented by async message-passing
高级语言: C++
项目地址: git://github.com/whunmr/msgrpc.git
创建时间: 2017-03-06T07:42:31Z
项目社区:https://github.com/whunmr/msgrpc

开源协议:Apache License 2.0

下载


msgrpc

async RPC implemented by async message-passing

  • using macro to replace thrift IDL, e.g.:
    ```
    namespace cpp org.example.msgrpc.thrift

struct SingleOptionalFieldStruct {
1: optional i16 value,
2: required i64 value64,
}

struct EmbeddedStruct {
1: required byte es_i8,
2: optional i16 es_i16,
}

struct ResponseData {
1: required i32 pet_id,
2: required string pet_name,
3: required i32 pet_weight,
4: required byte pet_i8_value,
5: required i16 pet_i16_value,
6: required i64 pet_i64_value,
7: required double pet_double_value,
8: required bool pet_bool_value,
9: required binary pet_binary_value,
10: required EmbeddedStruct pet_embedded_struct,
11: required list pet_list_i32,
12: required list pet_list_of_struct,
13: optional list pet_list_of_bool,
14: optional set pet_set_of_i32,
15: optional set pet_set_of_struct,
16: optional map pet_map_i32_string,
17: optional map pet_map_string_struct,
}

  1. can be write in msgrpc DSL:

___def_service(demo, 1.0.3) {

  1. #define ___fields_of_struct___SingleOptionalFieldStruct(_, ...) \
  2. _(1, optional, int16_t, value, (comments), __VA_ARGS__)\
  3. _(2, required, int64_t, value64, (comments), __VA_ARGS__)
  4. ___as_struct(SingleOptionalFieldStruct);
  5. #define ___fields_of_struct___EmbeddedStruct(_, ...) \
  6. _(1, required, int8_t, es_i8, (comments), __VA_ARGS__)\
  7. _(2, optional, int16_t, es_i16, (comments), __VA_ARGS__)
  8. ___as_struct(EmbeddedStruct);
  9. typedef std::map <int32_t, std::string> map_int32_string;
  10. typedef std::map <std::string, EmbeddedStruct> map_string_struct;
  11. #define ___fields_of_struct___ResponseData(_, ...) \
  12. _(1, required, int32_t, pet_id, (comments), __VA_ARGS__)\
  13. _(2, required, std::string, pet_name, (comments), __VA_ARGS__)\
  14. _(3, required, int32_t, pet_weight, (comments), __VA_ARGS__)\
  15. _(4, required, int8_t, pet_i8_value, (comments), __VA_ARGS__)\
  16. _(5, required, int16_t, pet_i16_value, (comments), __VA_ARGS__)\
  17. _(6, required, int64_t, pet_i64_value, (comments), __VA_ARGS__)\
  18. _(7, required, double, pet_double_value, (comments), __VA_ARGS__)\
  19. _(8, required, bool, pet_bool_value, (comments), __VA_ARGS__)\
  20. _(9, required, binary, pet_binary_value, (comments), __VA_ARGS__)\
  21. _(10, required, EmbeddedStruct, pet_embedded_struct, (comments), __VA_ARGS__)\
  22. _(11, required, std::vector<int32_t>, pet_list_i32, (comments), __VA_ARGS__)\
  23. _(12, required, std::vector<EmbeddedStruct>, pet_list_of_struct, (comments), __VA_ARGS__)\
  24. _(13, optional, std::vector<bool>, pet_list_of_bool, (comments), __VA_ARGS__)\
  25. _(14, optional, std::set<int32_t>, pet_set_of_i32, (comments), __VA_ARGS__)\
  26. _(15, optional, std::set<EmbeddedStruct>, pet_set_of_struct, (comments), __VA_ARGS__)\
  27. _(16, optional, map_int32_string, pet_map_i32_string, (comments), __VA_ARGS__)\
  28. _(17, optional, map_string_struct, pet_map_string_struct, (comments), __VA_ARGS__)
  29. ___as_struct(ResponseData);
  30. #define ___fields_of_struct___RequestFoo(_, ...) \
  31. _(1, required, int32_t, reqa, (comments), __VA_ARGS__)\
  32. _(2, optional, int32_t, reqb, (comments), __VA_ARGS__)
  33. ___as_struct(RequestFoo);
  34. #define ___fields_of_struct___ResponseBar(_, ...) \
  35. _(1, required, int32_t, rspa, (comments), __VA_ARGS__)\
  36. _(2, optional, int32_t, rspb, (comments), __VA_ARGS__)
  37. ___as_struct(ResponseBar);
  38. #define ___methods_of_interface___InterfaceX(_, ...)\
  39. _(1, ResponseBar, ______sync_x, RequestFoo, (comments), __VA_ARGS__)
  40. ___as_interface(InterfaceX, 1);
  41. #define ___methods_of_interface___InterfaceY(_, ...) \
  42. _(1, ResponseBar, ______sync_y , RequestFoo, (comments), __VA_ARGS__)\
  43. _(2, ResponseBar, _____async_y , RequestFoo, (comments), __VA_ARGS__)\
  44. _(3, ResponseBar, ______sync_y_failed , RequestFoo, (comments), __VA_ARGS__)\
  45. _(4, ResponseBar, ______sync_y_failed_immediately, RequestFoo, (comments), __VA_ARGS__)
  46. ___as_interface(InterfaceY, 2);

}

  1. * type mapping

bool bool
byte int8_t
i16 int16_t
i32 int32_t
i64 int64_t
double double
string std::string
binary binary
list std::vector
set std::set
map std::map
```