Skip to content

Commit

Permalink
Changed logic to typeswitch and added comments.
Browse files Browse the repository at this point in the history
And also added my name to contrib list as promised before.
  • Loading branch information
Alex Sergeyev committed Sep 20, 2014
1 parent 8aab8c6 commit fcf9302
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Dusty Wilson
Marek Majkowski
Peter van Dijk
Omri Bahumi
Alex Sergeyev
14 changes: 10 additions & 4 deletions msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit fcf9302

Please sign in to comment.