CSI-ES-2324/Projs/PD2/internal/protocol/protocol.go
afonso b86992a10a
[PD2] Relatorio inicio
Co-authored-by: tsousa111 <tiagao2001@hotmail.com>
2024-05-31 23:14:14 +01:00

114 lines
2.5 KiB
Go

package protocol
import (
"time"
)
type (
SendMsg struct {
ToUID string `json:"to_uid"`
Subject []byte `json:"subject"`
Body []byte `json:"body"`
}
AnswerGetUserCert struct {
UID string `json:"uid"`
Certificate []byte `json:"certificate"`
}
StoreUserCert struct {
Certificate []byte `json:"certificate"`
}
AnswerGetUnreadMsgsInfo struct {
Page int `json:"page"`
NumPages int `json:"num_pages"`
MessagesInfo []MsgInfo `json:"messages_info"`
}
MsgInfo struct {
Num int `json:"num"`
FromUID string `json:"from_uid"`
Subject []byte `json:"subject"`
Timestamp time.Time `json:"timestamp"`
}
AnswerGetMsg struct {
FromUID string `json:"from_uid"`
ToUID string `json:"to_uid"`
Subject []byte `json:"subject"`
Body []byte `json:"body"`
Timestamp time.Time `json:"timestamp"`
}
PostRegister struct {
Password string `json:"password"`
Certificate []byte `json:"certificate"`
}
PostLogin struct {
UID string `json:"uid"`
Password string `json:"password"`
}
ReportError struct {
ErrorMessage string `json:"error"`
}
)
func NewSendMsg(toUID string, subject []byte, body []byte) SendMsg {
return SendMsg{
ToUID: toUID,
Subject: subject,
Body: body,
}
}
func NewAnswerGetUserCert(uid string, certificate []byte) AnswerGetUserCert {
return AnswerGetUserCert{
UID: uid,
Certificate: certificate,
}
}
func NewAnswerGetUnreadMsgsInfo(page int, numPages int, messagesInfo []MsgInfo) AnswerGetUnreadMsgsInfo {
return AnswerGetUnreadMsgsInfo{Page: page, NumPages: numPages, MessagesInfo: messagesInfo}
}
func NewMsgInfo(num int, fromUID string, subject []byte, timestamp time.Time) MsgInfo {
return MsgInfo{
Num: num,
FromUID: fromUID,
Subject: subject,
Timestamp: timestamp,
}
}
func NewPostRegister(Password string, Certificate []byte) PostRegister {
return PostRegister{
Password: Password,
Certificate: Certificate,
}
}
func NewStoreUserCert(certificate []byte) StoreUserCert {
return StoreUserCert{
Certificate: certificate,
}
}
func NewPostLogin(UID string, Password string) PostLogin {
return PostLogin{
UID: UID,
Password: Password,
}
}
func NewAnswerGetMsg(fromUID, toUID string, subject []byte, body []byte, timestamp time.Time, last bool) AnswerGetMsg {
return AnswerGetMsg{
FromUID: fromUID,
ToUID: toUID,
Subject: subject,
Body: body,
Timestamp: timestamp,
}
}