lib/bindata/base.rb in bindata-0.7.0 vs lib/bindata/base.rb in bindata-0.8.0
- old
+ new
@@ -155,17 +155,29 @@
klass = @env.parent_data_object.klass_lookup(name)
end
klass
end
+ # Returns a list of parameters that *weren't* provided to this object.
+ def unsupplied_parameters
+ supplied = @params.keys + @env.params.keys
+ self.class.parameters - supplied
+ end
+
# Reads data into this bin object by calling #do_read then #done_read.
def read(io)
+ # remove previous method to prevent warnings
+ class << io
+ undef_method(:bindata_mark) if method_defined?(:bindata_mark)
+ end
+
# remember the current position in the IO object
- io.instance_eval "def mark; #{io.pos}; end"
+ io.instance_eval "def bindata_mark; #{io.pos}; end"
do_read(io)
done_read
+ self
end
# Reads the value for this data from +io+.
def do_read(io)
clear
@@ -187,10 +199,15 @@
# value data objects respond to <tt>#value</tt> and <tt>#value=</tt>.
def single_value?
respond_to? :value
end
+ # Return a human readable representation of this object.
+ def inspect
+ snapshot.inspect
+ end
+
#---------------
private
# Creates a new LazyEvalEnv for use by a child data object.
def create_env
@@ -228,11 +245,11 @@
# Checks that the current offset of +io+ is as expected. This should
# be called from #do_read before performing the reading.
def check_offset(io)
if has_param?(:check_offset)
- actual_offset = io.pos - io.mark
+ actual_offset = io.pos - io.bindata_mark
expected = eval_param(:check_offset, :offset => actual_offset)
if not expected
raise ValidityError, "offset not as expected"
elsif actual_offset != expected and expected != true
@@ -240,11 +257,10 @@
"expected '#{expected}'"
end
end
end
-=begin
# To be implemented by subclasses
# Resets the internal state to that of a newly created object.
def clear
raise NotImplementedError
@@ -279,9 +295,12 @@
# object.
def field_names
raise NotImplementedError
end
- # To be implemented by subclasses
-=end
+ # Set visibility requirements of methods to implement
+ public :clear, :done_read, :snapshot, :field_names
+ private :_do_read, :_write, :_num_bytes
+
+ # End To be implemented by subclasses
end
end