aboutsummaryrefslogtreecommitdiff
path: root/net/decode.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-07-24 20:11:23 +0000
committerFuwn <[email protected]>2021-07-24 20:11:23 +0000
commit688aec1791ca5ba357cef5afc4a4c6e11d8ff4c2 (patch)
tree73104855103207b7d04f385c255b8d891bf4715e /net/decode.go
downloadterra-688aec1791ca5ba357cef5afc4a4c6e11d8ff4c2.tar.xz
terra-688aec1791ca5ba357cef5afc4a4c6e11d8ff4c2.zip
feat(global): push development state
Diffstat (limited to 'net/decode.go')
-rw-r--r--net/decode.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/net/decode.go b/net/decode.go
new file mode 100644
index 0000000..2bc5051
--- /dev/null
+++ b/net/decode.go
@@ -0,0 +1,24 @@
+// Copyright (C) 2021-2021 The Whirlsplash Collective
+// SPDX-License-Identifier: GPL-3.0-only
+
+package net
+
+import "strconv"
+
+type Text struct {
+ Author string
+ Message string
+}
+
+// Decode a TEXT command from hexadecimal to a Text struct
+func DecodeText(data []byte) Text {
+ authorLength, _ := strconv.ParseInt(strconv.Itoa(int(data[4])), 16, 32)
+ authorLast := authorLength + 5
+ messageLength, _ := strconv.ParseInt(strconv.Itoa(int(data[authorLast])), 16, 32)
+ messageStart := authorLast + 1
+
+ return Text{
+ Author: string(data[5:(authorLast)]),
+ Message: string(data[messageStart : messageStart+(messageLength)]),
+ }
+}