This commit is contained in:
Adam Ierymenko 2019-09-30 20:03:03 -07:00
parent 47a08ccbd4
commit 6db2b8c66d
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
4 changed files with 8 additions and 15 deletions

View file

@ -170,23 +170,24 @@ func (l *Locator) MakeTXTRecords(key *LocatorDNSSigningKey) ([]string, error) {
return nil, ErrInternal
}
// MarshalJSON marshals this Locator as its byte encoding
func (l *Locator) MarshalJSON() ([]byte, error) {
return json.Marshal(l)
type locatorForUnmarshal struct {
Bytes []byte
}
// UnmarshalJSON unmarshals this Locator from a byte array in JSON.
func (l *Locator) UnmarshalJSON(j []byte) error {
err := json.Unmarshal(j, l)
var bytes locatorForUnmarshal
err := json.Unmarshal(j, &bytes)
if err != nil {
return err
}
tmp, err := NewLocatorFromBytes(l.Bytes)
tmp, err := NewLocatorFromBytes(bytes.Bytes)
if err != nil {
return err
}
l.Identity = tmp.Identity
l.Physical = tmp.Physical
l.Virtual = tmp.Virtual
l.Bytes = bytes.Bytes
return nil
}