util

package
v0.0.0-...-1a2867a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2017 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

* Archon PSO Server * Copyright (C) 2014 Andrew Rodman * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * --------------------------------------------------------------------- * * Functions and constants shared between server components.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesFromStruct

func BytesFromStruct(data interface{}) ([]byte, int)

Serializes the fields of a struct to an array of bytes in the order in which the fields are declared. Calls panic() if data is not a struct or pointer to struct, or if there was an error writing a field.

func ConvertToUtf16

func ConvertToUtf16(str string) []byte

Convert a UTF-8 string to UTF-16 LE and return it as an array of bytes.

func ExpandUtf16

func ExpandUtf16(src []uint16) []uint8

Expands an array of UTF-16 elements to a slice of uint8 elements in little endian order. E.g: [0x1234] -> [0x34, 0x12]

func GetPacketSize

func GetPacketSize(data []byte) (uint16, error)

Extract the packet length from the first two bytes of data.

func PrintPayload

func PrintPayload(data []uint8, pktLen int)

Print the contents of a packet to stdout in two columns, one for bytes and the other for their ascii representation.

func StripPadding

func StripPadding(b []byte) []byte

Returns a slice of b without the trailing 0s.

func StructFromBytes

func StructFromBytes(data []byte, targetStruct interface{})

Populates the struct pointed to by targetStruct by reading in a stream of bytes and filling the values in sequential order.

func ZeroSlice

func ZeroSlice(arr []byte, length int)

Sets the values of a slice of bytes (up to length) to 0.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL