18 lines
531 B
Go
18 lines
531 B
Go
package game
|
|
|
|
import "encoding/binary"
|
|
|
|
// AppendString appends the length of the string followed by its contents.
|
|
func AppendString(data []byte, str string) []byte {
|
|
data = binary.LittleEndian.AppendUint32(data, uint32(len(str)))
|
|
data = append(data, []byte(str)...)
|
|
return data
|
|
}
|
|
|
|
// AppendStringBytes appends the length of the string followed by its contents.
|
|
func AppendStringBytes(data []byte, str []byte) []byte {
|
|
data = binary.LittleEndian.AppendUint32(data, uint32(len(str)))
|
|
data = append(data, str...)
|
|
return data
|
|
}
|