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

Function cmdBITPOS

strings.go:519–567  ·  view source on GitHub ↗
(m uhaha.Machine, args []string)

Source from the content-addressed store, hash-verified

517 return redcon.SimpleInt(n), nil
518}
519
520func cmdBITPOS(m uhaha.Machine, args []string) (interface{}, error) {
521 // Validate the number of arguments provided by the client.
522 if len(args) < 3 || len(args) > 6 {
523 return nil, uhaha.ErrWrongNumArgs
524 }
525
526 // Convert the key from string to byte slice for database operations.
527 key := []byte(args[1])
528
529 // Parse the bit value to search for.
530 bit, err := strconv.Atoi(args[2])
531 if err != nil {
532 return nil, err
533 }
534
535 // Initialize default values for start, end, and bitMode.
536 start := 0
537 end := -1
538 bitMode := "BYTE" // Default to BYTE mode
539
540 // Parse optional start and end parameters.
541 if len(args) >= 4 {
542 start, err = strconv.Atoi(args[3])
543 if err != nil {
544 return nil, err
545 }
546 }
547 if len(args) >= 5 {
548 end, err = strconv.Atoi(args[4])
549 if err != nil {
550 return nil, err
551 }
552 }
553 if len(args) == 6 {
554 bitMode = strings.ToUpper(args[5])
555 if bitMode != "BYTE" && bitMode != "BIT" {
556 return nil, fmt.Errorf("invalid bit mode: %s", bitMode)
557 }
558 }
559
560 // Call the underlying BitPos function with the parsed parameters.
561 n, err := ldb.BitPos(key, bit, start, end, bitMode)
562 if err != nil {
563 return nil, err
564 }
565
566 // Return the result as a simple integer.
567 return redcon.SimpleInt(n), nil
568}
569
570func cmdBITOP(m uhaha.Machine, args []string) (interface{}, error) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected