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
Provides access to the reader. @api private
Provides access to the reader. @api private
Public Class Methods
@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 17 def initialize(reader, loader) 18 @read = [] 19 @reader = reader 20 @loader = loader 21 end
Public Instance Methods
Read the next value from the reader.
@return [Object] the value that was read @api public
# File lib/puppet/pops/serialization/deserializer.rb 27 def read 28 val = @reader.read 29 case val 30 when Extension::Tabulation 31 @read[val.index] 32 when Extension::Default 33 :default 34 when Extension::ArrayStart 35 result = remember([]) 36 val.size.times { result << read } 37 result 38 when Extension::MapStart 39 result = remember({}) 40 val.size.times { key = read; result[key] = read } 41 result 42 when Extension::SensitiveStart 43 Types::PSensitiveType::Sensitive.new(read) 44 when Extension::PcoreObjectStart 45 type_name = val.type_name 46 type = Types::TypeParser.singleton.parse(type_name, @loader) 47 raise SerializationError, _("No implementation mapping found for Puppet Type %{type_name}") % { type_name: type_name } if type.is_a?(Types::PTypeReferenceType) 48 result = type.read(val.attribute_count, self) 49 if result.is_a?(Types::PObjectType) 50 existing_type = loader.load(:type, result.name) 51 if result.eql?(existing_type) 52 result = existing_type 53 else 54 # Add result to the loader unless it is equal to the existing_type. The add 55 # will only succeed when the existing_type is nil. 56 loader.add_entry(:type, result.name, result, nil) 57 end 58 end 59 result 60 when Extension::ObjectStart 61 type = read 62 type.read(val.attribute_count - 1, self) 63 when Numeric, String, true, false, nil 64 val 65 else 66 remember(val) 67 end 68 end
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 75 def remember(value) 76 @read << value 77 value 78 end