Comments (2)
I was trying to push a fix where access denied error occurred.please check the following changes in base_primitive.rb file.
i have replaced 'assert' keyword with 'assert_key' only.
class BasePrimitive < BinData::Base
unregister_self
optional_parameters :initial_value, :value, :assert_key, :asserted_value
mutually_exclusive_parameters :initial_value, :value
mutually_exclusive_parameters :asserted_value, :value, :assert_key
def initialize_shared_instance
extend InitialValuePlugin if has_parameter?(:initial_value)
extend ValuePlugin if has_parameter?(:value)
extend AssertPlugin if has_parameter?(:assert_key)
extend AssertedValuePlugin if has_parameter?(:asserted_value)
super
end
def initialize_instance
@value = nil
end
def clear? #:nodoc:
@value.nil?
end
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 =
begin
raw_val.dup
rescue TypeError
# can't dup Fixnums
raw_val
end
end
def snapshot
_value
end
def value
snapshot
end
def value=(val)
assign(val)
end
def respond_to?(symbol, include_private = false) #:nodoc:
child = snapshot
child.respond_to?(symbol, include_private) || super
end
def method_missing(symbol, *args, &block) #:nodoc:
child = snapshot
if child.respond_to?(symbol)
self.class.class_eval \
"def #{symbol}(*args, &block);" \
" snapshot.#{symbol}(*args, &block);" \
"end"
child.__send__(symbol, *args, &block)
else
super
end
end
def <=>(other)
snapshot <=> other
end
def eql?(other)
# double dispatch
other.eql?(snapshot)
end
def hash
snapshot.hash
end
def do_read(io) #:nodoc:
@value = read_and_return_value(io)
end
def do_write(io) #:nodoc:
io.writebytes(value_to_binary_string(_value))
end
def do_num_bytes #:nodoc:
value_to_binary_string(_value).length
end
#---------------
private
# The unmodified value of this data object. Note that #snapshot calls this
# method. This indirection is so that #snapshot can be overridden in
# subclasses to modify the presentation value.
def _value
@value != nil ? @value : sensible_default
end
# Logic for the :value parameter
module ValuePlugin
def assign(val)
# Ignored
end
def _value
reading? ? @value : eval_parameter(:value)
end
end
# Logic for the :initial_value parameter
module InitialValuePlugin
def _value
@value != nil ? @value : eval_parameter(:initial_value)
end
end
# Logic for the :assert parameter
module AssertPlugin
def assign(val)
super(val)
assert_key!
end
def do_read(io) #:nodoc:
super(io)
assert_key!
end
def assert_key!
current_value = snapshot
expected = eval_parameter(:assert_key, value: current_value)
msg =
if !expected
"value '#{current_value}' not as expected"
elsif expected != true && current_value != expected
"value is '#{current_value}' but expected '#{expected}'"
else
nil
end
raise ValidityError, "#{msg} for #{debug_name}" if msg
end
end
# Logic for the :asserted_value parameter
module AssertedValuePlugin
def assign(val)
assert_value(val)
super(val)
end
def _value
reading? ? @value : eval_parameter(:asserted_value)
end
def do_read(io) #:nodoc:
super(io)
assert_key!
end
def assert_key!
assert_value(snapshot)
end
def assert_value(current_value)
expected = eval_parameter(:asserted_value, value: current_value)
if current_value != expected
raise ValidityError,
"value is '#{current_value}' but " \
"expected '#{expected}' for #{debug_name}"
end
end
end
###########################################################################
# To be implemented by subclasses
# Return the string representation that +val+ will take when written.
def value_to_binary_string(val)
raise NotImplementedError
end
# Read a number of bytes from +io+ and return the value they represent.
def read_and_return_value(io)
raise NotImplementedError
end
# Return a sensible default for this data.
def sensible_default
raise NotImplementedError
end
# To be implemented by subclasses
###########################################################################
end
end
`
from bindata.
Hey @dmendel thanks for the pointer in issue #141 , This resolved our issue.
from bindata.
Related Issues (20)
- parse ole file err HOT 2
- Arrays are fully allocated before checking to see if they can be read HOT 3
- Customize record Bindata name HOT 2
- List example references Fixnum which is deprecated in Ruby 2.4 HOT 1
- ActiveSupport 7 compatibility - Enumerable now contains a method called maximum HOT 1
- Help: use endian to report an error, why is this?I'm using bindata in the process of writing a plugin for logstash HOT 3
- DelayedIO ignores onlyif HOT 4
- Rename parameter 'assert' as it shadows an existing method. HOT 11
- Calculating offsets for the delayed_io directory example HOT 2
- test failures with ruby3.1
- Dependency on Ruby 2.4 added
- Calling auto_call_delayed_io twice breaks delayed io HOT 2
- Dynamic integer HOT 1
- Question: High memory usage HOT 2
- Heterogenous array of absolutely positioned items HOT 2
- EOFError when reading unaligned little endian bit integers HOT 5
- How can I read 2 bytes (little endian) and then interpret that value as a bit field? HOT 2
- Array read_until: -> { :eof } feature is broken HOT 2
- Multiple registries HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bindata.