Simplify the Type gob encode/decode
This commit is contained in:
parent
af0f5aa0ee
commit
72008812b1
20
object.go
20
object.go
|
@ -114,28 +114,12 @@ func (a ActivityVocabularyType) MarshalJSON() ([]byte, error) {
|
|||
|
||||
// GobEncode
|
||||
func (a ActivityVocabularyType) GobEncode() ([]byte, error) {
|
||||
if len(a) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
b := bytes.Buffer{}
|
||||
gg := gob.NewEncoder(&b)
|
||||
if err := gobEncodeStringLikeType(gg, []byte(a)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b.Bytes(), nil
|
||||
return []byte(a), nil
|
||||
}
|
||||
|
||||
// GobDecode
|
||||
func (a *ActivityVocabularyType) GobDecode(data []byte) error {
|
||||
if len(data) == 0 {
|
||||
// NOTE(marius): this behaviour diverges from vanilla gob package
|
||||
return nil
|
||||
}
|
||||
var bb []byte
|
||||
if err := gob.NewDecoder(bytes.NewReader(data)).Decode(&bb); err != nil {
|
||||
return err
|
||||
}
|
||||
*a = ActivityVocabularyType(bb)
|
||||
*a = ActivityVocabularyType(data)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue