libs5-go/metadata/media_meta_links.go

74 lines
1.5 KiB
Go
Raw Normal View History

2024-01-05 13:58:13 +00:00
package metadata
2024-03-01 05:18:07 +00:00
import (
"errors"
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
"github.com/vmihailenco/msgpack/v5"
)
var (
_ msgpack.CustomDecoder = (*MediaMetadataLinks)(nil)
_ msgpack.CustomEncoder = (*MediaMetadataLinks)(nil)
)
2024-01-05 13:58:13 +00:00
type MediaMetadataLinks struct {
Count int
Head []*encoding.CID
Collapsed []*encoding.CID
Tail []*encoding.CID
}
2024-03-01 05:18:07 +00:00
func (m MediaMetadataLinks) EncodeMsgpack(enc *msgpack.Encoder) error {
return errors.New("Not implemented")
}
func (m MediaMetadataLinks) DecodeMsgpack(dec *msgpack.Decoder) error {
data, err := decodeIntMap(dec)
if err != nil {
return err
}
for key, value := range data {
switch key {
case 1:
m.Count = value.(int)
case 2:
head := value.([]interface{})
for _, h := range head {
cid, err := encoding.CIDFromBytes(h.([]byte))
if err != nil {
return err
}
m.Head = append(m.Head, cid)
}
case 3:
collapsed := value.([]interface{})
for _, c := range collapsed {
cid, err := encoding.CIDFromBytes(c.([]byte))
if err != nil {
return err
}
m.Collapsed = append(m.Collapsed, cid)
}
case 4:
tail := value.([]interface{})
for _, t := range tail {
cid, err := encoding.CIDFromBytes(t.([]byte))
if err != nil {
return err
}
m.Tail = append(m.Tail, cid)
}
}
}
return nil
}
2024-01-05 13:58:13 +00:00
func NewMediaMetadataLinks(head []*encoding.CID) *MediaMetadataLinks {
return &MediaMetadataLinks{
Count: len(head),
Head: head,
}
}