module StructPacking::Unpackable

Unpackable module provides value assign function from packed byte array.

A class include this module, and call struct defininesg method, A instance's unpack method assign variables from packed object. This module also provide read_struct_data class method which construct object and assign values from packed object.

Private Class Methods

included(base) click to toggle source
# File lib/struct_packing/unpackable.rb, line 14
def self.included(base)
  base.send(:include, Base)
  base.extend ClassMethods
end

Public Instance Methods

read_struct_data(bytes) click to toggle source

Set attributes from packed struct byte array.

If attribute defined in byte_format, but object has no attr_setter, do nothing.

# File lib/struct_packing/unpackable.rb, line 134
def read_struct_data(bytes)
  self.class.set_values_from_byte_to_object(bytes, self)
end