pop

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package pop provides low-level routines to decode values from save files of Grim Dawn. The routines usually depict their processes as "popping", meaning under it data dequeuing from decoding/encoding context, actual decoding of the data, corresponding transformation of state of the context and returning of the decoded data.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidBlockSize error = &errInvalidBlockSize{}

The singleton instance of [errInvalidBlockSize] as a signal, that the context doesn't have enough data to pop the block in question

View Source
var ErrNotEnoughData error = &errNotEnoughData{}

The singleton instance of [errNotEnoughData] as a signal, that the context doesn't have enough data to pop the required value

View Source
var ErrThereIsMoreData error = &errThereIsMoreData{}

The singleton instance of [errThereIsMoreData] as a signal, that the context has excess data, though it shouldn't

Functions

func Block

func Block(ctx *gdio.Decenc, k uint32) func(func() bool)

Block takes a pointer to an instance of gdio.Decenc with kind of block and returns an iterator, which wraps around the general processing of a block. Before the yield, the iterator pops block's kind and size accordingly to the standard layout of a block, checking the popped kind against the provided one. Then the iterator yields, assuming, that the yielding function would work with the same context, and after that it recovers the context's state and dequeues all the bytes processed from the context. If the context has been halted or gets halted before the block's processing, the iterator doesn't yield, but if it does yield, it properly dequeues the processed bytes.

The iterator halts the provided context in the following situations:

  • the popped kind and provided kind are not equal;
  • the popped size supposes more, than the available data in the context;
  • the block's processing has left some data (see NoMore).

func Bool

func Bool(ctx *gdio.Decenc) bool

Bool takes a pointer to an instance of gdio.Decenc and pops a single byte with the context with help of Byte. It returns boolean false, if the popped byte is zero, and boolean truth, if it is one. It halts the context with a corresponding error, if the popped byte is neither zero nor one.

func Byte

func Byte(ctx *gdio.Decenc) byte

Byte takes a pointer to an instance of gdio.Decenc and pops a single byte from the context, transforming state of the context. It returns zero, if the context has been halted. It also returns zero if there is not enough data, halting the context with ErrNotEnoughData.

func Each

func Each[T any](ctx *gdio.Decenc, s *[]T, size int) iter.Seq[*T]

Each is a generic function to pop elements of some kind of collection from a decryption/encryption context and form a slice with the elements. It takes a pointer to an instance of gdio.Decenc, a pointer to a slice of values of T and an integer. The function returns an iterator over pointers to the elements of the slice, which should be popped from the same context by the body of the iterator. If the provided integer is negative, the iterator pops size of the collection of interest before the elements, otherwise it interprets the integer as the size of the collection. It initializes the provided slice with nil and appends elements one by one to the slice until it reaches the required size. If the context has been halted, it stops the gathering and reinitializes the slice as nil before return.

The function is supposed to be used in "for range" loop constructions. It can panic, if the provided yield function is nil.

func Float32

func Float32(ctx *gdio.Decenc) float32

Float32 takes a pointer to an instance of gdio.Decenc and pops a single-precision floating-point number from the context. Its behavior is based on Uint32 completely, and it returns the number, interpretting bits of the popped 32-bit unsigned integer as bits of the result.

func NoMore

func NoMore(ctx *gdio.Decenc)

NoMore takes a pointer to an instance of gdio.Decenc and checks, if the data within the context has non-zero length. If it has, the function halts the context with ErrThereIsMoreData.

func Slice

func Slice[T any](ctx *gdio.Decenc, p func(*gdio.Decenc) T) []T

Slice is a generic function to pop elements of some kind of collection from a decryption/encryption context in form of slice. It takes a pointer to an instance of gdio.Decenc and a function, which accepts a context too and returns a value of type T. Slice supposes, that an unsigned 32-bit size of the collection is encoded before the elements. It tries to pop the size and collect the elements, popping them with the provided function. If the context has been halted or any error has appeared during the gathering, it returns nil slice, otherwise it returns the collected slice.

func State

func State(ctx *gdio.Decenc)

State takes a pointer to an instance of gdio.Decenc and reads state from the context as it was unencrypted. It relies on Uint32 routine in sense of reading behavior and context halting. If the context is not halted after the read, it sets the context to the extracted state.

func String

func String(ctx *gdio.Decenc) string

String takes a pointer to an instance of gdio.Decenc and pops a regular ASCII string from the context. Its behavior is based on Slice completely. It returns empty string, if the popped slice of bytes is nil, or string from the slice of bytes otherwise.

func StringUtf16

func StringUtf16(ctx *gdio.Decenc) string

StringUtf16 takes a pointer to an instance of gdio.Decenc and pops a UTF-16 string from the context, supposing that amount of 16-bit characters is encoded before the pairs of bytes, forming the characters in little endian order. It returns empty string, if the provided context has been halted with an error, or if it has got halted during popping of the bytes.

func Uint32

func Uint32(ctx *gdio.Decenc) uint32

Uint32 takes a pointer to an instance of gdio.Decenc and pops an unsigned 32-bit integer from the context, transforming state of the context. It returns zero, if the context has been halted. It also returns zero if there is not enough data, halting the context with ErrNotEnoughData.

func Uuid

func Uuid(ctx *gdio.Decenc) uuid.UUID

Uuid takes a pointer to an instance of gdio.Decenc and pops 16 consecutive bytes from the context with help of Byte in form of uuid.UUID. If the context has been halted, the function returns default value.

Types

type ErrInvalidBlockKind

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

ErrInvalidBlockKind represents errors, which signal, that the popped kind of block differs from the expected kind of block

func (*ErrInvalidBlockKind) Error

func (e *ErrInvalidBlockKind) Error() string

Error returns a description of the error. It implements the corresponding method of the interface error.

func (*ErrInvalidBlockKind) Expected

func (e *ErrInvalidBlockKind) Expected() uint32

Expected returns the expected kind of block

func (*ErrInvalidBlockKind) Popped

func (e *ErrInvalidBlockKind) Popped() uint32

Popped returns the popped kind of block

type ErrInvalidBool

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

ErrInvalidBool represents errors, which signal, that the popped byte can't be converted to a boolean value

func (*ErrInvalidBool) Error

func (e *ErrInvalidBool) Error() string

Error returns a description of the error. It implements the corresponding method of the interface error.

func (*ErrInvalidBool) Popped

func (e *ErrInvalidBool) Popped() byte

Popped returns the popped byte

Jump to

Keyboard shortcuts

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