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), and outbound enum validation.
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
-
.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
.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.
66 67 68 69 70 71 |
# File '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) ⇒ 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.
55 56 57 58 59 |
# File '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) ⇒ 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.
42 43 44 45 46 47 48 49 50 |
# File '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 |