Changed logic to typeswitch and added comments.

And also added my name to contrib list as promised before.
This commit is contained in:
Alex Sergeyev 2014-09-20 18:13:51 -04:00
parent 8aab8c6fb2
commit fcf9302ae1
2 changed files with 11 additions and 4 deletions

View File

@ -6,3 +6,4 @@ Dusty Wilson
Marek Majkowski
Peter van Dijk
Omri Bahumi
Alex Sergeyev

14
msg.go
View File

@ -577,13 +577,16 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str
default:
return lenmsg, &Error{err: "bad kind packing"}
case reflect.Interface:
if data, ok := fv.Interface().(PrivateRdata); ok {
// PrivateRR is the only RR implementation that has interface field.
// therefore it's expected that this interface would be PrivateRdata
switch data := fv.Interface().(type) {
case PrivateRdata:
n, err := data.WriteByteSlice(msg[off:])
if err != nil {
return lenmsg, err
}
off += n
} else {
default:
return lenmsg, &Error{err: "bad kind interface packing"}
}
case reflect.Slice:
@ -880,13 +883,16 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
default:
return lenmsg, &Error{err: "bad kind unpacking"}
case reflect.Interface:
if data, ok := fv.Interface().(PrivateRdata); ok {
// PrivateRR is the only RR implementation that has interface field.
// therefore it's expected that this interface would be PrivateRdata
switch data := fv.Interface().(type) {
case PrivateRdata:
n, err := data.ParseByteSlice(msg[off:rdend])
if err != nil {
return lenmsg, err
}
off += n
} else {
default:
return lenmsg, &Error{err: "bad kind interface unpacking"}
}
case reflect.Slice: