Class: Net::HTTP::StructuredFieldValues::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/net/http/structured_field_values/serializer.rb

Overview

RFC8941 compliant serializer which serializes Ruby objects into HTTP fields.

Defined Under Namespace

Classes: SerializationError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSerializer

Returns a new instance of Serializer.



12
13
14
# File 'lib/net/http/structured_field_values/serializer.rb', line 12

def initialize
  @result = +''
end

Class Method Details

.serialize(obj) ⇒ String

Serializes given object.

Parameters:

  • obj (Array, Hash, ParameterizedValue, Integer, Float, String, Symbol, Boolean)

    object to be serialized

Returns:

  • (String)

See Also:



37
38
39
# File 'lib/net/http/structured_field_values/serializer.rb', line 37

def self.serialize(obj)
  new.serialize(obj)
end

.serialize_as_inner_list(input) ⇒ String

Note:

Use of this method breaks RFC8941.

Serializes input as Inner List.

Parameters:

Returns:

  • (String)

    serialized output



59
60
61
# File 'lib/net/http/structured_field_values/serializer.rb', line 59

def self.serialize_as_inner_list(input)
  new.serialize_as_inner_list(input)
end

Instance Method Details

#serialize(obj) ⇒ String

Returns:

  • (String)


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/net/http/structured_field_values/serializer.rb', line 17

def serialize(obj)
  case obj
  when Array
    serialize_list(obj)
  when Hash
    serialize_dictionary(obj)
  else
    value, params = unpack_parameterized_value(obj)
    serialize_item(value, params)
  end

  result.encode(Encoding::ASCII)
end

#serialize_as_inner_list(input) ⇒ String

Note:

Use of this method breaks RFC8941.

Serializes input as Inner List.

Parameters:

Returns:

  • (String)

    serialized output



47
48
49
50
51
# File 'lib/net/http/structured_field_values/serializer.rb', line 47

def serialize_as_inner_list(input)
  arr, params = unpack_parameterized_value(input)
  serialize_inner_list(arr, params)
  result.encode(Encoding::ASCII)
end