anchor.diff:  %% Called after sending a message - supports returning a
   %% request id for streaming calls
   %% @private
  -after_send(#rpblistkeysreq{}, {ReqId, _Client}, State) ->
  +after_send(#request{msg = #rpblistkeysreq{}, ctx = {ReqId, _Client}}, State) ->
       {reply, {ok, ReqId}, State};
  -after_send(rpblistbucketsreq, {ReqId, _Client}, State) ->
  +after_send(#request{msg = rpblistbucketsreq, ctx = {ReqId, _Client}}, State) ->
       {reply, {ok, ReqId}, State};
  -after_send(#rpbmapredreq{}, {ReqId, _Client}, State) ->
  +after_send(#request{msg = #rpbmapredreq{}, ctx = {ReqId, _Client}}, State) ->
       {reply, {ok, ReqId}, State};
  -after_send(_Req, _Ctx, State) ->
  +after_send(_Request, State) ->
       {noreply, State}.
   
   %%
  -%% Called after receiving an error message - supports retruning
  -%% an error for streamign calls
  -%% @private
  -on_error(#rpblistkeysreq{}, {ReqId, Client},  ErrMsg, undefined) ->
  -    Client ! { ReqId, fmt_err_msg(ErrMsg)};
  -on_error(rpblistbucketsreq, {ReqId, Client}, ErrMsg, undefined) ->
  -    Client ! { ReqId, fmt_err_msg(ErrMsg)};
  -on_error(#rpbmapredreq{}, {ReqId, Client}, ErrMsg, undefined) ->
  -    Client ! { ReqId, fmt_err_msg(ErrMsg)};
  -on_error(_Req, _Ctx, ErrMsg, From) when From =/= undefined ->
  -    gen_server:reply(From, fmt_err_msg(ErrMsg)).
  +%% Called after receiving an error message - supports reruning
  +%% an error for streaming calls
  +%% @private
  +on_error(_Request, ErrMsg, State) ->
  +    {reply, fmt_err_msg(ErrMsg), State}.
   
   %% Format the PB encoded error message
   fmt_err_msg(ErrMsg) ->
  
positive.code: %%        reply if the request is completed with a reply to the caller
  %%        pending if the request has not completed yet (streaming op)
  %% @private
  -spec process_response(rpb_req(), ctx(), rpb_resp(), #state{}) ->
                                {noreply, #state{}} |
                                {reply, term(), #state{}} |
                                {pending, #state{}}.
  process_response(rpbpingreq, _Ctx, rpbpingresp, State) ->
      {reply, pong, State};
  process_response(rpbgetclientidreq, undefined,
                   #rpbgetclientidresp{client_id = ClientId}, State) ->
      {reply, {ok, ClientId}, State};
  process_response(#rpbsetclientidreq{}, undefined,
                   rpbsetclientidresp, State) ->
      {reply, ok, State};
  process_response(rpbgetserverinforeq, undefined,
                   #rpbgetserverinforesp{node = Node, server_version = ServerVersion}, State) ->
      case Node of
          undefined ->
  
negative.code:     end.
  
  %% @private
  handle_call({req, Msg, Timeout}, From, State) when State#state.pending =/= undefined ->
      {noreply, queue_request(new_request(Msg, From, Timeout), State)};
  handle_call({req, Msg, Timeout, Ctx}, From, State) when State#state.pending =/= undefined ->
      {noreply, queue_request(new_request(Msg, From, Timeout, Ctx), State)};
  handle_call({req, Msg, Timeout}, From, State) ->
      {noreply, send_request(new_request(Msg, From, Timeout), State)};
  handle_call({req, Msg, Timeout, Ctx}, From, State) ->
      {noreply, send_request(new_request(Msg, From, Timeout, Ctx), State)}.
  
  %% @private
  handle_info({tcp_closed, _Socket}, State) ->
      {stop, normal, State};
  handle_info({tcp, _Socket, Data}, State=#state{sock = Sock, pending = Pending}) ->
      [MsgCode|MsgData] = Data,
      Resp = riakc_pb:decode(MsgCode, MsgData),
      case Resp of
          #rpberrorresp{} ->
              NewState1 = maybe_reply(on_error(Pending, Resp, State)),
              NewState = dequeue_request(NewState1#state{pending = undefined});
          _ ->
              case process_response(Pending, Resp, State) of
                  {reply, Response, NewState0} ->
                      %% Send reply and get ready for the next request - send the next request
                      %% if one is queued up
                      NewState1 = send_caller(Response, NewState0),
                      NewState = dequeue_request(NewState1#state{pending = undefined});
  
                  {noreply, NewState0} ->
                      %% Request has completed with no reply needed, send the next request 
                      %% if one is queued up
                      NewState = dequeue_request(NewState0#state{pending = undefined});
  
                  {pending, NewState} ->
                      ok %% Request is still pending - do not queue up a new one
  