aboutsummaryrefslogtreecommitdiff
path: root/net/decode.go
blob: 2bc5051cfc6b74a18bf22f88017321e738110255 (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 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)]),
	}
}