2024-04-17 19:56:30 +01:00
|
|
|
package client
|
|
|
|
|
2024-04-19 23:59:26 +01:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
)
|
2024-04-17 19:56:30 +01:00
|
|
|
|
2024-04-19 23:59:26 +01:00
|
|
|
type ClientMessage struct {
|
|
|
|
FromUID string
|
|
|
|
ToUID string
|
|
|
|
Subject string
|
|
|
|
Body string
|
|
|
|
Timestamp time.Time
|
2024-04-17 19:56:30 +01:00
|
|
|
}
|
|
|
|
|
2024-04-19 23:59:26 +01:00
|
|
|
type ClientMessageInfo struct {
|
|
|
|
Num int
|
2024-04-17 19:56:30 +01:00
|
|
|
FromUID string
|
|
|
|
Timestamp time.Time
|
2024-04-19 23:59:26 +01:00
|
|
|
Subject string
|
|
|
|
}
|
|
|
|
|
|
|
|
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) ClientMessageInfo {
|
|
|
|
return ClientMessageInfo{Num:num,FromUID: fromUID,Subject: subject,Timestamp: timestamp}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Marshal(data any) []byte {
|
|
|
|
subject, err := json.Marshal(data)
|
|
|
|
if err != nil {
|
|
|
|
log.Panicf("Error when marshalling message: %v", err)
|
|
|
|
}
|
|
|
|
return subject
|
|
|
|
}
|
|
|
|
|
|
|
|
func Unmarshal(data []byte) string {
|
|
|
|
var c string
|
|
|
|
err := json.Unmarshal(data, &c)
|
|
|
|
if err != nil {
|
|
|
|
log.Panicln("Could not unmarshal data")
|
|
|
|
}
|
|
|
|
return c
|
2024-04-17 19:56:30 +01:00
|
|
|
}
|