Adding placeholder Marshal/UnmarshalBinary and GobEncode/Decode

This commit is contained in:
Marius Orcsik 2021-03-14 19:36:32 +01:00
parent a65a3e9048
commit ac3d908e7b
No known key found for this signature in database
GPG key ID: 7970BDC7D4CB2674
15 changed files with 373 additions and 1 deletions

View file

@ -2,6 +2,7 @@ package activitypub
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
@ -758,6 +759,26 @@ func (a Activity) MarshalJSON() ([]byte, error) {
return b, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (a *Activity) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *a))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (a Activity) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", a))
}
// GobEncode
func (a Activity) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", a))
}
// GobDecode
func (a *Activity) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *a))
}
// Equals verifies if our receiver Object is equals with the "with" Object
func (a Activity) Equals(with Item) bool {
result := true

View file

@ -1,6 +1,7 @@
package activitypub
import (
"errors"
"fmt"
"github.com/buger/jsonparser"
"reflect"
@ -232,6 +233,24 @@ func (p PublicKey) MarshalJSON() ([]byte, error) {
return nil, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (a *Actor) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *a))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (a Actor) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", a))
}
func (a Actor) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", a))
}
func (a *Actor) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *a))
}
type (
// Application describes a software application.
Application = Actor

View file

@ -2,6 +2,7 @@ package activitypub
import (
"errors"
"fmt"
"reflect"
"time"
"unsafe"
@ -263,6 +264,24 @@ func (c Collection) MarshalJSON() ([]byte, error) {
return nil, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (c *Collection) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *c))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (c Collection) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", c))
}
func (c Collection) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", c))
}
func (c *Collection) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *c))
}
// ToCollection
func ToCollection(it Item) (*Collection, error) {
switch i := it.(type) {

View file

@ -2,6 +2,7 @@ package activitypub
import (
"errors"
"fmt"
"reflect"
"time"
)
@ -227,6 +228,24 @@ func (c CollectionPage) MarshalJSON() ([]byte, error) {
return nil, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (c *CollectionPage) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *c))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (c CollectionPage) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", c))
}
func (c CollectionPage) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", c))
}
func (c *CollectionPage) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *c))
}
// CollectionNew initializes a new CollectionPage
func CollectionPageNew(parent CollectionInterface) *CollectionPage {
p := CollectionPage{

View file

@ -2,6 +2,7 @@ package activitypub
import (
"errors"
"fmt"
"reflect"
"time"
"unsafe"
@ -192,6 +193,24 @@ func (i IntransitiveActivity) MarshalJSON() ([]byte, error) {
return b, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (i *IntransitiveActivity) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *i))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (i IntransitiveActivity) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", i))
}
func (i IntransitiveActivity) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", i))
}
func (i *IntransitiveActivity) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *i))
}
// IntransitiveActivityNew initializes a intransitive activity
func IntransitiveActivityNew(id ID, typ ActivityVocabularyType) *IntransitiveActivity {
if !IntransitiveActivityTypes.Contains(typ) {

27
iri.go
View file

@ -1,6 +1,8 @@
package activitypub
import (
"bytes"
"errors"
"fmt"
"github.com/buger/jsonparser"
"net/url"
@ -61,6 +63,31 @@ func (i IRI) MarshalJSON() ([]byte, error) {
return b, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (i *IRI) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *i))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (i IRI) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", i))
}
// GobEncode
func (i IRI) GobEncode() ([]byte, error) {
buf := bytes.NewBuffer(make([]byte, 0))
if _, err := writeIRIGobProp(buf, i); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
// GobDecode
func (i *IRI) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *i))
}
// AddPath concatenates el elements as a path to i
func (i IRI) AddPath(el ...string) IRI {
return IRI(fmt.Sprintf("%s/%s", i, path.Join(el...)))

22
link.go
View file

@ -1,5 +1,10 @@
package activitypub
import (
"errors"
"fmt"
)
var LinkTypes = ActivityVocabularyTypes{
LinkType,
MentionType,
@ -102,3 +107,20 @@ func (l *Link) UnmarshalJSON(data []byte) error {
return loadLink(data, l)
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (l *Link) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *l))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (l Link) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", l))
}
func (l Link) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", l))
}
func (l *Link) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *l))
}

View file

@ -1,6 +1,7 @@
package activitypub
import (
"errors"
"fmt"
"github.com/buger/jsonparser"
"reflect"
@ -108,6 +109,26 @@ func (a ActivityVocabularyType) MarshalJSON() ([]byte, error) {
return b, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (a *ActivityVocabularyType) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *a))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (a ActivityVocabularyType) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", a))
}
// GobEncode
func (a ActivityVocabularyType) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", a))
}
// GobDecode
func (a *ActivityVocabularyType) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *a))
}
// Object describes an ActivityPub object of any kind.
// It serves as the base type for most of the other kinds of objects defined in the Activity
// Vocabulary, including other Core types such as Activity, IntransitiveActivity, Collection and OrderedCollection.
@ -264,6 +285,26 @@ func (o Object) MarshalJSON() ([]byte, error) {
return nil, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (o *Object) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *o))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (o Object) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", o))
}
// GobEncode
func (o Object) GobEncode() ([]byte, error) {
return o.MarshalBinary()
}
// GobDecode
func (o *Object) GobDecode(data []byte) error {
return o.UnmarshalBinary(data)
}
// Recipients performs recipient de-duplication on the Object's To, Bto, CC and BCC properties
func (o *Object) Recipients() ItemCollection {
var aud ItemCollection
@ -311,6 +352,24 @@ func (m MimeType) MarshalJSON() ([]byte, error) {
return b, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (m *MimeType) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *m))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (m MimeType) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", m))
}
// GobEncode
func (m MimeType) GobEncode() ([]byte, error) {
if len(m) == 0 {
return nil, nil
}
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", m))
}
// ToLink returns a Link pointer to the data in the current Item
func ToLink(it Item) (*Link, error) {
switch i := it.(type) {
@ -439,6 +498,26 @@ func (s Source) MarshalJSON() ([]byte, error) {
return nil, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (s *Source) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *s))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (s Source) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", s))
}
// GobDecode
func (s *Source) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *s))
}
// GobEncode
func (s Source) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", s))
}
// Equals verifies if our receiver Object is equals with the "with" Object
func (o Object) Equals(with Item) bool {
if with.IsCollection() {

View file

@ -2,6 +2,7 @@ package activitypub
import (
"errors"
"fmt"
"reflect"
"time"
"unsafe"
@ -10,7 +11,7 @@ import (
// OrderedCollection is a subtype of Collection in which members of the logical
// collection are assumed to always be strictly ordered.
type OrderedCollection struct {
// ID provides the globally unique identifier for anActivity Pub Object or Link.
// ID provides the globally unique identifier for an Activity Pub Object or Link.
ID ID `jsonld:"id,omitempty"`
// Type identifies the Activity Pub Object or Link type. Multiple values may be specified.
Type ActivityVocabularyType `jsonld:"type,omitempty"`
@ -259,6 +260,26 @@ func (o OrderedCollection) MarshalJSON() ([]byte, error) {
return nil, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (o *OrderedCollection) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *o))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (o OrderedCollection) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", o))
}
// GobEncode
func (o OrderedCollection) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", o))
}
// GobDecode
func (o *OrderedCollection) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *o))
}
// OrderedCollectionPageNew initializes a new OrderedCollectionPage
func OrderedCollectionPageNew(parent CollectionInterface) *OrderedCollectionPage {
p := OrderedCollectionPage{

View file

@ -2,6 +2,7 @@ package activitypub
import (
"errors"
"fmt"
"reflect"
"time"
)
@ -230,6 +231,26 @@ func (o OrderedCollectionPage) MarshalJSON() ([]byte, error) {
return nil, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (o *OrderedCollectionPage) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *o))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (o OrderedCollectionPage) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", o))
}
// GobEncode
func (o OrderedCollectionPage) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", o))
}
// GobDecode
func (o *OrderedCollectionPage) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *o))
}
// ToOrderedCollectionPage
func ToOrderedCollectionPage(it Item) (*OrderedCollectionPage, error) {
switch i := it.(type) {

View file

@ -1,6 +1,7 @@
package activitypub
import (
"errors"
"fmt"
"reflect"
"time"
@ -191,6 +192,26 @@ func (p Place) MarshalJSON() ([]byte, error) {
return nil, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (p *Place) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *p))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (p Place) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", p))
}
// GobEncode
func (p Place) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", p))
}
// GobDecode
func (p *Place) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *p))
}
// Recipients performs recipient de-duplication on the Place object's To, Bto, CC and BCC properties
func (p *Place) Recipients() ItemCollection {
return ItemCollectionDeduplication(&p.To, &p.Bto, &p.CC, &p.BCC, &p.Audience)

View file

@ -1,6 +1,7 @@
package activitypub
import (
"errors"
"fmt"
"reflect"
"time"
@ -163,6 +164,26 @@ func (p Profile) MarshalJSON() ([]byte, error) {
return nil, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (p *Profile) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *p))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (p Profile) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", p))
}
// GobEncode
func (p Profile) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", p))
}
// GobDecode
func (p *Profile) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *p))
}
// Recipients performs recipient de-duplication on the Profile object's To, Bto, CC and BCC properties
func (p *Profile) Recipients() ItemCollection {
return ItemCollectionDeduplication(&p.To, &p.Bto, &p.CC, &p.BCC, &p.Audience)

View file

@ -2,6 +2,7 @@ package activitypub
import (
"errors"
"fmt"
"reflect"
"time"
)
@ -178,6 +179,26 @@ func (q Question) MarshalJSON() ([]byte, error) {
return b, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (q *Question) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *q))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (q Question) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", q))
}
// GobEncode
func (q Question) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", q))
}
// GobDecode
func (q *Question) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *q))
}
// QuestionNew initializes a Question activity
func QuestionNew(id ID) *Question {
q := Question{ID: id, Type: QuestionType}

View file

@ -1,6 +1,7 @@
package activitypub
import (
"errors"
"fmt"
"reflect"
"time"
@ -180,6 +181,26 @@ func (r Relationship) MarshalJSON() ([]byte, error) {
return nil, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (r *Relationship) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *r))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (r Relationship) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", r))
}
// GobEncode
func (r Relationship) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", r))
}
// GobDecode
func (r *Relationship) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *r))
}
// Recipients performs recipient de-duplication on the Relationship object's To, Bto, CC and BCC properties
func (r *Relationship) Recipients() ItemCollection {
return ItemCollectionDeduplication(&r.To, &r.Bto, &r.CC, &r.BCC, &r.Audience)

View file

@ -1,6 +1,7 @@
package activitypub
import (
"errors"
"fmt"
"reflect"
"time"
@ -169,6 +170,26 @@ func (t Tombstone) MarshalJSON() ([]byte, error) {
return nil, nil
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (t *Tombstone) UnmarshalBinary(data []byte) error {
return errors.New(fmt.Sprintf("UnmarshalBinary is not implemented for %T", *t))
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (t Tombstone) MarshalBinary() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("MarshalBinary is not implemented for %T", t))
}
// GobEncode
func (t Tombstone) GobEncode() ([]byte, error) {
return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", t))
}
// GobDecode
func (t *Tombstone) GobDecode([]byte) error {
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *t))
}
// Recipients performs recipient de-duplication on the Tombstone object's To, Bto, CC and BCC properties
func (t *Tombstone) Recipients() ItemCollection {
return ItemCollectionDeduplication(&t.To, &t.Bto, &t.CC, &t.BCC, &t.Audience)