gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

reverse.go (1351B)


      1 package dns
      2 
      3 // StringToType is the reverse of TypeToString, needed for string parsing.
      4 var StringToType = reverseInt16(TypeToString)
      5 
      6 // StringToClass is the reverse of ClassToString, needed for string parsing.
      7 var StringToClass = reverseInt16(ClassToString)
      8 
      9 // StringToOpcode is a map of opcodes to strings.
     10 var StringToOpcode = reverseInt(OpcodeToString)
     11 
     12 // StringToRcode is a map of rcodes to strings.
     13 var StringToRcode = reverseInt(RcodeToString)
     14 
     15 func init() {
     16 	// Preserve previous NOTIMP typo, see github.com/miekg/dns/issues/733.
     17 	StringToRcode["NOTIMPL"] = RcodeNotImplemented
     18 }
     19 
     20 // StringToAlgorithm is the reverse of AlgorithmToString.
     21 var StringToAlgorithm = reverseInt8(AlgorithmToString)
     22 
     23 // StringToHash is a map of names to hash IDs.
     24 var StringToHash = reverseInt8(HashToString)
     25 
     26 // StringToCertType is the reverseof CertTypeToString.
     27 var StringToCertType = reverseInt16(CertTypeToString)
     28 
     29 // Reverse a map
     30 func reverseInt8(m map[uint8]string) map[string]uint8 {
     31 	n := make(map[string]uint8, len(m))
     32 	for u, s := range m {
     33 		n[s] = u
     34 	}
     35 	return n
     36 }
     37 
     38 func reverseInt16(m map[uint16]string) map[string]uint16 {
     39 	n := make(map[string]uint16, len(m))
     40 	for u, s := range m {
     41 		n[s] = u
     42 	}
     43 	return n
     44 }
     45 
     46 func reverseInt(m map[int]string) map[string]int {
     47 	n := make(map[string]int, len(m))
     48 	for u, s := range m {
     49 		n[s] = u
     50 	}
     51 	return n
     52 }