Class: KineticRuby::Proto
- Inherits:
-
Object
- Object
- KineticRuby::Proto
- Defined in:
- lib/kinetic_proto.rb
Constant Summary collapse
- VERSION_PREFIX =
'F'
Class Method Summary collapse
Instance Method Summary collapse
- #decode(buf, indent = 0) ⇒ Object
-
#initialize(logger) ⇒ Proto
constructor
A new instance of Proto.
- #test_encode ⇒ Object
- #test_kinetic_proto ⇒ Object
- #to_yaml(msg) ⇒ Object
Constructor Details
#initialize(logger) ⇒ Proto
Returns a new instance of Proto.
10 11 12 13 14 |
# File 'lib/kinetic_proto.rb', line 10 def initialize(logger) @logger = logger = nil = nil end |
Class Method Details
.decode(buf, indent = 0, logger = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kinetic_proto.rb', line 16 def self.decode(buf, indent=0, logger=nil) msg = Seagate::Kinetic::Message.decode(buf) # Log the decoded protobuf if logger orig_prefix = logger.prefix add_prefix = (indent.class == Fixnum) ? (' '*indent) : indent add_prefix = ' ' * indent logger.prefix = logger.prefix + add_prefix logger.log 'message:' logger.prefix = logger.prefix + ' ' self.to_yaml(msg).each_line{|line| logger.log(line.rstrip) } logger.prefix = orig_prefix logger.log end return msg end |
.to_yaml(msg) ⇒ Object
39 40 41 42 43 |
# File 'lib/kinetic_proto.rb', line 39 def self.to_yaml(msg) yaml = "message:\n" msg.to_yaml.each_line{|line| yaml += " #{line}"} return yaml end |
Instance Method Details
#decode(buf, indent = 0) ⇒ Object
35 36 37 |
# File 'lib/kinetic_proto.rb', line 35 def decode(buf, indent=0) = Proto.decode(buf, indent, @logger) end |
#test_encode ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/kinetic_proto.rb', line 49 def test_encode pb = Seagate::Kinetic::Message.new @logger.log @logger.log("#{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:" @logger.log_verbose " #{pb.hmac}" @logger.log ' command:' pb.command.to_yaml.each_line{|l| @logger.log(" #{l.rstrip}")} @logger.log ' encoded:' @logger.log ' Length: ' + encoded.length.to_s + ' bytes' @logger.log_verbose " Raw:" @logger.log_verbose " #{encoded.inspect}" @logger.log_verbose " Content:" encoded.to_yaml.each_line{|line| @logger.log_verbose " #{line.rstrip}"} @logger.log return encoded end |
#test_kinetic_proto ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/kinetic_proto.rb', line 93 def test_kinetic_proto msg = test_encode @logger.log @logger.log("Decoded Message", true) decode(msg, 2) if != @logger.log_err "Inbound/outbound messages do not match!" @logger.log_err raise "\nKinetic Protocol message roundtrip FAILED!\n\n" end @logger.log @logger.log 'Kinetic Protocol protobuf encode/decode test passed!' @logger.log end |
#to_yaml(msg) ⇒ Object
45 46 47 |
# File 'lib/kinetic_proto.rb', line 45 def to_yaml(msg) self.to_yaml(msg) end |