Class: Codec::CompleteComposed

Inherits:
BaseComposed show all
Defined in:
lib/codec/composed.rb

Instance Attribute Summary

Attributes inherited from Base

#id

Instance Method Summary collapse

Methods inherited from BaseComposed

#add_sub_codec, #build_field, #decode, #initialize

Methods inherited from Base

#add_sub_codec, #build_field, #decode, #decode_with_length, #encode_with_length, #eval_length, #get_length, #get_sub_codecs, #initialize

Constructor Details

This class inherits a constructor from Codec::BaseComposed

Instance Method Details

#build_each_field(buf, length) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/codec/composed.rb', line 68

def build_each_field(buf,length)
  f,r = super(buf,length)
  # Check if all struct's fields have been parsed
  if f.get_value.size < @subCodecs.size 
    raise BufferUnderflow, "Not enough data for parsing Struct #{@id}" 
  end
  return f,r
end

#encode(field) ⇒ Object



77
78
79
80
81
82
# File 'lib/codec/composed.rb', line 77

def encode(field)
  if @subCodecs.size != field.get_value.size
    raise EncodingException, "Not enough subfields to encode #{@id}"
  end
  super(field)
end