MCPcopy Create free account
hub / github.com/distributedio/titan / SetRange

Function SetRange

command/strings.go:349–375  ·  view source on GitHub ↗

SetRange overwrites part of the string stored at key, starting at the specified offset, for the entire length of value.

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

347
348//SetRange overwrites part of the string stored at key, starting at the specified offset, for the entire length of value.
349func SetRange(ctx *Context, txn *db.Transaction) (OnCommit, error) {
350 offset, err := strconv.Atoi(ctx.Args[1])
351 if err != nil {
352 return nil, ErrInteger
353 }
354
355 key := []byte(ctx.Args[0])
356 if offset < 0 || offset > MaxRangeInteger {
357 return nil, ErrMaximum
358 }
359
360 str, err := txn.String(key)
361 if err != nil {
362 if err == db.ErrTypeMismatch {
363 return nil, ErrTypeMismatch
364 }
365 return nil, errors.New("ERR " + err.Error())
366 }
367
368 // If the offset is larger than the current length of the string at key, the string is padded with zero-bytes to make offset fit.
369 val, err := str.SetRange(int64(offset), []byte(ctx.Args[2]))
370 if err != nil {
371 return nil, errors.New("ERR " + err.Error())
372 }
373 return Integer(ctx.Out, int64(len(val))), nil
374
375}
376
377// Incr increments the integer value of a key by one
378func Incr(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 4

IntegerFunction · 0.85
SetRangeMethod · 0.80
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected