This repository has been archived on 2022-11-27. You can view files and clone it, but cannot push or open issues or pull requests.
activitypub/decoding_gob.go
2021-03-14 19:40:36 +01:00

45 lines
699 B
Go

package activitypub
import (
"bytes"
"encoding/gob"
)
func GobEncode(it Item) ([]byte, error) {
b := new(bytes.Buffer)
err := gob.NewEncoder(b).Encode(it)
return b.Bytes(), err
}
type hasType struct {
Type ActivityVocabularyType
}
func GobUnmarshalToItem(data []byte) Item {
if len(data) == 0 {
return nil
}
if ItemTyperFunc == nil {
return nil
}
typer := new(hasType)
err := gob.NewDecoder(bytes.NewReader(data)).Decode(typer)
if err != nil {
return nil
}
var it Item
switch typer.Type {
}
return it
}
// UnmarshalGob
func UnmarshalGob(data []byte) (Item, error) {
if ItemTyperFunc == nil {
ItemTyperFunc = GetItemByType
}
return GobUnmarshalToItem(data), nil
}