* chore(deps): bump filippo.io/edwards25519 from 1.1.0 to 1.1.1 * chore(deps): bump github.com/cloudflare/circl from 1.6.1 to 1.6.3 * chore(deps): bump github.com/russellhaering/goxmldsig from 1.5.0 to 1.6.0 * build(deps): bump fpicalausa/remove-stale-branches from 2.4.0 to 2.6.1 * build(deps): bump actions/upload-artifact from 4.6.2 to 7.0.1 * build(deps): bump actions/download-artifact from 4.3.0 to 8.0.1 * build(deps): bump pnpm/action-setup from 5.0.0 to 6.0.8 * chore(deps): bump github.com/shamaton/msgpack/v2 to v2.4.1 and reva to v2.0.0-20260519092700-9da01c6fb954 * chore: regenerate lock fil s and vendor * chore: changelog * fix: bump golang.org/x/image to v0.39.0 (GO-2026-4815, GO-2026-4961, GO-2026-4962)
61 lines
2.2 KiB
Go
61 lines
2.2 KiB
Go
package ext
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"github.com/shamaton/msgpack/v2/def"
|
|
)
|
|
|
|
// Decoder defines an interface for decoding values from bytes.
|
|
// It provides methods to get the decoder type, check if the data matches the type,
|
|
// and convert the data into a Go value.
|
|
type Decoder interface {
|
|
// Code returns the unique code representing the decoder type.
|
|
Code() int8
|
|
|
|
// IsType checks if the data at the given offset matches the expected type.
|
|
// Returns true if the type matches, false otherwise.
|
|
IsType(offset int, d *[]byte) bool
|
|
|
|
// AsValue decodes the data at the given offset into a Go value of the specified kind.
|
|
// Returns the decoded value, the new offset, and an error if decoding fails.
|
|
AsValue(offset int, k reflect.Kind, d *[]byte) (interface{}, int, error)
|
|
}
|
|
|
|
// DecoderCommon provides common utility methods for decoding data from bytes.
|
|
type DecoderCommon struct{}
|
|
|
|
// ReadSize1 reads a single byte from the given index in the byte slice.
|
|
// Returns the byte and the new index after reading.
|
|
func (cd *DecoderCommon) ReadSize1(index int, d *[]byte) (byte, int) {
|
|
rb := def.Byte1
|
|
return (*d)[index], index + rb
|
|
}
|
|
|
|
// ReadSize2 reads two bytes from the given index in the byte slice.
|
|
// Returns the bytes as a slice and the new index after reading.
|
|
func (cd *DecoderCommon) ReadSize2(index int, d *[]byte) ([]byte, int) {
|
|
rb := def.Byte2
|
|
return (*d)[index : index+rb], index + rb
|
|
}
|
|
|
|
// ReadSize4 reads four bytes from the given index in the byte slice.
|
|
// Returns the bytes as a slice and the new index after reading.
|
|
func (cd *DecoderCommon) ReadSize4(index int, d *[]byte) ([]byte, int) {
|
|
rb := def.Byte4
|
|
return (*d)[index : index+rb], index + rb
|
|
}
|
|
|
|
// ReadSize8 reads eight bytes from the given index in the byte slice.
|
|
// Returns the bytes as a slice and the new index after reading.
|
|
func (cd *DecoderCommon) ReadSize8(index int, d *[]byte) ([]byte, int) {
|
|
rb := def.Byte8
|
|
return (*d)[index : index+rb], index + rb
|
|
}
|
|
|
|
// ReadSizeN reads a specified number of bytes (n) from the given index in the byte slice.
|
|
// Returns the bytes as a slice and the new index after reading.
|
|
func (cd *DecoderCommon) ReadSizeN(index, n int, d *[]byte) ([]byte, int) {
|
|
return (*d)[index : index+n], index + n
|
|
}
|