bitfield.go
bitfield.go - Overview
This file provides utility functions for parsing bitfield operations in the DiceDB database. It defines the BitFieldOp
struct and functions for parsing the encoding, offset, and operations from the bitfield command arguments.
Detailed Documentation
BitFieldOp
type BitFieldOp struct {
Kind string
EType string
EVal int64
Offset int64
Value int64
}
- Purpose: Represents a single bitfield operation.
Kind
: The type of bitfield operation (e.g., GET, SET, INCRBY, OVERFLOW).EType
: The encoding type (e.g., "i" for signed, "u" for unsigned).EVal
: The encoding value (number of bits).Offset
: The bit offset.Value
: The value to set, increment by, or the overflow type
parseBitfieldEncodingAndOffset
func parseBitfieldEncodingAndOffset(args []string) (eType, eVal, offset interface{}, err error)
- Purpose: Parses the encoding type and offset from the bitfield command arguments.
- Parameters:
args
([]string): A slice of strings containing the encoding and offset.
- Returns:
eType
(interface{}): The encoding type ("i" or "u").eVal
(interface{}): The encoding value (number of bits).offset
(interface{}): The bit offset.err
(error): An error if parsing fails.
ParseBitfieldOps
func ParseBitfieldOps(args []string, readOnly bool) (ops []BitFieldOp, err error)
- Purpose: Parses a slice of strings into a slice of
BitFieldOp
structs, representing a sequence of bitfield operations. - Parameters:
args
([]string): A slice of strings representing the bitfield command arguments.readOnly
(bool): A boolean indicating whether the command is read-only.
- Returns:
ops
([]BitFieldOp): A slice ofBitFieldOp
structs representing the parsed operations.err
(error): An error if parsing fails or if a write operation is attempted in read-only mode.