Documentation
¶
Index ¶
- Constants
- Variables
- func AlignData(data []byte, offset, alignment uint) ([]byte, error)
- func CalculateTotalSize(segment Segment) (uint, error)
- func CountLeadingZeros(data []byte) uint
- func CountTrailingZeros(data []byte) uint
- func ExtractBits(data []byte, start, length uint) ([]byte, error)
- func GetBitValue(data []byte, pos uint) (bool, error)
- func PadData(data []byte, bitLen, target uint) []byte
- func SetBitValue(data []byte, pos uint, value bool) error
- func SetBits(target, data []byte, start uint) error
- func ValidateSegment(segment *Segment) error
- func ValidateSize(size uint, unit uint) error
- type BitString
- type BitStringError
- type Segment
- type SegmentOption
- func WithDynamicSize(sizeVar *uint) SegmentOption
- func WithDynamicSizeExpression(expr string) SegmentOption
- func WithEndianness(endianness string) SegmentOption
- func WithSigned(signed bool) SegmentOption
- func WithSize(size uint) SegmentOption
- func WithType(segmentType string) SegmentOption
- func WithUnit(unit uint) SegmentOption
- type SegmentResult
Constants ¶
const ( TypeInteger = "integer" TypeFloat = "float" TypeBinary = "binary" TypeBitstring = "bitstring" TypeUTF = "utf" // Generic UTF type TypeUTF8 = "utf8" // UTF-8 specific TypeUTF16 = "utf16" // UTF-16 specific TypeUTF32 = "utf32" // UTF-32 specific TypeRestBinary = "rest_binary" TypeRestBitstring = "rest_bitstring" )
Segment types constants
const ( EndiannessBig = "big" EndiannessLittle = "little" EndiannessNative = "native" )
Endianness constants
const ( Signed = true Unsigned = false )
Signedness constants
const ( DefaultUnitInteger = 1 DefaultUnitFloat = 1 DefaultUnitBinary = 8 DefaultUnitBitstring = 1 DefaultUnitUTF = 1 )
Default unit values for different types
const ( DefaultSizeInteger = 8 DefaultSizeFloat = 64 )
Default size values for different types (in bits)
const ( // Overflow errors CodeOverflow = "OVERFLOW" CodeSignedOverflow = "SIGNED_OVERFLOW" // Insufficient data errors CodeInsufficientBits = "INSUFFICIENT_BITS" // Invalid segment configuration errors CodeInvalidSize = "INVALID_SIZE" CodeInvalidType = "INVALID_TYPE" CodeInvalidEndianness = "INVALID_ENDIANNESS" // Binary-specific errors CodeBinarySizeRequired = "BINARY_SIZE_REQUIRED" CodeBinarySizeMismatch = "BINARY_SIZE_MISMATCH" CodeInvalidBinaryData = "INVALID_BINARY_DATA" // Bitstring-specific errors CodeInvalidBitstringData = "INVALID_BITSTRING_DATA" // UTF-specific errors CodeUTFSizeSpecified = "UTF_SIZE_SPECIFIED" CodeInvalidUnicodeCodepoint = "INVALID_UNICODE_CODEPOINT" // Type mismatch errors CodeTypeMismatch = "TYPE_MISMATCH" // General validation errors CodeInvalidSegment = "INVALID_SEGMENT" CodeInvalidUnit = "INVALID_UNIT" CodeInvalidFloatSize = "INVALID_FLOAT_SIZE" CodeUTFUnitModified = "UTF_UNIT_MODIFIED" )
Error codes for bitstring operations
Variables ¶
var ( ErrInvalidSize = errors.New("invalid size") ErrSizeTooLarge = errors.New("size too large") ErrInvalidPosition = errors.New("invalid position") ErrLengthTooLarge = errors.New("length too large") ErrInvalidAlignment = errors.New("invalid alignment") )
Size handling errors
Functions ¶
func CalculateTotalSize ¶
CalculateTotalSize calculates the total size in bits for a segment
func CountLeadingZeros ¶
CountLeadingZeros counts the number of leading zero bits in the data
func CountTrailingZeros ¶
CountTrailingZeros counts the number of trailing zero bits in the data
func ExtractBits ¶
ExtractBits extracts a sequence of bits from data
func GetBitValue ¶
GetBitValue gets the value of a single bit at the specified position
func SetBitValue ¶
SetBitValue sets the value of a single bit at the specified position
func ValidateSegment ¶
ValidateSegment checks if a segment has valid configuration
func ValidateSize ¶
ValidateSize validates the size and unit for a segment
Types ¶
type BitString ¶
type BitString struct {
// contains filtered or unexported fields
}
BitString represents a sequence of bits
func NewBitStringFromBits ¶
NewBitStringFromBits creates a bitstring from bits with specific length
func NewBitStringFromBytes ¶
NewBitStringFromBytes creates a bitstring from byte slice
type BitStringError ¶
BitStringError represents an error in bitstring operations
func NewBitStringError ¶
func NewBitStringError(code, message string) *BitStringError
NewBitStringError creates a new BitStringError with the given code and message
func NewBitStringErrorWithContext ¶
func NewBitStringErrorWithContext(code, message string, context interface{}) *BitStringError
NewBitStringErrorWithContext creates a new BitStringError with the given code, message, and context
func (*BitStringError) Error ¶
func (e *BitStringError) Error() string
type Segment ¶
type Segment struct {
Value interface{}
Size uint
SizeSpecified bool // Flag to indicate if size was explicitly specified
Type string
Signed bool
Endianness string
Unit uint
UnitSpecified bool // Flag to indicate if unit was explicitly specified
DynamicSize *uint // Pointer to variable for dynamic size
DynamicExpr string // Expression for dynamic size calculation
IsDynamic bool // Flag to indicate if size is dynamic
}
Segment represents a single segment in bitstring construction/matching
func NewSegment ¶
func NewSegment(value interface{}, options ...SegmentOption) *Segment
NewSegment creates a new segment with the given value and options
type SegmentOption ¶
type SegmentOption func(*Segment)
SegmentOption is a function type for configuring segments
func WithDynamicSize ¶
func WithDynamicSize(sizeVar *uint) SegmentOption
WithDynamicSize sets the size for a segment using a variable reference
func WithDynamicSizeExpression ¶
func WithDynamicSizeExpression(expr string) SegmentOption
WithDynamicSizeExpression sets the size for a segment using an expression
func WithEndianness ¶
func WithEndianness(endianness string) SegmentOption
WithEndianness sets the endianness for a segment
func WithSigned ¶
func WithSigned(signed bool) SegmentOption
WithSigned sets the signedness for a segment
func WithType ¶
func WithType(segmentType string) SegmentOption
WithType sets the type for a segment
type SegmentResult ¶
SegmentResult represents result of segment matching