File: reverse.go

package info (click to toggle)
golang-github-miekg-dns 1.1.68-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 1,260 kB
  • sloc: makefile: 3
file content (55 lines) | stat: -rw-r--r-- 1,479 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package dns

// StringToType is the reverse of TypeToString, needed for string parsing.
var StringToType = reverseInt16(TypeToString)

// StringToClass is the reverse of ClassToString, needed for string parsing.
var StringToClass = reverseInt16(ClassToString)

// StringToOpcode is a map of opcodes to strings.
var StringToOpcode = reverseInt(OpcodeToString)

// StringToRcode is a map of rcodes to strings.
var StringToRcode = reverseInt(RcodeToString)

func init() {
	// Preserve previous NOTIMP typo, see github.com/miekg/dns/issues/733.
	StringToRcode["NOTIMPL"] = RcodeNotImplemented
}

// StringToAlgorithm is the reverse of AlgorithmToString.
var StringToAlgorithm = reverseInt8(AlgorithmToString)

// StringToHash is a map of names to hash IDs.
var StringToHash = reverseInt8(HashToString)

// StringToCertType is the reverse of CertTypeToString.
var StringToCertType = reverseInt16(CertTypeToString)

// StringToStatefulType is the reverse of StatefulTypeToString.
var StringToStatefulType = reverseInt16(StatefulTypeToString)

// Reverse a map
func reverseInt8(m map[uint8]string) map[string]uint8 {
	n := make(map[string]uint8, len(m))
	for u, s := range m {
		n[s] = u
	}
	return n
}

func reverseInt16(m map[uint16]string) map[string]uint16 {
	n := make(map[string]uint16, len(m))
	for u, s := range m {
		n[s] = u
	}
	return n
}

func reverseInt(m map[int]string) map[string]int {
	n := make(map[string]int, len(m))
	for u, s := range m {
		n[s] = u
	}
	return n
}