Class: Necropsy::BoundedCanonicalizer
- Inherits:
-
Object
- Object
- Necropsy::BoundedCanonicalizer
- Defined in:
- lib/necropsy/bounded_canonicalizer.rb
Defined Under Namespace
Classes: CycleError, Error, LimitError, UnsupportedTypeError
Constant Summary collapse
- MAX_DEPTH =
256- MAX_ITEMS =
1_000_000- MAX_STRING_BYTES =
64 * 1024 * 1024
- MAX_TOTAL_BYTES =
256 * 1024 * 1024
Class Method Summary collapse
Instance Method Summary collapse
-
#call(value) ⇒ Object
Kept for callers that need the canonical Ruby representation rather than bytes.
- #dump(value) ⇒ Object
-
#initialize(max_depth: MAX_DEPTH, max_items: MAX_ITEMS, max_string_bytes: MAX_STRING_BYTES, max_total_bytes: MAX_TOTAL_BYTES) ⇒ BoundedCanonicalizer
constructor
A new instance of BoundedCanonicalizer.
Constructor Details
#initialize(max_depth: MAX_DEPTH, max_items: MAX_ITEMS, max_string_bytes: MAX_STRING_BYTES, max_total_bytes: MAX_TOTAL_BYTES) ⇒ BoundedCanonicalizer
Returns a new instance of BoundedCanonicalizer.
21 22 23 24 25 26 27 |
# File 'lib/necropsy/bounded_canonicalizer.rb', line 21 def initialize(max_depth: MAX_DEPTH, max_items: MAX_ITEMS, max_string_bytes: MAX_STRING_BYTES, max_total_bytes: MAX_TOTAL_BYTES) @max_depth = positive_limit(max_depth, :max_depth) @max_items = positive_limit(max_items, :max_items) @max_string_bytes = positive_limit(max_string_bytes, :max_string_bytes) @max_total_bytes = positive_limit(max_total_bytes, :max_total_bytes) end |
Class Method Details
.dump(value, **limits) ⇒ Object
17 18 19 |
# File 'lib/necropsy/bounded_canonicalizer.rb', line 17 def self.dump(value, **limits) new(**limits).dump(value) end |
Instance Method Details
#call(value) ⇒ Object
Kept for callers that need the canonical Ruby representation rather than bytes.
30 31 32 |
# File 'lib/necropsy/bounded_canonicalizer.rb', line 30 def call(value) JSON.parse(dump(value), max_nesting: false) end |
#dump(value) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/necropsy/bounded_canonicalizer.rb', line 34 def dump(value) reset_state output = binary_string process([[:value, value, 0, output]]) output rescue JSON::GeneratorError => e raise Error, "Could not encode canonical payload: #{e.}" end |