node/lib/metasm/metasm/exe_format/serialstruct.rb
def encode(exe, *a)
		set_default_values(exe, *a)

		ed = EncodedData.new
		struct_fields(exe).each { |f|
			if not f[NAME]
				ed << f[ENCODE][exe, self, nil] if f[ENCODE]
				next
			end
			val = instance_variable_get(f[NAME])
			if h = f[ENUM]; h = h[exe, self] if h.kind_of? Proc; val = int_from_hash( val, h) end
			if h = f[BITS]; h = h[exe, self] if h.kind_of? Proc; val = bits_from_hash(val, h) end
			case e = f[ENCODE]
			when Symbol; val = exe.send(e, val)
			when Array; val = exe.send(e, *val)
			when Proc; val = e[exe, self, val]
			when nil; next
			end
			ed << val
		}
		ed
	end
# sets default values, then encodes the fields, returns an EData
sets default values, then encodes the fields, returns an EData
sets default values then encodes the fields returns an EData
def encode(exe, *a)
		set_default_values(exe, *a)
		ed = EncodedData.new
		struct_fields(exe).each { |f|
			if not f[NAME]
				ed << f[ENCODE][exe, self, nil] if f[ENCODE]
				next
			end
			val = instance_variable_get(f[NAME])
			if h = f[ENUM]; h = h[exe, self] if h.kind_of? Proc; val = int_from_hash( val, h) end
			if h = f[BITS]; h = h[exe, self] if h.kind_of? Proc; val = bits_from_hash(val, h) end
			case e = f[ENCODE]
			when Symbol; val = exe.send(e, val)
			when Array; val = exe.send(e, *val)
			when Proc; val = e[exe, self, val]
			when nil; next
			end
			ed << val
		}
		ed
	end
def encode ( exe , * a ) set_default_values ( exe , * a ) ed = EncodedData . new struct_fields ( exe ) . each { | f | if not f [ NAME ] ed << f [ ENCODE ] [ exe , self , nil ] if f [ ENCODE ] next end val = instance_variable_get ( f [ NAME ] ) if h = f [ ENUM ] ; h = h [ exe , self ] if h . kind_of? Proc ; val = int_from_hash ( val , h ) end if h = f [ BITS ] ; h = h [ exe , self ] if h . kind_of? Proc ; val = bits_from_hash ( val , h ) end case e = f [ ENCODE ] when Symbol ; val = exe . send ( e , val ) when Array ; val = exe . send ( e , * val ) when Proc ; val = e [ exe , self , val ] when nil ; next end ed << val } ed end
sets default values, then encodes the fields, returns an EData
sets default values then encodes the fields returns an EData
exe
a