protocol

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2022 License: MPL-2.0 Imports: 8 Imported by: 22

Documentation

Overview

Package protocol implements common utilities for Warcraft III network protocols.

Example
package main

import (
	"fmt"

	"github.com/nielsAD/gowarcraft3/protocol"
)

func main() {
	var pbuf protocol.Buffer
	pbuf.WriteUInt32(0x01)
	pbuf.WriteUInt16(0x02)
	pbuf.WriteUInt8(0x03)
	pbuf.WriteCString("4")

	fmt.Println(pbuf.ReadUInt32())
	fmt.Println(pbuf.ReadUInt16())
	fmt.Println(pbuf.ReadUInt8())

	str, err := pbuf.ReadCString()
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(str)

	pbuf = protocol.Buffer{Bytes: []byte{5, 0, 0, 0}}
	fmt.Println(pbuf.ReadUInt32())

}
Output:

1
2
3
4
5

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidIP4               = errors.New("pbuf: Invalid IP4 address")
	ErrInvalidSockAddr          = errors.New("pbuf: Invalid SockAddr structure")
	ErrNoCStringTerminatorFound = errors.New("pbuf: No null terminator for string found in buffer")
)

Errors

View Source
var (
	ErrInvalidDString = errors.New("dwstr: Length of input for DString() exceeds 4")
)

Errors

Functions

This section is empty.

Types

type BitSet16

type BitSet16 uint16

BitSet16 is a set of 16 bits

func BS16

func BS16(b ...bool) BitSet16

BS16 is a BitSet16 contructor

func (*BitSet16) Clear

func (b *BitSet16) Clear(i uint) *BitSet16

Clear bit i

func (BitSet16) MarshalText added in v1.2.0

func (b BitSet16) MarshalText() ([]byte, error)

MarshalText implements TextMarshaler

func (*BitSet16) Set

func (b *BitSet16) Set(i uint) *BitSet16

Set bit i

func (BitSet16) String

func (b BitSet16) String() string

func (BitSet16) Test

func (b BitSet16) Test(i uint) bool

Test if bit i is in set

func (*BitSet16) UnmarshalText added in v1.2.0

func (b *BitSet16) UnmarshalText(txt []byte) error

UnmarshalText implements TextUnmarshaler

type BitSet32

type BitSet32 uint32

BitSet32 is a set of 32 bits

func BS32

func BS32(b ...bool) BitSet32

BS32 is a BitSet32 contructor

func (*BitSet32) Clear

func (b *BitSet32) Clear(i uint) *BitSet32

Clear bit i

func (BitSet32) MarshalText added in v1.2.0

func (b BitSet32) MarshalText() ([]byte, error)

MarshalText implements TextMarshaler

func (*BitSet32) Set

func (b *BitSet32) Set(i uint) *BitSet32

Set bit i

func (BitSet32) String

func (b BitSet32) String() string

func (BitSet32) Test

func (b BitSet32) Test(i uint) bool

Test if bit i is in set

func (*BitSet32) UnmarshalText added in v1.2.0

func (b *BitSet32) UnmarshalText(txt []byte) error

UnmarshalText implements TextUnmarshaler

type BitSet8

type BitSet8 uint8

BitSet8 is a set of 8 bits

func BS8

func BS8(b ...bool) BitSet8

BS8 is a BitSet8 contructor

func (*BitSet8) Clear

func (b *BitSet8) Clear(i uint) *BitSet8

Clear bit i

func (BitSet8) MarshalText added in v1.2.0

func (b BitSet8) MarshalText() ([]byte, error)

MarshalText implements TextMarshaler

func (*BitSet8) Set

func (b *BitSet8) Set(i uint) *BitSet8

Set bit i

func (BitSet8) String

func (b BitSet8) String() string

func (BitSet8) Test

func (b BitSet8) Test(i uint) bool

Test if bit i is in set

func (*BitSet8) UnmarshalText added in v1.2.0

func (b *BitSet8) UnmarshalText(txt []byte) error

UnmarshalText implements TextUnmarshaler

type Buffer

type Buffer struct {
	Bytes []byte
}

Buffer wraps a []byte slice and adds helper functions for binary (de)serialization

func (*Buffer) Read

func (b *Buffer) Read(p []byte) (int, error)

Read implements io.Reader interface

func (*Buffer) ReadBEDString

func (b *Buffer) ReadBEDString() DWordString

ReadBEDString consumes a big-endian dword string and returns its value

func (*Buffer) ReadBlob

func (b *Buffer) ReadBlob(len int) []byte

ReadBlob consumes a blob of size len and returns (a slice of) its value

func (*Buffer) ReadBool32

func (b *Buffer) ReadBool32() bool

ReadBool32 consumes a bool and returns its value

func (*Buffer) ReadBool8

func (b *Buffer) ReadBool8() bool

ReadBool8 consumes a bool and returns its value

func (*Buffer) ReadByte added in v1.5.0

func (b *Buffer) ReadByte() (byte, error)

ReadByte implements io.ByteReader interface

func (*Buffer) ReadCString

func (b *Buffer) ReadCString() (string, error)

ReadCString consumes a null terminated string and returns its value

func (*Buffer) ReadFloat32

func (b *Buffer) ReadFloat32() float32

ReadFloat32 consumes a float32 and returns its value

func (*Buffer) ReadFrom added in v1.5.0

func (b *Buffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements io.ReaderFrom interface

func (*Buffer) ReadIP

func (b *Buffer) ReadIP() net.IP

ReadIP consumes an ip and returns its value

func (*Buffer) ReadLEDString

func (b *Buffer) ReadLEDString() DWordString

ReadLEDString consumes a little-endian dword string and returns its value

func (*Buffer) ReadSizeFrom added in v1.5.0

func (b *Buffer) ReadSizeFrom(r io.Reader, n int) (int, error)

ReadSizeFrom reads n bytes from r

func (*Buffer) ReadSockAddr

func (b *Buffer) ReadSockAddr() (SockAddr, error)

ReadSockAddr consumes a SockAddr structure and returns its value

func (*Buffer) ReadUInt16

func (b *Buffer) ReadUInt16() uint16

ReadUInt16 a uint16 and returns its value

func (*Buffer) ReadUInt32

func (b *Buffer) ReadUInt32() uint32

ReadUInt32 consumes a uint32 and returns its value

func (*Buffer) ReadUInt64

func (b *Buffer) ReadUInt64() uint64

ReadUInt64 consumes a uint32 and returns its value

func (*Buffer) ReadUInt8

func (b *Buffer) ReadUInt8() byte

ReadUInt8 consumes a uint8 and returns its value

func (*Buffer) Reset added in v1.5.0

func (b *Buffer) Reset(p []byte)

Reset buffer to p

func (*Buffer) Size

func (b *Buffer) Size() int

Size returns the total size of the buffer

func (*Buffer) Skip

func (b *Buffer) Skip(len int)

Skip consumes len bytes and throws away the result

func (*Buffer) Truncate

func (b *Buffer) Truncate()

Truncate resets the buffer to size 0

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (int, error)

Write implements io.Writer interface

func (*Buffer) WriteBEDString

func (b *Buffer) WriteBEDString(v DWordString)

WriteBEDString appends big-endian dword string v to the buffer

func (*Buffer) WriteBEDStringAt

func (b *Buffer) WriteBEDStringAt(p int, v DWordString)

WriteBEDStringAt overwrites position p in the buffer with big-endian dword string v

func (*Buffer) WriteBlob

func (b *Buffer) WriteBlob(v []byte)

WriteBlob appends blob v to the buffer

func (*Buffer) WriteBlobAt

func (b *Buffer) WriteBlobAt(p int, v []byte)

WriteBlobAt overwrites position p in the buffer with blob v

func (*Buffer) WriteBool32

func (b *Buffer) WriteBool32(v bool)

WriteBool32 appends bool v to the buffer

func (*Buffer) WriteBool32At

func (b *Buffer) WriteBool32At(p int, v bool)

WriteBool32At overwrites position p in the buffer with bool v

func (*Buffer) WriteBool8

func (b *Buffer) WriteBool8(v bool)

WriteBool8 appends bool v to the buffer

func (*Buffer) WriteBool8At

func (b *Buffer) WriteBool8At(p int, v bool)

WriteBool8At overwrites position p in the buffer with bool v

func (*Buffer) WriteByte added in v1.5.0

func (b *Buffer) WriteByte(c byte) error

WriteByte implements io.ByteWriter interface

func (*Buffer) WriteCString

func (b *Buffer) WriteCString(v string)

WriteCString appends null terminated string v to the buffer

func (*Buffer) WriteCStringAt

func (b *Buffer) WriteCStringAt(p int, v string)

WriteCStringAt overwrites position p in the buffer with null terminated string v

func (*Buffer) WriteFloat32

func (b *Buffer) WriteFloat32(v float32)

WriteFloat32 appends float32 v to the buffer

func (*Buffer) WriteFloat32At

func (b *Buffer) WriteFloat32At(p int, v float32)

WriteFloat32At overwrites position p in the buffer with float32 v

func (*Buffer) WriteIP

func (b *Buffer) WriteIP(v net.IP) error

WriteIP appends ip v to the buffer

func (*Buffer) WriteIPAt

func (b *Buffer) WriteIPAt(p int, v net.IP) error

WriteIPAt overwrites position p in the buffer with ip v

func (*Buffer) WriteLEDString

func (b *Buffer) WriteLEDString(v DWordString)

WriteLEDString appends little-endian dword string v to the buffer

func (*Buffer) WriteLEDStringAt

func (b *Buffer) WriteLEDStringAt(p int, v DWordString)

WriteLEDStringAt overwrites position p in the buffer with little-endian dword string v

func (*Buffer) WriteSockAddr

func (b *Buffer) WriteSockAddr(v *SockAddr) error

WriteSockAddr appends SockAddr v to the buffer

func (*Buffer) WriteSockAddrAt

func (b *Buffer) WriteSockAddrAt(p int, v *SockAddr) error

WriteSockAddrAt overwrites position p in the buffer with SockAddr v

func (*Buffer) WriteTo added in v1.5.0

func (b *Buffer) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo interface

func (*Buffer) WriteUInt16

func (b *Buffer) WriteUInt16(v uint16)

WriteUInt16 appends uint16 v to the buffer

func (*Buffer) WriteUInt16At

func (b *Buffer) WriteUInt16At(p int, v uint16)

WriteUInt16At overwrites position p in the buffer with uint16 v

func (*Buffer) WriteUInt32

func (b *Buffer) WriteUInt32(v uint32)

WriteUInt32 appends uint32 v to the buffer

func (*Buffer) WriteUInt32At

func (b *Buffer) WriteUInt32At(p int, v uint32)

WriteUInt32At overwrites position p in the buffer with uint32 v

func (*Buffer) WriteUInt64

func (b *Buffer) WriteUInt64(v uint64)

WriteUInt64 appends uint64 v to the buffer

func (*Buffer) WriteUInt64At

func (b *Buffer) WriteUInt64At(p int, v uint64)

WriteUInt64At overwrites position p in the buffer with uint64 v

func (*Buffer) WriteUInt8

func (b *Buffer) WriteUInt8(v byte)

WriteUInt8 appends uint8 v to the buffer

func (*Buffer) WriteUInt8At

func (b *Buffer) WriteUInt8At(p int, v byte)

WriteUInt8At overwrites position p in the buffer with uint8 v

type DWordString

type DWordString uint32

DWordString is a string of size dword (4 bytes / characters)

func DString

func DString(str string) DWordString

DString converts str to DWordString panic if input invalid

func (DWordString) MarshalText added in v1.2.0

func (s DWordString) MarshalText() ([]byte, error)

MarshalText implements TextMarshaler

func (DWordString) String

func (s DWordString) String() string

func (*DWordString) UnmarshalText added in v1.1.0

func (s *DWordString) UnmarshalText(txt []byte) error

UnmarshalText implements TextUnmarshaler

type SockAddr

type SockAddr struct {
	Port uint16
	IP   net.IP
}

SockAddr stores a single socket connection tuple (port+ip) similar to Windows SOCKADDR_IN.

func Addr

func Addr(a net.Addr) SockAddr

Addr converts net.Addr to SockAddr

func (*SockAddr) Equal

func (s *SockAddr) Equal(o *SockAddr) bool

Equal compares s against o and returns true if they represent the same address

func (*SockAddr) IPAddr

func (s *SockAddr) IPAddr() *net.IPAddr

IPAddr converts SockAddr to net.IPAddr (ignores port)

func (*SockAddr) TCPAddr

func (s *SockAddr) TCPAddr() *net.TCPAddr

TCPAddr converts SockAddr to net.TCPAddr

func (*SockAddr) UDPAddr

func (s *SockAddr) UDPAddr() *net.UDPAddr

UDPAddr converts SockAddr to net.UDPAddr

Directories

Path Synopsis
Package bncs implements the old Battle.net chat protocol for Warcraft III.
Package bncs implements the old Battle.net chat protocol for Warcraft III.
Package capi implements the datastructures for the official classic Battle.net chat API.
Package capi implements the datastructures for the official classic Battle.net chat API.
Package w3gs implements the game protocol for Warcraft III.
Package w3gs implements the game protocol for Warcraft III.

Jump to

Keyboard shortcuts

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