data

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Packate data provides utilities to read and write EO data types.

Index

Constants

View Source
const (
	CHAR_MAX  int = 253                            // represents the maximum value of an EO char  (1-byte encoded integer)
	SHORT_MAX int = CHAR_MAX * CHAR_MAX            // represents the maximum value of an EO short (2-byte encoded integer)
	THREE_MAX int = CHAR_MAX * CHAR_MAX * CHAR_MAX // represents the maximum value of an EO three (3-byte encoded integer)
	INT_MAX   int = SHORT_MAX * SHORT_MAX          // represents the maximum value of an EO int   (4-byte encoded integer)
)

Numeric maximum values for different EO data sizes

Variables

This section is empty.

Functions

func BytesFromString

func BytesFromString(str string) []byte

BytesFromString converts a string to a sequence of bytes using the Windows-1252 character set

func DecodeNumber

func DecodeNumber(bytes []byte) int

DecodeNumber decodes a number from a sequence of bytes.

func DecodeString

func DecodeString(bytes []byte) []byte

DecodeString decodes a string by reversing the bytes and then inverting them.

func EncodeNumber

func EncodeNumber(number int) []byte

EncodeNumber encodes a number to a sequence of bytes.

func EncodeString

func EncodeString(str []byte) []byte

EncodeString encodes a string by inverting the bytes and then reversing them.

func StringFromBytes

func StringFromBytes(bytes []byte) string

StringFromBytes converts a sequence of bytes to a string using the Windows-1252 character set

Types

type EoReader

type EoReader struct {
	// contains filtered or unexported fields
}

EoReader encapsulates operations related to reading EO data from a sequence of bytes.

EoReader features a "chunked" reading mode, which is important for accurate emulation of the official game client.

See chunked reading for more information.

func NewEoReader

func NewEoReader(data []byte) *EoReader

NewEoReader initializes an data.EoReader with the data in the specified byte slice.

func (*EoReader) GetByte

func (r *EoReader) GetByte() byte

GetByte reads a raw byte from the input data.

func (*EoReader) GetBytes

func (r *EoReader) GetBytes(length int) []byte

GetBytes reads an array of raw bytes from the input data.

func (*EoReader) GetChar

func (r *EoReader) GetChar() int

GetChar reads an encoded 1-byte integer from the input data.

func (*EoReader) GetEncodedString

func (r *EoReader) GetEncodedString() (string, error)

GetEncodedString reads and decodes an encoded string from the input data.

func (*EoReader) GetFixedEncodedString

func (r *EoReader) GetFixedEncodedString(length int) (string, error)

GetFixedEncodedString reads and decodes a fixed string from the input data.

func (*EoReader) GetFixedString

func (r *EoReader) GetFixedString(length int) (string, error)

GetFixedString reads an unencoded fixed string from the input data.

func (*EoReader) GetInt

func (r *EoReader) GetInt() int

GetInt reads an encoded 4-byte integer from the input data.

func (*EoReader) GetPaddedEncodedString

func (r *EoReader) GetPaddedEncodedString(length int) (string, error)

GetPaddedEncodedString reads and decodes a fixed string from the input data and removes trailing padding bytes (0xFF value).

func (*EoReader) GetPaddedString

func (r *EoReader) GetPaddedString(length int) (string, error)

GetPaddedString reads an unencoded fixed string from the input data and removes trailing padding bytes (0xFF value).

func (*EoReader) GetShort

func (r *EoReader) GetShort() int

GetShort reads an encoded 2-byte integer from the input data.

func (*EoReader) GetString

func (r *EoReader) GetString() (string, error)

GetString reads an unencoded string from the input data.

func (*EoReader) GetThree

func (r *EoReader) GetThree() int

GetThree reads an encoded 3-byte integer from the input data.

func (*EoReader) IsChunked

func (r *EoReader) IsChunked() bool

IsChunked gets whether chunked reading is enabled for the reader.

func (*EoReader) Length

func (r *EoReader) Length() int

Length gets the length of the input data.

func (*EoReader) NextChunk

func (r *EoReader) NextChunk() error

NextChunk moves the reader position to the start of the next chunk in the input data. An error is returned if the reader is not in chunked reading mode.

func (*EoReader) Position

func (r *EoReader) Position() int

Position gets the current position in the input data.

func (*EoReader) Read

func (r *EoReader) Read(b []byte) (n int, err error)

Read satisfies the io.Reader interface.

Read will read up to len(b) bytes into b. It returns the number of bytes read (0 <= n <= len(b)) and any error encountered.

If Read returns n < len(b), it may use all of b as scratch space during the call. If some data is available but not len(b) bytes, Read returns what is available instead of waiting for more.

When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read. In the end-of-file condition, it returns the (non-nil) error and n == 0 from a subsequent call.

func (*EoReader) Remaining

func (r *EoReader) Remaining() int

GetRemaining returns the number of bytes remaining in the input data.

If chunked reading mode is enabled, gets the number of bytes remaining in the current chunk. Otherwise, gets the total number of bytes remaining in the input data.

func (*EoReader) Seek

func (r *EoReader) Seek(offset int64, whence int) (i int64, err error)

Seek satisfies the io.Seeker interface.

Seek sets the current position of the reader to the specified offset, based on the specified value of whence. - io.SeekStart will set the absolute position of the reader relative to the start of the data. - io.SeekCurrent will set a relative position of the reader based on the current read position. - io.SeekEnd will set an absolute position from the end of the file (negative offset).

Seek returns the new position of the reader and/or any error that occurred while seeking.

func (*EoReader) SetIsChunked

func (r *EoReader) SetIsChunked(value bool)

SetIsChunked sets whether chunked reading is enabled for the reader. In chunked reading mode: - The reader will treat 0xFF bytes as the end of the current chunk. - EoReader.NextChunk can be called to move to the next chunk.

func (*EoReader) Slice added in v1.1.0

func (r *EoReader) Slice(index int, length int) (ret *EoReader, err error)

Slice creates a new data.EoReader from a slice of the reader's underlying data.

The input data of the new reader will start at the specified index and contain bytes equal to the specified length. The position and chunked reading mode of each reader are independent.

The new reader's position starts at zero with chunked reading mode disabled.

func (*EoReader) SliceFromCurrent added in v1.1.0

func (r *EoReader) SliceFromCurrent() (*EoReader, error)

SliceFromCurrent creates a new data.EoReader from a slice of the reader's underlying data.

The input data of the new reader will start at this reader's current position and contain all remaining data. The position and chunked reading mode of each reader are independent.

The new reader's position starts at zero with chunked reading mode disabled.

func (*EoReader) SliceFromIndex added in v1.1.0

func (r *EoReader) SliceFromIndex(index int) (*EoReader, error)

SliceFromIndex creates a new data.EoReader from a slice of the reader's underlying data.

The input data of the new reader will start at the specified index, offset from the start of the underlying data array, and contains all remaining data. The position and chunked reading mode of each reader are independent.

The new reader's position starts at zero with chunked reading mode disabled.

type EoWriter

type EoWriter struct {

	// SanitizeStrings gets or sets the sanitization mode for the writer.
	// With sanitization enabled, the writer will switch 0xFF bytes in strings (ÿ) to 0x79 (y)
	// See [Chunked Reading: Sanitization]
	//
	// [Chunked Reading: Sanitization]: https://github.com/Cirras/eo-protocol/blob/master/docs/chunks.md#sanitization
	SanitizeStrings bool
	// contains filtered or unexported fields
}

EoWriter encapsulates operations related to writing EO data to a sequence of bytes.

func NewEoWriter

func NewEoWriter() *EoWriter

NewEoWriter initializes an empty data.EoWriter. This writer has underlying data with length 0 and capacity 16.

func (*EoWriter) AddByte

func (w *EoWriter) AddByte(value int) error

AddInt adds a raw byte to the writer data.

func (*EoWriter) AddBytes

func (w *EoWriter) AddBytes(bytes []byte) error

AddBytes adds the specified bytes to the writer data.

func (*EoWriter) AddChar

func (w *EoWriter) AddChar(number int) error

AddChar adds an encoded 1-byte integer to the writer data.

func (*EoWriter) AddEncodedString

func (w *EoWriter) AddEncodedString(str string) error

AddEncodedString encodes and adds a string to the writer data.

func (*EoWriter) AddFixedEncodedString

func (w *EoWriter) AddFixedEncodedString(str string, length int) (err error)

AddFixedEncodedString encodes and adds a fixed-length string to the writer data.

func (*EoWriter) AddFixedString

func (w *EoWriter) AddFixedString(str string, length int) (err error)

AddFixedString adds a fixed-length string to the writer data.

func (*EoWriter) AddInt

func (w *EoWriter) AddInt(number int) error

AddInt adds an encoded 4-byte integer to the writer data.

func (*EoWriter) AddPaddedEncodedString

func (w *EoWriter) AddPaddedEncodedString(str string, length int) (err error)

AddPaddedEncodedString encodes and adds a fixed-length string to the writer data and adds trailing padding (0xFF) bytes.

func (*EoWriter) AddPaddedString

func (w *EoWriter) AddPaddedString(str string, length int) (err error)

AddPaddedString adds a fixed-length string to the writer data add adds trailing padding (0xFF) bytes.

func (*EoWriter) AddShort

func (w *EoWriter) AddShort(number int) error

AddShort adds an encoded 2-byte integer to the writer data.

func (*EoWriter) AddString

func (w *EoWriter) AddString(str string) error

AddString adds a string to the writer data.

func (*EoWriter) AddThree

func (w *EoWriter) AddThree(number int) error

AddThree adds an encoded 3-byte integer to the writer data.

func (*EoWriter) Array

func (w *EoWriter) Array() []byte

Array gets the writer data as a byte array.

func (*EoWriter) Length

func (w *EoWriter) Length() int

Length gets the length of the writer data.

func (*EoWriter) Write

func (w *EoWriter) Write(p []byte) (int, error)

Write satisifies the io.Writer interface

Write writes len(p) bytes from p to the writer data. This implementation unconditionally writes all bytes in the input slice and returns len(p) and a nil error.

Jump to

Keyboard shortcuts

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