123456789_123456789_123456789_123456789_123456789_

Module: Selenium::WebDriver::BiDi::Serialization Private

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

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: 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.

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.

[ GitHub ]

  
# 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.

[ GitHub ]

  
# 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.

Raises:

  • (::ArgumentError)
[ GitHub ]

  
# 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