lib/riak/client/beefcake/protocol.rb in riak-client-2.2.0.pre1 vs lib/riak/client/beefcake/protocol.rb in riak-client-2.2.0
- old
+ new
@@ -14,16 +14,16 @@
@socket = socket
end
# Encodes and writes a Riak-formatted message, including protocol buffer
# payload if given.
- #
- # @param [Symbol, Integer] code the symbolic or numeric code for the
+ #
+ # @param [Symbol, Integer] code the symbolic or numeric code for the
# message
# @param [Beefcake::Message, nil] message the protocol buffer message
# payload, or nil if the message carries no payload
- def write(code, message=nil)
+ def write(code, message = nil)
if code.is_a? Symbol
code = BeefcakeMessageCodes.index code
end
serialized = serialize message
@@ -40,11 +40,11 @@
# the message along with the string payload from the network.
#
# @return [Array<Symbol, String>]
def receive
header = socket.read 5
-
+
raise ProtobuffsFailedHeader.new if header.nil?
message_length, code = header.unpack 'NC'
body_length = message_length - 1
body = nil
body = socket.read body_length if body_length > 0
@@ -57,11 +57,11 @@
# Receives a Riak-formatted message, checks the symbolic name against
# the given code, decodes it if it matches, and can optionally return
# success if the payload is empty.
#
# @param [Symbol] code the code for the message
- # @param [Class, nil] decoder_class the class to attempt to decode
+ # @param [Class, nil] decoder_class the class to attempt to decode
# the payload with
# @param [Hash] options
# @option options [Boolean] :empty_body_acceptable Whether to accept
# an empty body and not attempt decoding. In this case, this method
# will return the symbol `:empty` instead of a `Beefcake::Message`
@@ -69,13 +69,13 @@
# @return [Beefcake::Message, :empty]
# @raise {ProtobuffsErrorResponse} if the message from Riak was a
# 255-ErrorResp
# @raise {ProtobuffsUnexpectedResponse} if the message from riak did
# not match `code`
- def expect(code, decoder_class=nil, options={ })
+ def expect(code, decoder_class = nil, options = { })
code = BeefcakeMessageCodes[code] unless code.is_a? Symbol
name, body = receive
-
+
if name == :ErrorResp
raise ProtobuffsErrorResponse.new RpbErrorResp.decode(body)
end
if name != code