Module: Selenium::WebDriver::BiDi::Serialization Private
- Defined in:
- lib/selenium/webdriver/bidi/serialization.rb,
lib/selenium/webdriver/bidi/serialization/union.rb,
lib/selenium/webdriver/bidi/serialization/record.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Wire round-trip runtime for the generated protocol layer: the value-type bases (Record, Union), the omit sentinel (UNSET), outbound enum validation, and the strict-inbound toggle.
Defined Under Namespace
Constant Summary collapse
- UNSET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Sentinel for an omitted optional: dropped from the payload entirely, vs nil which a nullable field serializes as wire null.
::Object.new
Class Method Summary collapse
-
.strict? ⇒ Boolean
private
Strict inbound mode.
-
.to_symbol(name, value, enum) ⇒ Object
private
Inbound: map a wire token (or list) back to its enum symbol, raising on a token outside our schema so a non-compliant (or newer-than-schema) browser value fails loud instead of silently passing through untyped.
-
.to_wire(value, enum) ⇒ Object
private
Outbound: map a validated enum symbol (or list) to the wire token(s) to serialize.
-
.validate!(name, value, enum) ⇒ Object
private
Validates an outbound enum argument:
valueis a symbol (or list of symbols) that must be a key of the enum hash (+=> wire_token+), so a bad value fails locally with a clear error instead of a round-trip.
Class Method Details
.strict? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Strict inbound mode. Off by default: a required field missing from a response is tolerated as omitted and warned, so a schema ahead of the browser does not block the caller. When SE_BIDI_STRICT is set to anything but 0/false, that same case escalates to an error for callers who want it.
43 44 45 46 |
# File 'lib/selenium/webdriver/bidi/serialization.rb', line 43 def self.strict? value = ENV.fetch('SE_BIDI_STRICT', '').strip.downcase !value.empty? && value != '0' && value != 'false' end |
.to_symbol(name, value, enum) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Inbound: map a wire token (or list) back to its enum symbol, raising on a token outside our schema so a non-compliant (or newer-than-schema) browser value fails loud instead of silently passing through untyped.
78 79 80 81 82 83 |
# File 'lib/selenium/webdriver/bidi/serialization.rb', line 78 def self.to_symbol(name, value, enum) return value if value.nil? return value.map { |element| to_symbol(name, element, enum) } if value.is_a?(::Array) enum.key(value) || raise(Error::WebDriverError, "#{name} received an unknown value: #{value.inspect}") end |
.to_wire(value, enum) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Outbound: map a validated enum symbol (or list) to the wire token(s) to serialize.
67 68 69 70 71 |
# File 'lib/selenium/webdriver/bidi/serialization.rb', line 67 def self.to_wire(value, enum) return value if UNSET.equal?(value) || value.nil? value.is_a?(::Array) ? value.map { |element| enum.fetch(element) } : enum.fetch(value) end |
.validate!(name, value, enum) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Validates an outbound enum argument: value is a symbol (or list of symbols) that
must be a key of the enum hash (+=> wire_token+), so a bad value fails
locally with a clear error instead of a round-trip. Outbound only; inbound wire
tokens are mapped and checked separately in to_symbol.
54 55 56 57 58 59 60 61 62 |
# File 'lib/selenium/webdriver/bidi/serialization.rb', line 54 def self.validate!(name, value, enum) return if UNSET.equal?(value) || value.nil? elements = value.is_a?(::Array) ? value : [value] invalid = elements.reject { |element| enum.key?(element) } return if invalid.empty? raise ::ArgumentError, "#{name} must be one of #{enum.keys.inspect}, got #{invalid.inspect}" end |