Changes
2 changed files (+84/-10)
-
-
@@ -1,7 +1,10 @@package activitypub import ( "bytes" "encoding/gob" "errors" "fmt" "reflect" "strings" "time"
-
@@ -765,27 +768,84 @@ 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)) return a.GobDecode(data) } // 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)) return a.GobEncode() } func mapIntransitiveActivityProperties(mm map[string][]byte, a *IntransitiveActivity) (hasData bool, err error) { err = OnObject(a, func(o *Object) error { hasData, err = mapObjectProperties(mm, o) return err }) if a.Actor != nil { if mm["actor"], err = gobEncodeItem(a.Actor); err != nil { return hasData, err } hasData = true } if a.Target != nil { if mm["target"], err = gobEncodeItem(a.Target); err != nil { return hasData, err } hasData = true } if a.Result != nil { if mm["result"], err = gobEncodeItem(a.Result); err != nil { return hasData, err } hasData = true } if a.Instrument != nil { if mm["instrument"], err = gobEncodeItem(a.Instrument); err != nil { return hasData, err } hasData = true } return hasData, err } func mapActivityProperties(mm map[string][]byte, a *Activity) (hasData bool, err error) { err = OnIntransitiveActivity(a, func(a *IntransitiveActivity) error { hasData, err = mapIntransitiveActivityProperties(mm, a) return err }) if a.Object != nil { if mm["object"], err = gobEncodeItem(a.Object); err != nil { return hasData, err } hasData = true } return hasData, err } // GobEncode func (a Activity) GobEncode() ([]byte, error) { return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", a)) var mm = make(map[string][]byte) hasData, err := mapActivityProperties(mm, &a) if err != nil { return nil, err } if !hasData { return []byte{}, nil } bb := bytes.Buffer{} g := gob.NewEncoder(&bb) if err := g.Encode(mm); err != nil { return nil, err } return bb.Bytes(), nil } // 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 {
-
-
-
@@ -1,7 +1,10 @@package activitypub import ( "bytes" "encoding/gob" "errors" "fmt" "reflect" "time" "unsafe"
-
@@ -199,25 +202,36 @@ 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)) return i.GobDecode(data) } // 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)) return i.GobEncode() } func (i IntransitiveActivity) GobEncode() ([]byte, error) { return nil, errors.New(fmt.Sprintf("GobEncode is not implemented for %T", i)) var mm = make(map[string][]byte) hasData, err := mapIntransitiveActivityProperties(mm, &i) if err != nil { return nil, err } if !hasData { return []byte{}, nil } bb := bytes.Buffer{} g := gob.NewEncoder(&bb) if err := g.Encode(mm); err != nil { return nil, err } return bb.Bytes(), nil } 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 {
-