Module: Selenium::WebDriver::BiDi::Serialization Private
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Defined in: | rb/lib/selenium/webdriver/bidi/serialization.rb, rb/lib/selenium/webdriver/bidi/serialization/record.rb, rb/lib/selenium/webdriver/bidi/serialization/union.rb |
Overview
Wire round-trip runtime for the generated protocol layer: the value-type bases
(Record, Union), the omit sentinel (UNSET), and outbound enum validation.
Constant Summary
-
UNSET =
# File 'rb/lib/selenium/webdriver/bidi/serialization.rb', line 32
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
-
.to_symbol(name, value, enum)
Internal use only
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)
Internal use only
Outbound: map a validated enum symbol (or list) to the wire token(s) to serialize.
-
.validate!(name, value, enum)
Internal use only
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
.to_symbol(name, value, enum)
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.
# File 'rb/lib/selenium/webdriver/bidi/serialization.rb', line 66
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)
Outbound: map a validated enum symbol (or list) to the wire token(s) to serialize.
# File 'rb/lib/selenium/webdriver/bidi/serialization.rb', line 55
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)
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.
# File 'rb/lib/selenium/webdriver/bidi/serialization.rb', line 42
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