class Puppet::Pops::Serialization::Deserializer

The deserializer is capable of reading, arrays, maps, and complex objects using an underlying protocol reader. It takes care of resolving tabulations and assembling complex objects. The type of the complex objects are resolved using a loader. @api public

Attributes

loader[R]

Provides access to the reader. @api private

reader[R]

Provides access to the reader. @api private

Public Class Methods

new(reader, loader) click to toggle source

@param [AbstractReader] reader the reader used when reading primitive objects from a stream @param [Loader::Loader] loader the loader used when resolving names of types @api public

   # File lib/puppet/pops/serialization/deserializer.rb
16 def initialize(reader, loader)
17   @read = []
18   @reader = reader
19   @loader = loader
20 end

Public Instance Methods

read() click to toggle source

Read the next value from the reader.

@return [Object] the value that was read @api public

   # File lib/puppet/pops/serialization/deserializer.rb
26 def read
27   val = @reader.read
28   case val
29   when Extension::Tabulation
30     @read[val.index]
31   when Extension::Default
32     :default
33   when Extension::ArrayStart
34     result = remember([])
35     val.size.times { result << read }
36     result
37   when Extension::MapStart
38     result = remember({})
39     val.size.times { key = read; result[key] = read }
40     result
41   when Extension::SensitiveStart
42     Types::PSensitiveType::Sensitive.new(read)
43   when Extension::PcoreObjectStart
44     type_name = val.type_name
45     type = Types::TypeParser.singleton.parse(type_name, @loader)
46     raise SerializationError, _("No implementation mapping found for Puppet Type %{type_name}") % { type_name: type_name } if type.is_a?(Types::PTypeReferenceType)
47     result = type.read(val.attribute_count, self)
48     if result.is_a?(Types::PObjectType)
49       existing_type = loader.load(:type, result.name)
50       if result.eql?(existing_type)
51         result = existing_type
52       else
53         # Add result to the loader unless it is equal to the existing_type. The add
54         # will only succeed when the existing_type is nil.
55         loader.add_entry(:type, result.name, result, nil)
56       end
57     end
58     result
59   when Extension::ObjectStart
60     type = read
61     type.read(val.attribute_count - 1, self)
62   when Numeric, String, true, false, nil
63     val
64   else
65     remember(val)
66   end
67 end
remember(value) click to toggle source

Remember that a value has been read. This means that the value is given an index and that subsequent reads of a tabulation with that index should return the value. @param [Object] value The value to remember @return [Object] the argument @api private

   # File lib/puppet/pops/serialization/deserializer.rb
74 def remember(value)
75   @read << value
76   value
77 end