Be consistent in how we encode stringy types

Namely as []byte slices
This commit is contained in:
mariusor 2021-12-30 19:49:25 +01:00
parent 525748448c
commit f00af9750d
No known key found for this signature in database
GPG key ID: DBF5E47F5DBC4D21
6 changed files with 11 additions and 11 deletions

2
iri.go
View file

@ -98,7 +98,7 @@ func (i *IRI) GobDecode(data []byte) error {
// NOTE(marius): this behaviour diverges from vanilla gob package
return nil
}
var bb string
var bb []byte
if err := gob.NewDecoder(bytes.NewReader(data)).Decode(&bb); err != nil {
return err
}

View file

@ -332,7 +332,7 @@ func TestIRI_GobDecode(t *testing.T) {
{
name: "some iri",
i: "https://example.com",
data: gobValue("https://example.com"),
data: gobValue([]byte("https://example.com")),
wantErr: false,
},
}

View file

@ -3,9 +3,6 @@ package activitypub
import (
"bytes"
"encoding/gob"
"errors"
"fmt"
"github.com/valyala/fastjson"
)
@ -214,6 +211,9 @@ func gobDecodeUint(i *uint, data []byte) error {
}
func (l *Link) GobDecode(data []byte) error {
if len(data) == 0 {
return nil
}
mm := make(map[string][]byte)
g := gob.NewDecoder(bytes.NewReader(data))
if err := g.Decode(&mm); err != nil {
@ -264,5 +264,5 @@ func (l *Link) GobDecode(data []byte) error {
return err
}
}
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *l))
return nil
}

View file

@ -642,7 +642,7 @@ func TestLangRef_GobDecode(t *testing.T) {
{
name: "some text",
l: LangRef("ana are"),
data: gobValue([]byte{'a', 'n', 'a', ' ', 'a', 'r', 'e'}),
data: gobValue([]byte("ana are")),
wantErr: false,
},
}

View file

@ -130,7 +130,7 @@ func (a *ActivityVocabularyType) GobDecode(data []byte) error {
// NOTE(marius): this behaviour diverges from vanilla gob package
return nil
}
var bb string
var bb []byte
if err := gob.NewDecoder(bytes.NewReader(data)).Decode(&bb); err != nil {
return err
}
@ -402,7 +402,7 @@ func (m *MimeType) GobDecode(data []byte) error {
// NOTE(marius): this behaviour diverges from vanilla gob package
return nil
}
var bb string
var bb []byte
if err := gob.NewDecoder(bytes.NewReader(data)).Decode(&bb); err != nil {
return err
}

View file

@ -377,7 +377,7 @@ func TestMimeType_GobDecode(t *testing.T) {
{
name: "some mime-type",
m: "application/json",
data: gobValue("application/json"),
data: gobValue([]byte("application/json")),
wantErr: false,
},
}
@ -576,7 +576,7 @@ func TestActivityVocabularyType_GobDecode(t *testing.T) {
{
name: "some activity type",
t: PersonType,
data: gobValue("Person"),
data: gobValue([]byte("Person")),
wantErr: false,
},
}