[PD1] Fixed almost everything

This commit is contained in:
Afonso Franco 2024-04-19 23:59:26 +01:00
parent 39a0e5c01f
commit 7b3172a850
Signed by: afonso
SSH key fingerprint: SHA256:aiLbdlPwXKJS5wMnghdtod0SPy8imZjlVvCyUX9DJNk
13 changed files with 534 additions and 192 deletions

View file

@ -1,15 +1,47 @@
package client
import "time"
import (
"encoding/json"
"log"
"time"
)
type Content struct {
Subject []byte
Body []byte
}
type RecievedMessage struct {
type ClientMessage struct {
FromUID string
ToUID string
Content Content
Subject string
Body string
Timestamp time.Time
}
type ClientMessageInfo struct {
Num int
FromUID string
Timestamp time.Time
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
}