summaryrefslogtreecommitdiffstats
path: root/core/data.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/data.go')
-rw-r--r--core/data.go30
1 files changed, 22 insertions, 8 deletions
diff --git a/core/data.go b/core/data.go
index 16775db..b25b853 100644
--- a/core/data.go
+++ b/core/data.go
@@ -16,13 +16,21 @@ type PayloadType uint8
const (
PayloadUnknown PayloadType = 0x00
- PayloadHandshake = 0x01
- PayloadPing = 0x02
- PayloadPong = 0x03
- PayloadMessage = 0x04
+ PayloadSuccess = 0x01
+ PayloadError = 0x02
+ PayloadHandshake = 0x03
+ PayloadAuth = 0x04
+ PayloadMessage = 0x05
PayloadTest = 0xFF
)
+type ErrorType uint8
+
+const (
+ ErrorUnknown ErrorType = 0x00
+ ErrorAuthFailed = 0x01
+)
+
type Frame struct {
Length uint16
Type PayloadType
@@ -41,12 +49,13 @@ func Encode(w Wrapper) ([]byte, error) {
for _, p := range payload {
switch v := p.(type) {
case string:
- err := binary.Write(buf, binary.BigEndian, uint16(len(v)))
+ strBytes := []byte(v)
+ err := binary.Write(buf, binary.BigEndian, uint16(len(strBytes)))
if err != nil {
return []byte{}, fmt.Errorf("cannot encode string length: %v", err)
}
- _, err = buf.WriteString(v)
+ _, err = buf.Write(strBytes)
if err != nil {
return []byte{}, fmt.Errorf("cannot encode string: %v", err)
}
@@ -100,11 +109,16 @@ func Decode(buf io.Reader) (any, error) {
}
switch pType {
+ case PayloadSuccess:
+ return Success{}, nil
+ case PayloadError:
+ return DecodeError(buf)
case PayloadHandshake:
return DecodeHandshake(buf)
- case PayloadPing:
- case PayloadPong:
+ case PayloadAuth:
+ return DecodeAuth(buf)
case PayloadMessage:
+ return DecodeMessage(buf)
case PayloadTest:
return DecodeTest(buf)
default: