encryption + helpers + contact card compression + server routing start

This commit is contained in:
ycc
2022-10-22 14:41:48 +02:00
parent 2160babeae
commit fc3747a124
15 changed files with 350 additions and 24 deletions

View File

@ -1,6 +1,8 @@
package meowlib
import (
"bytes"
"compress/gzip"
"encoding/json"
"fmt"
"image"
@ -27,6 +29,31 @@ func (Contact *ContactCard) AddUrls(urls []string) {
}
}
func (contact *ContactCard) Serialize() ([]byte, error) {
out, err := proto.Marshal(contact)
if err != nil {
return nil, err
}
return out, nil
}
func (contact *ContactCard) Compress() ([]byte, error) {
out, err := contact.Serialize()
if err != nil {
return nil, err
}
var b bytes.Buffer
gz := gzip.NewWriter(&b)
if _, err := gz.Write(out); err != nil {
log.Fatal(err)
}
if err := gz.Close(); err != nil {
log.Fatal(err)
}
fmt.Println(b.Bytes())
return b.Bytes(), nil
}
func (contact *ContactCard) WritePng(filename string) {
out, err := proto.Marshal(contact)
if err != nil {