class BinData::BasePrimitive


:asserted_value] Equivalent to :assert and :value.
the value just read in.
or failure. Any other return is compared to
parameter. A boolean return indicates success
made available to any lambda assigned to this
meets this criteria. The variable value is
[:assert] Raise an error unless the value read or assigned
IO, not the result of the :value param.
will return the value of the data read from the
using this param. While reading, #value
Calls to #value= are ignored when
[:value] The object will always have this value.
either #read or explicitly set with #value=.
[:initial_value] This is the initial value to use before one is
an object. These params include those for BinData::Base as well as:
Parameters may be provided at initialisation to control the behaviour of
== Parameters
obj.read(“007”) #=> BinData::ValidityError: value not as expected
obj = BinData::Uint8.new(assert: -> { value < 5 })
obj.read(“005”) #=> BinData::ValidityError: value is ‘5’ but expected ‘3’
obj = BinData::Uint8.new(assert: 3)
obj #=> 42
obj.assign(5)
obj #=> 42
obj = BinData::Uint8.new(value: 42)
obj #=> 42
obj.clear
obj #=> 5
obj.assign(5)
obj #=> 42
obj = BinData::Uint8.new(initial_value: 42)
require ‘bindata’
this object. This value can be read from or written to an IO stream.
such as as integer, float or string. Only one value can be contained by
particular binary representation. A value corresponds to a primitive type
A BinData::BasePrimitive object is a container for a value that has a

def <=>(other)

def <=>(other)
  snapshot <=> other
end

def _value

subclasses to modify the presentation value.
method. This indirection is so that #snapshot can be overridden in
The unmodified value of this data object. Note that #snapshot calls this
def _value
  @value != nil ? @value : sensible_default
end

def assign(val)

def assign(val)
  raise ArgumentError, "can't set a nil value for #{debug_name}" if val.nil?
  raw_val = val.respond_to?(:snapshot) ? val.snapshot : val
  @value = raw_val.dup
end

def clear? # :nodoc:

:nodoc:
def clear? # :nodoc:
  @value.nil?
end

def do_num_bytes # :nodoc:

:nodoc:
def do_num_bytes # :nodoc:
  value_to_binary_string(_value).length
end

def do_read(io) # :nodoc:

:nodoc:
def do_read(io) # :nodoc:
  @value = read_and_return_value(io)
end

def do_read_with_hook(io)

def do_read_with_hook(io)
  do_read_without_hook(io)
  BinData.trace_message do |tracer|
    value_string = _value.inspect
    tracer.trace_obj(debug_name, value_string)
  end
end

def do_write(io) # :nodoc:

:nodoc:
def do_write(io) # :nodoc:
  io.writebytes(value_to_binary_string(_value))
end

def eql?(other)

def eql?(other)
  # double dispatch
  other.eql?(snapshot)
end

def hash

def hash
  snapshot.hash
end

def initialize_instance

def initialize_instance
  @value = nil
end

def initialize_shared_instance

def initialize_shared_instance
  extend InitialValuePlugin  if has_parameter?(:initial_value)
  extend ValuePlugin         if has_parameter?(:value)
  extend AssertPlugin        if has_parameter?(:assert)
  extend AssertedValuePlugin if has_parameter?(:asserted_value)
  super
end

def method_missing(symbol, *args, &block) # :nodoc:

:nodoc:
def method_missing(symbol, *args, &block) # :nodoc:
  child = snapshot
  if child.respond_to?(symbol)
    self.class.class_eval <<-END, __FILE__, __LINE__ + 1
      def #{symbol}(*args, &block)         # def clamp(*args, &block)
        snapshot.#{symbol}(*args, &block)  #   snapshot.clamp(*args, &block)
      end                                  # end
    END
    child.__send__(symbol, *args, &block)
  else
    super
  end
end

def read_and_return_value(io)

Read a number of bytes from +io+ and return the value they represent.
def read_and_return_value(io)
  raise NotImplementedError
end

def respond_to_missing?(symbol, include_all = false) # :nodoc:

:nodoc:
def respond_to_missing?(symbol, include_all = false) # :nodoc:
  child = snapshot
  child.respond_to?(symbol, include_all) || super
end

def sensible_default

Return a sensible default for this data.
def sensible_default
  raise NotImplementedError
end

def snapshot

def snapshot
  _value
end

def value

def value
  snapshot
end

def value=(val)

def value=(val)
  assign(val)
end

def value_to_binary_string(val)

Return the string representation that +val+ will take when written.
def value_to_binary_string(val)
  raise NotImplementedError
end