reverse.go 897 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package dns
  2. // StringToType is the reverse of TypeToString, needed for string parsing.
  3. var StringToType = reverseInt16(TypeToString)
  4. // StringToClass is the reverse of ClassToString, needed for string parsing.
  5. var StringToClass = reverseInt16(ClassToString)
  6. // StringToOpcode is a map of opcodes to strings.
  7. var StringToOpcode = reverseInt(OpcodeToString)
  8. // StringToRcode is a map of rcodes to strings.
  9. var StringToRcode = reverseInt(RcodeToString)
  10. // Reverse a map
  11. func reverseInt8(m map[uint8]string) map[string]uint8 {
  12. n := make(map[string]uint8, len(m))
  13. for u, s := range m {
  14. n[s] = u
  15. }
  16. return n
  17. }
  18. func reverseInt16(m map[uint16]string) map[string]uint16 {
  19. n := make(map[string]uint16, len(m))
  20. for u, s := range m {
  21. n[s] = u
  22. }
  23. return n
  24. }
  25. func reverseInt(m map[int]string) map[string]int {
  26. n := make(map[string]int, len(m))
  27. for u, s := range m {
  28. n[s] = u
  29. }
  30. return n
  31. }