summaryrefslogtreecommitdiffstats
path: root/core/data.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/data.go')
-rw-r--r--core/data.go33
1 files changed, 22 insertions, 11 deletions
diff --git a/core/data.go b/core/data.go
index a96b56f..dd2777f 100644
--- a/core/data.go
+++ b/core/data.go
@@ -16,13 +16,14 @@ type Wrapper interface {
type PayloadType uint8
const (
- PayloadUnknown PayloadType = 0x00
- PayloadSuccess = 0x01
- PayloadError = 0x02
- PayloadHandshake = 0x03
- PayloadAuth = 0x04
- PayloadMessage = 0x05
- PayloadTest = 0xFF
+ PayloadUnknown PayloadType = 0x00
+ PayloadSuccess = 0x01
+ PayloadError = 0x02
+ PayloadHandshake = 0x03
+ PayloadUserAuth = 0x04
+ PayloadMessage = 0x05
+ PayloadServerAuth = 0x06
+ PayloadTest = 0xFF
)
type ErrorType uint8
@@ -33,6 +34,14 @@ const (
ErrorNotFound = 0x02
)
+type ConnType uint8
+
+const (
+ ConnTypeUnknown ConnType = 0x00
+ ConnTypeUser = 0x01
+ ConnTypeServer = 0x02
+)
+
type Frame struct {
Length uint16
Type PayloadType
@@ -99,7 +108,7 @@ func Decode(buf io.Reader) (any, error) {
err := binary.Read(buf, binary.BigEndian, &pTypeByte)
if err != nil {
- return nil, fmt.Errorf("cannot read payload type: %v", err)
+ return nil, fmt.Errorf("cannot read payload type: %w", err)
}
pType := PayloadType(pTypeByte)
@@ -107,7 +116,7 @@ func Decode(buf io.Reader) (any, error) {
var pLen uint16
err = binary.Read(buf, binary.BigEndian, &pLen)
if err != nil {
- return nil, fmt.Errorf("cannot read payload length: %v", err)
+ return nil, fmt.Errorf("cannot read payload length: %w", err)
}
switch pType {
@@ -117,8 +126,10 @@ func Decode(buf io.Reader) (any, error) {
return DecodeError(buf)
case PayloadHandshake:
return DecodeHandshake(buf)
- case PayloadAuth:
- return DecodeAuth(buf)
+ case PayloadUserAuth:
+ return DecodeUserAuth(buf)
+ case PayloadServerAuth:
+ return DecodeServerAuth(buf)
case PayloadMessage:
return DecodeMessage(buf)
case PayloadTest: