func()

in pkg/mgmapi/config_reader.go [126:196]


func (cr *configReader) readEntryFromSection(
	isNodesSection bool, sectionTypeFilter cfgSectionType, nodeIdFilter uint32, configKey uint32) (stopReading bool) {

	// read the header
	sectionLength := cr.readUint32()
	numOfEntries := int(cr.readUint32())
	sectionType := cfgSectionType(cr.readUint32())

	// Calculate the offset required to skip the section.
	// Increment the current offset by sectionLength in bytes
	// minus the header size(3 words), as they have been read already.
	endOfSectionOffset := cr.offset + (sectionLength-3)*4

	if sectionType != sectionTypeFilter {
		// Caller is not interested in this type of section - skip reading configSection.
		cr.offset = endOfSectionOffset
		return false
	}

	// put the entries that need to be extracted in a map
	configValues := make(map[uint32]interface{}, 2)
	configValues[configKey] = nil
	if isNodesSection {
		// This is a node section, read the nodeId
		configValues[nodeCfgNodeId] = nil
	}

	// read the required entries and extract the values
	// stop reading the section as soon as the required values are extracted
	numOfValuesExtracted := 0
	for i := 0; i < numOfEntries && numOfValuesExtracted < len(configValues); i++ {
		key, value := cr.readEntry()
		if _, exists := configValues[key]; exists {
			// this entry needs to be stored
			configValues[key] = value
			numOfValuesExtracted++
		}
	}

	// update offset to mark end of section
	cr.offset = endOfSectionOffset

	if !isNodesSection {
		// A default section is being read
		// Store the extracted value in configReader and return
		cr.value = configValues[configKey]
		// stop reading if this is a system section, if not continue
		return sectionType == cfgSectionTypeSystem
	}

	// Node Section
	sectionNodeId := configValues[nodeCfgNodeId]
	if sectionNodeId == nil {
		debug.Panic("nodeId not found in section")
		return true
	}

	if nodeIdFilter != 0 && nodeIdFilter != sectionNodeId.(uint32) {
		// Caller not interested in this node
		return false
	}

	// store the extracted value if it is not nil
	extractedValue := configValues[configKey]
	if extractedValue != nil {
		cr.value = extractedValue
	}

	// stop reading config as both the default, and the desired node section have been read
	return true
}