lib/bindata/buffer.rb in bindata-2.0.0 vs lib/bindata/buffer.rb in bindata-2.1.0
- old
+ new
@@ -49,36 +49,22 @@
#
# <tt>:length</tt>:: The number of bytes in the buffer.
# <tt>:type</tt>:: The single type inside the buffer. Use a struct if
# multiple fields are required.
class Buffer < BinData::Base
- include DSLMixin
+ extend DSLMixin
- dsl_parser :buffer
+ dsl_parser :buffer
+ arg_processor :buffer
mandatory_parameters :length, :type
- class << self
- def arg_extractor
- MultiFieldArgExtractor
- end
-
- def sanitize_parameters!(params) #:nodoc:
- params.merge!(dsl_params)
-
- if params.needs_sanitizing?(:type)
- el_type, el_params = params[:type]
- params[:type] = params.create_sanitized_object_prototype(el_type, el_params)
- end
- end
- end
-
def initialize_instance
@type = get_parameter(:type).instantiate(nil, self)
end
- def clear? #:nodoc:
+ def clear?
@type.clear?
end
def assign(val)
@type.assign(val)
@@ -112,8 +98,23 @@
end
end
def do_num_bytes #:nodoc:
eval_parameter(:length)
+ end
+ end
+
+ class BufferArgProcessor < BaseArgProcessor
+ include MultiFieldArgSeparator
+
+ def sanitize_parameters!(obj_class, params)
+ params.merge!(obj_class.dsl_params)
+
+ params.must_be_integer(:length)
+
+ if params.needs_sanitizing?(:type)
+ el_type, el_params = params[:type]
+ params[:type] = params.create_sanitized_object_prototype(el_type, el_params)
+ end
end
end
end