Debian Codegraph @

worker/jmap/cache/gob.go

raw
1 package cache
2
3 import (
4 "bytes"
5 "encoding/gob"
6
7 "git.sr.ht/~rockorager/go-jmap/mail/email"
8 "git.sr.ht/~rockorager/go-jmap/mail/mailbox"
9 )
10
11 type jmapObject interface {
12 *email.Email |
13 *email.QueryResponse |
14 *mailbox.Mailbox |
15 *FolderContents |
16 *IDList
17 }
18
19 func marshal[T jmapObject](obj T) ([]byte, error) {
20 buf := bytes.NewBuffer(nil)
21 encoder := gob.NewEncoder(buf)
22 err := encoder.Encode(obj)
23 if err != nil {
24 return nil, err
25 }
26 return buf.Bytes(), nil
27 }
28
29 func unmarshal[T jmapObject](data []byte, obj T) error {
30 buf := bytes.NewBuffer(data)
31 decoder := gob.NewDecoder(buf)
32 return decoder.Decode(obj)
33 }