aboutsummaryrefslogtreecommitdiff
path: root/pkg/server/utils/decode.go
blob: e819b318c8cbbb2a3445eeff57c4eb71e752a2ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Copyright (C) 2021-2021 The Whirlsplash Collective
// SPDX-License-Identifier: GPL-3.0-only

package utils

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)]),
	}
}