Class: KineticRuby::Proto
- Inherits:
-
Object
- Object
- KineticRuby::Proto
- Defined in:
- lib/kinetic_proto.rb
Constant Summary collapse
- VERSION_PREFIX =
'F'
Instance Method Summary collapse
- #decode(buf) ⇒ Object
-
#initialize(logger) ⇒ Proto
constructor
A new instance of Proto.
- #test_encode ⇒ Object
- #test_kinetic_proto ⇒ Object
Constructor Details
#initialize(logger) ⇒ Proto
Returns a new instance of Proto.
9 10 11 12 13 |
# File 'lib/kinetic_proto.rb', line 9 def initialize(logger) @logger = logger = nil = nil end |
Instance Method Details
#decode(buf) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/kinetic_proto.rb', line 15 def decode(buf) = Seagate::Kinetic::Message.decode(buf) @logger.log @logger.log("\n#{@message_in.class} - Decoding", true) @logger.log ' command:' .command.to_yaml.each_line{|line| @logger.log ' ' + line} @logger.log end |
#test_encode ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kinetic_proto.rb', line 24 def test_encode pb = Seagate::Kinetic::Message.new @logger.log("\n#{pb.class} - Encoding", true) pb.hmac = '0123456789ABCDEF0123' pb.command = Seagate::Kinetic::Message::Command.new( header: Seagate::Kinetic::Message::Header.new( clusterVersion: 0x1122334455667788, identity: 0x1234567898654321 ), body: Seagate::Kinetic::Message::Body.new( keyValue: Seagate::Kinetic::Message::KeyValue.new( key: "KeYvAl" ) ), status: Seagate::Kinetic::Message::Status.new( code: Seagate::Kinetic::Message::Status::StatusCode::NO_SUCH_HMAC_ALGORITHM, statusMessage: 'The specified HMAC security algorithm does not exist!', detailedMessage: 'YOUCH!' ), ) encoded = pb.encode = pb @logger.log_verbose ' fields:' pb.fields.sort.each{|f| @logger.log_verbose(" #{f}")} @logger.log_verbose " hmac:\n #{pb.hmac}" @logger.log ' command:' pb.command.to_yaml.each_line{|l| @logger.log(" #{l}")} @logger.log ' encoded:' @logger.log ' Length: ' + encoded.length.to_s + ' bytes' @logger.log_verbose " Raw:\n #{encoded.inspect}" @logger.log_verbose " Content:" encoded.to_yaml.each_line{|line| @logger.log_verbose " #{line}"} @logger.log return encoded end |
#test_kinetic_proto ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/kinetic_proto.rb', line 66 def test_kinetic_proto msg = test_encode decode msg if != @logger.log_err "Inbound/outbound messages do not match!\n\n" raise "\nKinetic Protocol message roundtrip FAILED!\n\n" end @logger.log @logger.log 'Kinetic Protocol protobuf encode/decode test passed!' @logger.log end |