MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / cmdGETBIT

Function cmdGETBIT

strings.go:321–348  ·  view source on GitHub ↗

Retrieves the bit value at a specified offset in the string stored at the given key. Returns: The bit value (0 or 1), or an error if the number of arguments is incorrect or the offset is not a valid non-negative integer. Behavior: Retrieves the bit value at the specified offset: - Returns 0

(m uhaha.Machine, args []string)

Source from the content-addressed store, hash-verified

319// Error Handling:
320// - Returns an error for incorrect number of arguments.
321// - Returns an error if the offset is not a valid non-negative integer.
322func cmdGETBIT(m uhaha.Machine, args []string) (interface{}, error) {
323 // Check if the number of arguments is correct; requires 3 arguments: key and offset
324 if len(args) != 3 {
325 return nil, uhaha.ErrWrongNumArgs
326 }
327
328 key := []byte(args[1]) // Retrieve the key
329 offsetStr := args[2] // Retrieve the offset string
330
331 // Convert the offset string to a non-negative integer
332 offset, err := strconv.Atoi(offsetStr)
333 if err != nil {
334 return nil, errors.New("offset must be a non-negative integer")
335 }
336 if offset < 0 {
337 return nil, errors.New("offset must be a non-negative integer")
338 }
339
340 // Retrieve the bit value at the specified offset from the database
341 // If the key does not exist or the offset exceeds the string length, ldb.GetBit should return 0
342 n, err := ldb.GetBit(key, offset)
343 if err != nil {
344 return nil, err
345 }
346
347 // Return the bit value, which is either 0 or 1
348 return redcon.SimpleInt(n), nil
349}
350
351// cmdEXISTS checks the existence of keys. no concurrent

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected