9 // NumField returns the number of rdata fields r has.
10 func NumField(r RR) int {
11 return reflect.ValueOf(r).Elem().NumField() - 1 // Remove RR_Header
14 // Field returns the rdata field i as a string. Fields are indexed starting from 1.
15 // RR types that holds slice data, for instance the NSEC type bitmap will return a single
16 // string where the types are concatenated using a space.
17 // Accessing non existing fields will cause a panic.
18 func Field(r RR, i int) string {
22 d := reflect.ValueOf(r).Elem().Field(i)
26 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
27 return strconv.FormatInt(d.Int(), 10)
28 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
29 return strconv.FormatUint(d.Uint(), 10)
31 switch reflect.ValueOf(r).Elem().Type().Field(i).Tag {
33 // TODO(miek): Hmm store this as 16 bytes
34 if d.Len() < net.IPv6len {
35 return net.IPv4(byte(d.Index(0).Uint()),
36 byte(d.Index(1).Uint()),
37 byte(d.Index(2).Uint()),
38 byte(d.Index(3).Uint())).String()
40 return net.IPv4(byte(d.Index(12).Uint()),
41 byte(d.Index(13).Uint()),
42 byte(d.Index(14).Uint()),
43 byte(d.Index(15).Uint())).String()
46 byte(d.Index(0).Uint()),
47 byte(d.Index(1).Uint()),
48 byte(d.Index(2).Uint()),
49 byte(d.Index(3).Uint()),
50 byte(d.Index(4).Uint()),
51 byte(d.Index(5).Uint()),
52 byte(d.Index(6).Uint()),
53 byte(d.Index(7).Uint()),
54 byte(d.Index(8).Uint()),
55 byte(d.Index(9).Uint()),
56 byte(d.Index(10).Uint()),
57 byte(d.Index(11).Uint()),
58 byte(d.Index(12).Uint()),
59 byte(d.Index(13).Uint()),
60 byte(d.Index(14).Uint()),
61 byte(d.Index(15).Uint()),
67 s := Type(d.Index(0).Uint()).String()
68 for i := 1; i < d.Len(); i++ {
69 s += " " + Type(d.Index(i).Uint()).String()
73 // if it does not have a tag its a string slice
79 s := d.Index(0).String()
80 for i := 1; i < d.Len(); i++ {
81 s += " " + d.Index(i).String()