diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m index 1b046845cef3690f6d0eef42644b5149048e8a7c..4a2372e24089a812768b646022b4abaaf3495ef3 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.m +++ b/src/objective-c/ProtoRPC/ProtoRPC.m @@ -33,7 +33,10 @@ #import "ProtoRPC.h" +#import <ProtocolBuffers/ProtocolBuffers.h> #import <RxLibrary/GRXWriteable.h> +#import <RxLibrary/GRXWriter.h> +#import <RxLibrary/GRXWriter+Transformations.h> @implementation ProtoRPC { id<GRXWriteable> _responseWriteable; @@ -60,7 +63,13 @@ [NSException raise:NSInvalidArgumentException format:@"A protobuf class to parse the responses must be provided."]; } - if ((self = [super initWithHost:host method:method requestsWriter:requestsWriter])) { + // A writer that serializes the proto messages to send. + id<GRXWriter> bytesWriter = + [[[GRXWriter alloc] initWithWriter:requestsWriter] map:^id(PBGeneratedMessage *proto) { + return [proto data]; + }]; + if ((self = [super initWithHost:host method:method requestsWriter:bytesWriter])) { + // A writeable that parses the proto messages received. _responseWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { [responsesWriteable didReceiveValue:[responseClass parseFromData:value]]; } completionHandler:^(NSError *errorOrNil) { @@ -76,6 +85,7 @@ - (void)startWithWriteable:(id<GRXWriteable>)writeable { [super startWithWriteable:writeable]; + // Break retain cycles. _responseWriteable = nil; } @end