diff options
Diffstat (limited to 'net/decode.go')
| -rw-r--r-- | net/decode.go | 24 |
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)]), + } +} |