Class: Nl::Protocols::Raw::Message
- Inherits:
-
Object
- Object
- Nl::Protocols::Raw::Message
- Defined in:
- lib/nl/protocols/raw.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#fixed_header ⇒ Object
Returns the value of attribute fixed_header.
-
#nlmsg_header ⇒ Object
Returns the value of attribute nlmsg_header.
Class Method Summary collapse
Instance Method Summary collapse
- #append_attribute(attribute) ⇒ Object
- #encode(encoder) ⇒ Object
-
#initialize(header, fixed_header = nil, attributes = self.class::ATTRIBUTE_SET.new) ⇒ Message
constructor
A new instance of Message.
Constructor Details
#initialize(header, fixed_header = nil, attributes = self.class::ATTRIBUTE_SET.new) ⇒ Message
Returns a new instance of Message.
213 214 215 216 217 |
# File 'lib/nl/protocols/raw.rb', line 213 def initialize(header, fixed_header = nil, attributes = self.class::ATTRIBUTE_SET.new) @nlmsg_header = header @fixed_header = fixed_header @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
211 212 213 |
# File 'lib/nl/protocols/raw.rb', line 211 def attributes @attributes end |
#fixed_header ⇒ Object
Returns the value of attribute fixed_header.
211 212 213 |
# File 'lib/nl/protocols/raw.rb', line 211 def fixed_header @fixed_header end |
#nlmsg_header ⇒ Object
Returns the value of attribute nlmsg_header.
211 212 213 |
# File 'lib/nl/protocols/raw.rb', line 211 def nlmsg_header @nlmsg_header end |
Class Method Details
.decode(decoder, header, type: header.type) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/nl/protocols/raw.rb', line 249 def self.decode(decoder, header, type: header.type) unless self::TYPE == type raise "Expected message type #{self::TYPE}, got #{type}" end if fixed_header_class = self::FIXED_HEADER fixed_header = fixed_header_class.decode(decoder) end attributes = self::ATTRIBUTE_SET.decode(decoder) new(header, fixed_header, attributes) end |
.from_params(params) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/nl/protocols/raw.rb', line 219 def self.from_params(params) if self::FIXED_HEADER header_params = params.slice(*self::FIXED_HEADER.members) fixed_header = self::FIXED_HEADER.new(**header_params) end attribute_params = params.slice(*self::ATTRIBUTES) attributes = self::ATTRIBUTE_SET.build_attributes(**attribute_params) unknown = params.keys - attribute_params.keys unknown -= header_params.keys if header_params unless unknown.empty? raise ArgumentError, "unknown parameters: #{unknown.join(', ')}" end header = Core::NlMsgHdr.new(0, self::TYPE, nil, nil, nil) new(header, fixed_header, attributes) end |
Instance Method Details
#append_attribute(attribute) ⇒ Object
237 238 239 |
# File 'lib/nl/protocols/raw.rb', line 237 def append_attribute(attribute) @attributes << attribute end |