[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
119
Projs/PD2/internal/protocol/protocol.go
Normal file
119
Projs/PD2/internal/protocol/protocol.go
Normal file
|
@ -0,0 +1,119 @@
|
|||
package protocol
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Body interface{}
|
||||
|
||||
type (
|
||||
GetUserCert struct {
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
GetUnreadMsgsInfo struct {
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
|
||||
GetMsg struct {
|
||||
Num int `json:"num"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
ReportError struct {
|
||||
ErrorMessage string `json:"error"`
|
||||
}
|
||||
)
|
||||
|
||||
func NewGetUserCert(UID string) GetUserCert {
|
||||
return GetUserCert{
|
||||
UID: UID,
|
||||
}
|
||||
}
|
||||
|
||||
func NewGetUnreadMsgsInfo(page int, pageSize int) GetUnreadMsgsInfo {
|
||||
return GetUnreadMsgsInfo{
|
||||
Page: page,
|
||||
PageSize: pageSize}
|
||||
}
|
||||
|
||||
func NewGetMsg(num int) GetMsg {
|
||||
return GetMsg{
|
||||
Num: num,
|
||||
}
|
||||
}
|
||||
|
||||
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 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,
|
||||
}
|
||||
}
|
||||
|
||||
func NewReportError(errorMessage string) ReportError {
|
||||
return ReportError{
|
||||
ErrorMessage: errorMessage,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue