MCPcopy Create free account
hub / github.com/HDT3213/rdb / tryWriteZipListHashMap

Method tryWriteZipListHashMap

core/hash.go:475–502  ·  view source on GitHub ↗
(key string, hash map[string][]byte, options ...interface{})

Source from the content-addressed store, hash-verified

473}
474
475func (enc *Encoder) tryWriteZipListHashMap(key string, hash map[string][]byte, options ...interface{}) (bool, error) {
476 if len(hash) > enc.hashZipListOpt.getMaxEntries() {
477 return false, nil
478 }
479 maxValue := enc.hashZipListOpt.getMaxValue()
480 for _, v := range hash {
481 if len(v) > maxValue {
482 return false, nil
483 }
484 }
485 err := enc.write([]byte{typeHashZipList})
486 if err != nil {
487 return true, err
488 }
489 err = enc.writeString(key)
490 if err != nil {
491 return true, err
492 }
493 entries := make([]string, 0, len(hash)*2)
494 for k, v := range hash {
495 entries = append(entries, k, unsafeBytes2Str(v))
496 }
497 err = enc.writeZipList(entries)
498 if err != nil {
499 return true, err
500 }
501 return true, nil
502}

Callers 1

WriteHashMapObjectMethod · 0.95

Calls 6

writeMethod · 0.95
writeStringMethod · 0.95
writeZipListMethod · 0.95
getMaxEntriesMethod · 0.80
getMaxValueMethod · 0.80
unsafeBytes2StrFunction · 0.70

Tested by

no test coverage detected