[PD2] Server done?
Co-authored-by: tsousa111 <tiagao2001@hotmail.com>
This commit is contained in:
parent
08a73a4f76
commit
49a29e43a7
66 changed files with 2777 additions and 5 deletions
47
Projs/PD2/internal/client/datastore.go
Normal file
47
Projs/PD2/internal/client/datastore.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue