diff --git a/actor.go b/actor.go index bd41bb3..b83b2f9 100644 --- a/actor.go +++ b/actor.go @@ -156,8 +156,8 @@ type Actor struct { // to a JSON-LD document with these properties. Endpoints *Endpoints `jsonld:"endpoints,omitempty"` // A list of supplementary Collections which may be of interest. - Streams []ItemCollection `jsonld:"streams,omitempty"` - PublicKey PublicKey `jsonld:"publicKey,omitempty"` + Streams ItemCollection `jsonld:"streams,omitempty"` + PublicKey PublicKey `jsonld:"publicKey,omitempty"` } // GetID returns the ID corresponding to the current Actor @@ -396,11 +396,7 @@ func (a Actor) MarshalJSON() ([]byte, error) { } if len(a.Streams) > 0 { writePropJSONName(&b, "streams") - lNotEmpty := true - for _, ss := range a.Streams { - lNotEmpty = writeItemCollectionJSONValue(&b, ss) || lNotEmpty - } - notEmpty = lNotEmpty || notEmpty + notEmpty = notEmpty || writeItemCollectionJSONValue(&b, a.Streams) } if len(a.PublicKey.PublicKeyPem)+len(a.PublicKey.ID) > 0 { if v, err := a.PublicKey.MarshalJSON(); err == nil && len(v) > 0 { diff --git a/decoding_gob.go b/decoding_gob.go index fbb25b7..7a66d2f 100644 --- a/decoding_gob.go +++ b/decoding_gob.go @@ -73,11 +73,11 @@ func unmapActorProperties(mm map[string][]byte, a *Actor) error { return err } } - //if raw, ok := mm["streams"]; ok { - // if err = a.Streams.GobDecode(raw); err != nil { - // return err - // } - //} + if raw, ok := mm["streams"]; ok { + if a.Streams, err = gobDecodeItems(raw); err != nil { + return err + } + } if raw, ok := mm["publicKey"]; ok { if err = a.PublicKey.GobDecode(raw); err != nil { return err diff --git a/decoding_json.go b/decoding_json.go index 46c90f4..bef52c4 100644 --- a/decoding_json.go +++ b/decoding_json.go @@ -132,11 +132,6 @@ func JSONGetPublicKey(val *fastjson.Value, prop string) PublicKey { return key } -func JSONGetStreams(val *fastjson.Value, prop string) []ItemCollection { - // TODO(marius) - return nil -} - func itemsFn(val *fastjson.Value) (Item, error) { if val.Type() == fastjson.TypeArray { it := val.GetArray() @@ -512,7 +507,7 @@ func loadActor(val *fastjson.Value, a *Actor) error { a.Outbox = JSONGetItem(val, "outbox") a.Liked = JSONGetItem(val, "liked") a.Endpoints = JSONGetActorEndpoints(val, "endpoints") - a.Streams = JSONGetStreams(val, "streams") + a.Streams = JSONGetItems(val, "streams") a.PublicKey = JSONGetPublicKey(val, "publicKey") return nil } diff --git a/encoding_gob.go b/encoding_gob.go index 73e2713..89a644f 100644 --- a/encoding_gob.go +++ b/encoding_gob.go @@ -47,15 +47,6 @@ func gobEncodeBool(t bool) ([]byte, error) { return b.Bytes(), nil } -func gobEncodeBytes(s []byte) ([]byte, error) { - b := bytes.Buffer{} - gg := gob.NewEncoder(&b) - if err := gg.Encode(s); err != nil { - return nil, err - } - return b.Bytes(), nil -} - func gobEncodeStringLikeType(g *gob.Encoder, s []byte) error { if err := g.Encode(s); err != nil { return err @@ -459,10 +450,10 @@ func mapActorProperties(mm map[string][]byte, a *Actor) (hasData bool, err error hasData = true } if len(a.Streams) > 0 { - //if mm["streams"], err = gobDecodeItem(a.Streams); err != nil { - // return hasData, err - //} - //hasData = true + if mm["streams"], err = gobEncodeItems(a.Streams); err != nil { + return hasData, err + } + hasData = true } if len(a.PublicKey.PublicKeyPem)+len(a.PublicKey.ID) > 0 { if mm["publicKey"], err = a.PublicKey.GobEncode(); err != nil {