Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ruby.h>
- #include "riakclient.pb-c.h"
- #include <arpa/inet.h>
- static VALUE cRiakClient;
- static VALUE cProtocolBuffersBackend;
- static VALUE mProtobufC;
- // Converts a Ruby string into a PBC Binary
- #define STR2PBCBIN(string,bin) do { \
- bin.len = RSTRING_LEN(string); \
- bin.data = (uint8_t*)rb_string_value_cstr(&string); \
- } while(0)
- #define PBCBIN2STR(bin) rb_str_new((char*)bin.data, (long)bin.len)
- // Adds the Riak message header/prologue to the buffer
- #define ADDPROLOG(code,pblen,buf) do { \
- ((uint32_t*)buf)[0] = htonl((uint32_t)pblen+1); \
- buf[4] = (uint8_t)(code & 0xFF); \
- } while(0)
- // Size of the message with prologue
- #define PBCSIZE(size) size+5
- #define PBCMSGOFFSET(size) size+5
- // Shortcuts for Ruby socket methods
- #define GET_SOCKET VALUE socket = rb_ivar_get(self, rb_intern("@socket"))
- #define WRITE_SOCKET(__val) rb_funcall(socket, rb_intern("write"), 1, __val)
- #define READ_SOCKET(__len) rb_funcall(socket, rb_intern("read"), 1, INT2NUM(__len))
- #define UREAD_SOCKET(__len) rb_funcall(socket, rb_intern("read"), 1, UINT2NUM(__len))
- // Shortcuts for body-less requests
- //#define PING_REQ_AS_STR rb_str_new("\x00\x00\x00\x01\x01",5)
- enum RpbMessageCodes {
- ERROR,
- PING_REQ,
- PING_RES,
- GET_CLIENT_ID_REQ,
- GET_CLIENT_ID_RES,
- SET_CLIENT_ID_REQ,
- SET_CLIENT_ID_RES,
- GET_SERVER_INFO_REQ,
- GET_SERVER_INFO_RES,
- GET_REQ,
- GET_RES,
- PUT_REQ,
- PUT_RES,
- DEL_REQ,
- DEL_RES,
- LIST_BUCKETS_REQ,
- LIST_BUCKETS_RES,
- LIST_KEYS_REQ,
- LIST_KEYS_RES,
- GET_BUCKET_REQ,
- GET_BUCKET_RES,
- SET_BUCKET_REQ,
- SET_BUCKET_RES,
- MAPRED_REQ,
- MAPRED_RES
- };
- // Memory allocator for protobuf-c
- void ruby_pbc_out_of_memory();
- void *ruby_pbc_alloc(void *, size_t);
- void ruby_pbc_free(void *, void *);
- // Decoders
- VALUE rpb_decode_response(VALUE);
- VALUE rpb_decode_error_resp(uint8_t*, uint32_t);
- VALUE rpb_decode_get_bucket_resp(uint8_t*, uint32_t);
- // Encoders
- VALUE rpb_encode_get_bucket_req(VALUE);
- // Complete requests
- VALUE rpb_ping(VALUE);
- VALUE rpb_get_bucket(VALUE, VALUE);
Add Comment
Please, Sign In to add comment