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 ¶
- Variables
- type BitSet16
- type BitSet32
- type BitSet8
- type Buffer
- func (b *Buffer) Read(p []byte) (int, error)
- func (b *Buffer) ReadBEDString() DWordString
- func (b *Buffer) ReadBlob(len int) []byte
- func (b *Buffer) ReadBool32() bool
- func (b *Buffer) ReadBool8() bool
- func (b *Buffer) ReadByte() (byte, error)
- func (b *Buffer) ReadCString() (string, error)
- func (b *Buffer) ReadFloat32() float32
- func (b *Buffer) ReadFrom(r io.Reader) (int64, error)
- func (b *Buffer) ReadIP() net.IP
- func (b *Buffer) ReadLEDString() DWordString
- func (b *Buffer) ReadSizeFrom(r io.Reader, n int) (int, error)
- func (b *Buffer) ReadSockAddr() (SockAddr, error)
- func (b *Buffer) ReadUInt16() uint16
- func (b *Buffer) ReadUInt32() uint32
- func (b *Buffer) ReadUInt64() uint64
- func (b *Buffer) ReadUInt8() byte
- func (b *Buffer) Reset(p []byte)
- func (b *Buffer) Size() int
- func (b *Buffer) Skip(len int)
- func (b *Buffer) Truncate()
- func (b *Buffer) Write(p []byte) (int, error)
- func (b *Buffer) WriteBEDString(v DWordString)
- func (b *Buffer) WriteBEDStringAt(p int, v DWordString)
- func (b *Buffer) WriteBlob(v []byte)
- func (b *Buffer) WriteBlobAt(p int, v []byte)
- func (b *Buffer) WriteBool32(v bool)
- func (b *Buffer) WriteBool32At(p int, v bool)
- func (b *Buffer) WriteBool8(v bool)
- func (b *Buffer) WriteBool8At(p int, v bool)
- func (b *Buffer) WriteByte(c byte) error
- func (b *Buffer) WriteCString(v string)
- func (b *Buffer) WriteCStringAt(p int, v string)
- func (b *Buffer) WriteFloat32(v float32)
- func (b *Buffer) WriteFloat32At(p int, v float32)
- func (b *Buffer) WriteIP(v net.IP) error
- func (b *Buffer) WriteIPAt(p int, v net.IP) error
- func (b *Buffer) WriteLEDString(v DWordString)
- func (b *Buffer) WriteLEDStringAt(p int, v DWordString)
- func (b *Buffer) WriteSockAddr(v *SockAddr) error
- func (b *Buffer) WriteSockAddrAt(p int, v *SockAddr) error
- func (b *Buffer) WriteTo(w io.Writer) (int64, error)
- func (b *Buffer) WriteUInt16(v uint16)
- func (b *Buffer) WriteUInt16At(p int, v uint16)
- func (b *Buffer) WriteUInt32(v uint32)
- func (b *Buffer) WriteUInt32At(p int, v uint32)
- func (b *Buffer) WriteUInt64(v uint64)
- func (b *Buffer) WriteUInt64At(p int, v uint64)
- func (b *Buffer) WriteUInt8(v byte)
- func (b *Buffer) WriteUInt8At(p int, v byte)
- type DWordString
- type SockAddr
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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
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 (BitSet16) MarshalText ¶ added in v1.2.0
MarshalText implements TextMarshaler
func (*BitSet16) UnmarshalText ¶ added in v1.2.0
UnmarshalText implements TextUnmarshaler
type BitSet32 ¶
type BitSet32 uint32
BitSet32 is a set of 32 bits
func (BitSet32) MarshalText ¶ added in v1.2.0
MarshalText implements TextMarshaler
func (*BitSet32) UnmarshalText ¶ added in v1.2.0
UnmarshalText implements TextUnmarshaler
type BitSet8 ¶
type BitSet8 uint8
BitSet8 is a set of 8 bits
func (BitSet8) MarshalText ¶ added in v1.2.0
MarshalText implements TextMarshaler
func (*BitSet8) UnmarshalText ¶ added in v1.2.0
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) ReadBEDString ¶
func (b *Buffer) ReadBEDString() DWordString
ReadBEDString consumes a big-endian dword string and returns its value
func (*Buffer) ReadBool32 ¶
ReadBool32 consumes a bool and returns its value
func (*Buffer) ReadCString ¶
ReadCString consumes a null terminated string and returns its value
func (*Buffer) ReadFloat32 ¶
ReadFloat32 consumes a float32 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
ReadSizeFrom reads n bytes from r
func (*Buffer) ReadSockAddr ¶
ReadSockAddr consumes a SockAddr structure and returns its value
func (*Buffer) ReadUInt16 ¶
ReadUInt16 a uint16 and returns its value
func (*Buffer) ReadUInt32 ¶
ReadUInt32 consumes a uint32 and returns its value
func (*Buffer) ReadUInt64 ¶
ReadUInt64 consumes a uint32 and returns its value
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) WriteBlobAt ¶
WriteBlobAt overwrites position p in the buffer with blob v
func (*Buffer) WriteBool32 ¶
WriteBool32 appends bool v to the buffer
func (*Buffer) WriteBool32At ¶
WriteBool32At overwrites position p in the buffer with bool v
func (*Buffer) WriteBool8 ¶
WriteBool8 appends bool v to the buffer
func (*Buffer) WriteBool8At ¶
WriteBool8At overwrites position p in the buffer with bool v
func (*Buffer) WriteCString ¶
WriteCString appends null terminated string v to the buffer
func (*Buffer) WriteCStringAt ¶
WriteCStringAt overwrites position p in the buffer with null terminated string v
func (*Buffer) WriteFloat32 ¶
WriteFloat32 appends float32 v to the buffer
func (*Buffer) WriteFloat32At ¶
WriteFloat32At overwrites position p in the buffer with float32 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 ¶
WriteSockAddr appends SockAddr v to the buffer
func (*Buffer) WriteSockAddrAt ¶
WriteSockAddrAt overwrites position p in the buffer with SockAddr v
func (*Buffer) WriteUInt16 ¶
WriteUInt16 appends uint16 v to the buffer
func (*Buffer) WriteUInt16At ¶
WriteUInt16At overwrites position p in the buffer with uint16 v
func (*Buffer) WriteUInt32 ¶
WriteUInt32 appends uint32 v to the buffer
func (*Buffer) WriteUInt32At ¶
WriteUInt32At overwrites position p in the buffer with uint32 v
func (*Buffer) WriteUInt64 ¶
WriteUInt64 appends uint64 v to the buffer
func (*Buffer) WriteUInt64At ¶
WriteUInt64At overwrites position p in the buffer with uint64 v
func (*Buffer) WriteUInt8 ¶
WriteUInt8 appends uint8 v to the buffer
func (*Buffer) WriteUInt8At ¶
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 ¶
SockAddr stores a single socket connection tuple (port+ip) similar to Windows SOCKADDR_IN.
func (*SockAddr) Equal ¶
Equal compares s against o and returns true if they represent the same address
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. |