Guest User

Untitled

a guest
Jun 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #include <ruby.h>
  2. #include "riakclient.pb-c.h"
  3. #include <arpa/inet.h>
  4.  
  5. static VALUE cRiakClient;
  6. static VALUE cProtocolBuffersBackend;
  7. static VALUE mProtobufC;
  8.  
  9. // Converts a Ruby string into a PBC Binary
  10. #define STR2PBCBIN(string,bin) do { \
  11. bin.len = RSTRING_LEN(string); \
  12. bin.data = (uint8_t*)rb_string_value_cstr(&string); \
  13. } while(0)
  14.  
  15. #define PBCBIN2STR(bin) rb_str_new((char*)bin.data, (long)bin.len)
  16.  
  17. // Adds the Riak message header/prologue to the buffer
  18. #define ADDPROLOG(code,pblen,buf) do { \
  19. ((uint32_t*)buf)[0] = htonl((uint32_t)pblen+1); \
  20. buf[4] = (uint8_t)(code & 0xFF); \
  21. } while(0)
  22.  
  23. // Size of the message with prologue
  24. #define PBCSIZE(size) size+5
  25. #define PBCMSGOFFSET(size) size+5
  26.  
  27. // Shortcuts for Ruby socket methods
  28. #define GET_SOCKET VALUE socket = rb_ivar_get(self, rb_intern("@socket"))
  29. #define WRITE_SOCKET(__val) rb_funcall(socket, rb_intern("write"), 1, __val)
  30. #define READ_SOCKET(__len) rb_funcall(socket, rb_intern("read"), 1, INT2NUM(__len))
  31. #define UREAD_SOCKET(__len) rb_funcall(socket, rb_intern("read"), 1, UINT2NUM(__len))
  32.  
  33. // Shortcuts for body-less requests
  34. //#define PING_REQ_AS_STR rb_str_new("\x00\x00\x00\x01\x01",5)
  35.  
  36. enum RpbMessageCodes {
  37. ERROR,
  38. PING_REQ,
  39. PING_RES,
  40. GET_CLIENT_ID_REQ,
  41. GET_CLIENT_ID_RES,
  42. SET_CLIENT_ID_REQ,
  43. SET_CLIENT_ID_RES,
  44. GET_SERVER_INFO_REQ,
  45. GET_SERVER_INFO_RES,
  46. GET_REQ,
  47. GET_RES,
  48. PUT_REQ,
  49. PUT_RES,
  50. DEL_REQ,
  51. DEL_RES,
  52. LIST_BUCKETS_REQ,
  53. LIST_BUCKETS_RES,
  54. LIST_KEYS_REQ,
  55. LIST_KEYS_RES,
  56. GET_BUCKET_REQ,
  57. GET_BUCKET_RES,
  58. SET_BUCKET_REQ,
  59. SET_BUCKET_RES,
  60. MAPRED_REQ,
  61. MAPRED_RES
  62. };
  63.  
  64. // Memory allocator for protobuf-c
  65. void ruby_pbc_out_of_memory();
  66. void *ruby_pbc_alloc(void *, size_t);
  67. void ruby_pbc_free(void *, void *);
  68.  
  69. // Decoders
  70. VALUE rpb_decode_response(VALUE);
  71. VALUE rpb_decode_error_resp(uint8_t*, uint32_t);
  72. VALUE rpb_decode_get_bucket_resp(uint8_t*, uint32_t);
  73.  
  74. // Encoders
  75. VALUE rpb_encode_get_bucket_req(VALUE);
  76.  
  77. // Complete requests
  78. VALUE rpb_ping(VALUE);
  79. VALUE rpb_get_bucket(VALUE, VALUE);
Add Comment
Please, Sign In to add comment