48 lines
1 KiB
Go
48 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
|
||
|
}
|