Created
October 14, 2010 01:49
-
-
Save sgonyea/625386 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MessageCodes.h | |
// riak_pb-objc | |
// | |
// Created by Scott Gonyea on 8/30/10. | |
// Copyright (c) 2010 Inherently Lame, Inc. All rights reserved. | |
// | |
#ifndef _PABST_MC_ | |
# define _PABST_MC_ | |
/* */ | |
# define Serialize_Request(message, request) (message.SerializeToArray(request + 1, sizeof( char ))) | |
# define CStr_End_With_Nil(request, length) (request[ length-1 ] = nil) | |
/* Message/Packet Headers */ | |
# define MESSAGE_LENGTH_SIZE 4 | |
# define MESSAGE_CODE_SIZE 1 | |
# define MESSAGE_PAD_SIZE MESSAGE_LENGTH_SIZE + MESSAGE_CODE_SIZE | |
/* Some random stuff needing a better description */ | |
# define EMPTY_MESSAGE_SIZE 1 | |
/* Message Codes */ | |
# define MC_ERROR_RESPONSE 0 | |
# define MC_PING_REQUEST 1 | |
# define MC_PING_RESPONSE 2 | |
# define MC_GET_CLIENT_ID_REQUEST 3 | |
# define MC_GET_CLIENT_ID_RESPONSE 4 | |
# define MC_SET_CLIENT_ID_REQUEST 5 | |
# define MC_SET_CLIENT_ID_RESPONSE 6 | |
# define MC_GET_SERVER_INFO_REQUEST 7 | |
# define MC_GET_SERVER_INFO_RESPONSE 8 | |
# define MC_GET_REQUEST 9 | |
# define MC_GET_RESPONSE 10 | |
# define MC_PUT_REQUEST 11 | |
# define MC_PUT_RESPONSE 12 | |
# define MC_DEL_REQUEST 13 | |
# define MC_DEL_RESPONSE 14 | |
# define MC_LIST_BUCKETS_REQUEST 15 | |
# define MC_LIST_BUCKETS_RESPONSE 16 | |
# define MC_LIST_KEYS_REQUEST 17 | |
# define MC_LIST_KEYS_RESPONSE 18 | |
# define MC_GET_BUCKET_REQUEST 19 | |
# define MC_GET_BUCKET_RESPONSE 20 | |
# define MC_SET_BUCKET_REQUEST 21 | |
# define MC_SET_BUCKET_RESPONSE 22 | |
# define MC_MAP_REDUCE_REQUEST 23 | |
# define MC_MAP_REDUCE_RESPONSE 24 | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "rb_pabst.h" | |
VALUE rb_list_keys_request(VALUE self, VALUE bucket_name) { | |
RiakProtobuf *riakpb = Get_RiakProtobuf(self); | |
char *request = nil; | |
OFString *bucket; | |
VALUE rb_request; | |
// @TODO: Ensure that 'bucket_name' is a String, or call :to_s. Raise intelligent exception if that fails | |
// @TODO: Figure out how to get the encoding of the String. Assumption is a UTF-8 encoding, for now. | |
bucket = [OFString stringWithCString:RSTRING_PTR(bucket_name) | |
length:RSTRING_LEN(bucket_name)]; | |
[riakpb listKeysRequest:request bucket:bucket]; | |
rb_request = rb_str_new2(request); | |
return rb_request; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// rb_riakpb.m | |
// riak_pb-objc | |
// | |
// Created by Scott Gonyea on 9/1/10. | |
// Copyright (c) 2010 Inherently Lame, Inc. All rights reserved. | |
// | |
#import "rb_riakpb.h" | |
VALUE rb_mRiakpb = Qnil; | |
VALUE rb_cPabst = Qnil; | |
OFAutoreleasePool *pool = nil; | |
void Init_Riakpb() { | |
rb_mRiakpb = rb_define_module("Riakpb"); | |
rb_cPabst = rb_define_class_under(rb_mRiakpb, "Pabst", rb_cObject); | |
rb_define_alloc_func(rb_cPabst, pabst_allocate); | |
rb_define_method(rb_cPabst, "initialize", pabst_initialize, 0); | |
rb_define_method(rb_cPabst, "list_keys_request", rb_list_keys_request, 1); | |
} | |
VALUE pabst_allocate(VALUE klass) { | |
RiakProtobuf *riakpb; | |
pool = [OFAutoreleasePool alloc]; | |
riakpb = [RiakProtobuf alloc]; | |
return Data_Wrap_Struct(klass, pabst_mark, pabst_free, riakpb); | |
} | |
VALUE pabst_initialize(VALUE self) { | |
RiakProtobuf *riakpb = Get_RiakProtobuf(self); | |
[pool init]; | |
[riakpb init]; | |
return self; | |
} | |
void pabst_mark(RiakProtobuf *self) { | |
/* Nothing to do, right now */ | |
} | |
void pabst_free(RiakProtobuf *self) { | |
[self release]; | |
[pool release]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RiakProtobuf.h | |
// riak_pb-objc | |
// | |
// Created by Scott Gonyea on 9/1/10. | |
// Copyright (c) 2010 Inherently Lame Inc. All rights reserved. | |
// | |
#import <ObjFW/ObjFW.h> | |
#import <stdint.h> | |
#import "MessageCodes.h" | |
@interface RiakProtobuf : OFObject { | |
@private | |
} | |
- (id)init; | |
- (void)dealloc; | |
- (OFDictionary *)errorResponse:(char *)response; | |
// Message Code Only | |
- (void)pingRequest; | |
- (BOOL)pingResponse; // Message Code Only | |
// Message Code Only | |
- (void)getClientIdRequest; | |
- (uint32_t)getClientIdResponse:(char *)response; | |
- (void)setClientIdRequest:(char *)request clientId:(uint32_t)clientId; | |
- (BOOL)setClientIdResponse; // Message Code Only | |
// Message Code Only | |
- (void)getServerInfoRequest; | |
- (OFDictionary *)getServerInfoResponse:(char *)response; | |
- (void)getRequest:(char *)request bucket:(OFString *)bucket key:(OFString *)key; | |
- (void)getRequest:(char *)request bucket:(OFString *)bucket key:(OFString *)key quorum:(uint32_t)quorum; | |
- (OFDictionary *)getResponse:(char *)response; | |
- (void)putRequest:(char *)request bucket:(OFString *)bucket key:(OFString *)key content:(OFDictionary *)content withBody:(BOOL)body; | |
- (void)putRequest:(char *)request bucket:(OFString *)bucket key:(OFString *)key content:(OFDictionary *)content withBody:(BOOL)body quorum:(uint32_t)quorum commit:(uint32_t)commit; | |
- (OFDictionary *)putResponse:(char *)response; | |
- (void)delRequest:(char *)request bucket:(OFString *)bucket key:(OFString *)key; | |
- (void)delRequest:(char *)request bucket:(OFString *)bucket key:(OFString *)key replicas:(uint32_t)replicas; | |
- (BOOL)delResponse; // Message Code Only | |
// Message Code Only | |
- (void)listBucketsRequest; | |
- (OFArray *)listBucketsResponse:(char *)response; | |
- (void)listKeysRequest:(char *)request bucket:(OFString *)bucket; | |
- (OFArray *)listKeysResponse: (char *)response; | |
- (void)getBucketRequest:(char *)request bucket:(OFString *)bucket; | |
- (OFDictionary *)getBucketResponse:(char *)response; | |
- (void)setBucketRequest:(char *)request bucket:(OFString *)bucket nVal:(uint32_t)nVal isMult:(BOOL)isMult; | |
- (BOOL)setBucketResponse; // Message Code Only | |
- (void)mapReduceRequest:(char *)request bucket:(OFString *)bucket contentType:(OFString *)contentType; | |
- (OFDictionary *)mapReduceResponse:(char *)response; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RiakProtobuf.m | |
// riak_pb-objc | |
// | |
// Created by Scott Gonyea on 9/1/10. | |
// Copyright (c) 2010 Inherently Lame, Inc. All rights reserved. | |
// | |
#import "riakclient.pb.h" | |
extern "C" { | |
# import "RiakProtobuf.h" | |
} | |
@implementation RiakProtobuf | |
- (id)init { | |
if ((self = [super init])) { | |
// Initialization code here. | |
} | |
return self; | |
} | |
- (void)dealloc { | |
// Clean-up code here. | |
google::protobuf::ShutdownProtobufLibrary(); | |
[super dealloc]; | |
} | |
- (void)listKeysRequest:(char *)request bucket:(OFString *)bucket { | |
RpbListKeysReq pbMsg; | |
int reqSize; | |
pbMsg.set_bucket([bucket cString]); | |
// message code message \0 (nil) term. | |
reqSize = (int)sizeof(uint8_t) + pbMsg.ByteSize() + 1; | |
request = new char [reqSize]; | |
*request = (char)MC_LIST_KEYS_REQUEST; | |
Serialize_Request(pbMsg, request); | |
CStr_End_With_Nil(request, reqSize); | |
delete &pbMsg; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment