Class: TorigoyaKit::Protocol::Packet
- Inherits:
-
Object
- Object
- TorigoyaKit::Protocol::Packet
- Defined in:
- lib/torigoya_kit/protocol.rb
Overview
MessageKind byte // Version [4]byte // uint32, little endian Length [4]byte // uint32, little endian Message []byte // data, msgpacked
Constant Summary collapse
- Signature =
"TG"
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(kind, version, data) ⇒ Packet
constructor
A new instance of Packet.
- #to_binary ⇒ Object
Constructor Details
#initialize(kind, version, data) ⇒ Packet
Returns a new instance of Packet.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/torigoya_kit/protocol.rb', line 41 def initialize(kind, version, data) if kind < MessageKindIndexBegin || kind > MessageKindIndexEnd raise "invalid header" end @kind = [kind].pack("C*") # byte @version = [version].pack("V*") # little endian, 32bit, unsigned int @message = data.to_msgpack # msgpacked @length = [@message.size].pack("V*") # little endian, 32bit, unsigned int end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
51 52 53 |
# File 'lib/torigoya_kit/protocol.rb', line 51 def kind @kind end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
51 52 53 |
# File 'lib/torigoya_kit/protocol.rb', line 51 def length @length end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
51 52 53 |
# File 'lib/torigoya_kit/protocol.rb', line 51 def @message end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
51 52 53 |
# File 'lib/torigoya_kit/protocol.rb', line 51 def version @version end |
Instance Method Details
#to_binary ⇒ Object
54 55 56 |
# File 'lib/torigoya_kit/protocol.rb', line 54 def to_binary return Signature + @kind + @version + @length + @message end |