Documentation ¶
Overview ¶
Packate data provides utilities to read and write EO data types.
Index ¶
- Constants
- func BytesFromString(str string) []byte
- func DecodeNumber(bytes []byte) int
- func DecodeString(bytes []byte) []byte
- func EncodeNumber(number int) []byte
- func EncodeString(str []byte) []byte
- func StringFromBytes(bytes []byte) string
- type EoReader
- func (r *EoReader) GetByte() byte
- func (r *EoReader) GetBytes(length int) []byte
- func (r *EoReader) GetChar() int
- func (r *EoReader) GetEncodedString() (string, error)
- func (r *EoReader) GetFixedEncodedString(length int) (string, error)
- func (r *EoReader) GetFixedString(length int) (string, error)
- func (r *EoReader) GetInt() int
- func (r *EoReader) GetPaddedEncodedString(length int) (string, error)
- func (r *EoReader) GetPaddedString(length int) (string, error)
- func (r *EoReader) GetShort() int
- func (r *EoReader) GetString() (string, error)
- func (r *EoReader) GetThree() int
- func (r *EoReader) IsChunked() bool
- func (r *EoReader) Length() int
- func (r *EoReader) NextChunk() error
- func (r *EoReader) Position() int
- func (r *EoReader) Read(b []byte) (n int, err error)
- func (r *EoReader) Remaining() int
- func (r *EoReader) Seek(offset int64, whence int) (i int64, err error)
- func (r *EoReader) SetIsChunked(value bool)
- func (r *EoReader) Slice(index int, length int) (ret *EoReader, err error)
- func (r *EoReader) SliceFromCurrent() (*EoReader, error)
- func (r *EoReader) SliceFromIndex(index int) (*EoReader, error)
- type EoWriter
- func (w *EoWriter) AddByte(value int) error
- func (w *EoWriter) AddBytes(bytes []byte) error
- func (w *EoWriter) AddChar(number int) error
- func (w *EoWriter) AddEncodedString(str string) error
- func (w *EoWriter) AddFixedEncodedString(str string, length int) (err error)
- func (w *EoWriter) AddFixedString(str string, length int) (err error)
- func (w *EoWriter) AddInt(number int) error
- func (w *EoWriter) AddPaddedEncodedString(str string, length int) (err error)
- func (w *EoWriter) AddPaddedString(str string, length int) (err error)
- func (w *EoWriter) AddShort(number int) error
- func (w *EoWriter) AddString(str string) error
- func (w *EoWriter) AddThree(number int) error
- func (w *EoWriter) Array() []byte
- func (w *EoWriter) Length() int
- func (w *EoWriter) Write(p []byte) (int, error)
Constants ¶
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 ¶
BytesFromString converts a string to a sequence of bytes using the Windows-1252 character set
func DecodeNumber ¶
DecodeNumber decodes a number from a sequence of bytes.
func DecodeString ¶
DecodeString decodes a string by reversing the bytes and then inverting them.
func EncodeNumber ¶
EncodeNumber encodes a number to a sequence of bytes.
func EncodeString ¶
EncodeString encodes a string by inverting the bytes and then reversing them.
func StringFromBytes ¶
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 ¶
NewEoReader initializes an data.EoReader with the data in the specified byte slice.
func (*EoReader) GetEncodedString ¶
GetEncodedString reads and decodes an encoded string from the input data.
func (*EoReader) GetFixedEncodedString ¶
GetFixedEncodedString reads and decodes a fixed string from the input data.
func (*EoReader) GetFixedString ¶
GetFixedString reads an unencoded fixed string from the input data.
func (*EoReader) GetPaddedEncodedString ¶
GetPaddedEncodedString reads and decodes a fixed string from the input data and removes trailing padding bytes (0xFF value).
func (*EoReader) GetPaddedString ¶
GetPaddedString reads an unencoded fixed string from the input data and removes trailing padding bytes (0xFF value).
func (*EoReader) NextChunk ¶
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) Read ¶
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 ¶
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 ¶
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 ¶
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
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
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
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) AddEncodedString ¶
AddEncodedString encodes and adds a string to the writer data.
func (*EoWriter) AddFixedEncodedString ¶
AddFixedEncodedString encodes and adds a fixed-length string to the writer data.
func (*EoWriter) AddFixedString ¶
AddFixedString adds a fixed-length string to the writer data.
func (*EoWriter) AddPaddedEncodedString ¶
AddPaddedEncodedString encodes and adds a fixed-length string to the writer data and adds trailing padding (0xFF) bytes.
func (*EoWriter) AddPaddedString ¶
AddPaddedString adds a fixed-length string to the writer data add adds trailing padding (0xFF) bytes.