func (rs *ResourceSet) prepare() *state {
	var (
		nameSet     = make(map[Name]struct{})
		typeNameSet = make(map[Name]struct{})
		s           = &state{
			nameOffset: make(map[Name]int),
		}
	)

	rs.order(s)

	for ident, te := range rs.Types {
		if name, ok := ident.(Name); ok {
			typeNameSet[name] = struct{}{}
			nameSet[name] = struct{}{}
		}
		for _, name := range te.OrderedKeys[:te.NamesCount] {
			nameSet[name.(Name)] = struct{}{}
		}
	}

	names := make([]string, 0, len(nameSet))
	for n := range nameSet {
		names = append(names, string(n))
	}
	sort.Strings(names)

	offset := rs.dirSize()
	for _, n := range names {
		s.nameOffset[Name(n)] = offset
		u := utf16.Encode([]rune(n))
		s.namesData = append(s.namesData, uint16(len(u)))
		s.namesData = append(s.namesData, u...)
		offset += (len(u) + 1) * 2
	}

	// Names must be padded to align the resource data.
	sz := len(s.namesData) * 2
	s.namesData = append(s.namesData, make([]uint16, (alignData(sz)-sz)/2)...)
	return s
}
// prepare calculates the names index offset and content, as this has to be known before writing the resource directory.
// It also freezes the order of identifiers in the directory, so that subsequent write functions can rely on it.
prepare calculates the names index offset and content, as this has to be known before writing the resource directory.
It also freezes the order of identifiers in the directory, so that subsequent write functions can rely on it.
// prepare calculates the names index offset and content as this has to be known before writing the resource directory . // It also freezes the order of identifiers in the directory so that subsequent write functions can rely on it .
func (rs *ResourceSet) prepare() *state {
	var (
		nameSet     = make(map[Name]struct{})
		typeNameSet = make(map[Name]struct{})
		s           = &state{
			nameOffset: make(map[Name]int),
		}
	)
	rs.order(s)
	for ident, te := range rs.Types {
		if name, ok := ident.(Name); ok {
			typeNameSet[name] = struct{}{}
			nameSet[name] = struct{}{}
		}
		for _, name := range te.OrderedKeys[:te.NamesCount] {
			nameSet[name.(Name)] = struct{}{}
		}
	}
	names := make([]string, 0, len(nameSet))
	for n := range nameSet {
		names = append(names, string(n))
	}
	sort.Strings(names)
	offset := rs.dirSize()
	for _, n := range names {
		s.nameOffset[Name(n)] = offset
		u := utf16.Encode([]rune(n))
		s.namesData = append(s.namesData, uint16(len(u)))
		s.namesData = append(s.namesData, u...)
		offset += (len(u) + 1) * 2
	}
	sz := len(s.namesData) * 2
	s.namesData = append(s.namesData, make([]uint16, (alignData(sz)-sz)/2)...)
	return s
}
func ( rs * ResourceSet ) prepare ( ) * state { var ( nameSet = make ( map [ Name ] struct { } ) typeNameSet = make ( map [ Name ] struct { } ) s = & state { nameOffset : make ( map [ Name ] int ) , } ) rs . order ( s ) for ident , te := range rs . Types { if name , ok := ident . ( Name ) ; ok { typeNameSet [ name ] = struct { } { } nameSet [ name ] = struct { } { } } for _ , name := range te . OrderedKeys [ : te . NamesCount ] { nameSet [ name . ( Name ) ] = struct { } { } } } names := make ( [ ] string , 0 , len ( nameSet ) ) for n := range nameSet { names = append ( names , string ( n ) ) } sort . Strings ( names ) offset := rs . dirSize ( ) for _ , n := range names { s . nameOffset [ Name ( n ) ] = offset u := utf16 . Encode ( [ ] rune ( n ) ) s . namesData = append ( s . namesData , uint16 ( len ( u ) ) ) s . namesData = append ( s . namesData , u ... ) offset += ( len ( u ) + 1 ) * 2 } sz := len ( s . namesData ) * 2 s . namesData = append ( s . namesData , make ( [ ] uint16 , ( alignData ( sz ) - sz ) / 2 ) ... ) return s }
prepare calculates the names index offset and content, as this has to be known before writing the resource directory.
prepare calculates the names index offset and content as this has to be known before writing the resource directory .
// Names must be padded to align the resource data.