CSI-ES-2324/Projs/PD2/internal/client/datastore.go
afonso 49a29e43a7
[PD2] Server done?
Co-authored-by: tsousa111 <tiagao2001@hotmail.com>
2024-05-28 20:13:33 +01:00

47 lines
1 KiB
Go

package client
import (
"encoding/json"
"time"
)
type ClientMessage struct {
FromUID string
ToUID string
Subject string
Body string
Timestamp time.Time
}
type ClientMessageInfo struct {
Num int
FromUID string
Timestamp time.Time
Subject string
decryptError error
}
func newClientMessage(fromUID string, toUID string, subject string, body string, timestamp time.Time) ClientMessage {
return ClientMessage{FromUID: fromUID, ToUID: toUID, Subject: subject, Body: body, Timestamp: timestamp}
}
func newClientMessageInfo(num int, fromUID string, subject string, timestamp time.Time, err error) ClientMessageInfo {
return ClientMessageInfo{Num: num, FromUID: fromUID, Subject: subject, Timestamp: timestamp, decryptError: err}
}
func Marshal(data any) ([]byte, error) {
subject, err := json.Marshal(data)
if err != nil {
return nil, err
}
return subject, nil
}
func Unmarshal(data []byte) (string, error) {
var c string
err := json.Unmarshal(data, &c)
if err != nil {
return "", err
}
return c, nil
}