MCPcopy Index your code
hub / github.com/HDT3213/rdb / writeHash2Encoding

Method writeHash2Encoding

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

Source from the content-addressed store, hash-verified

437}
438
439func (enc *Encoder) writeHash2Encoding(key string, hash map[string][]byte, expire map[string]int64, options ...interface{}) error {
440 ttl := make([]byte, 8)
441 err := enc.write([]byte{typeHash2})
442 if err != nil {
443 return err
444 }
445 err = enc.writeString(key)
446 if err != nil {
447 return err
448 }
449 err = enc.writeLength(uint64(len(hash)))
450 if err != nil {
451 return err
452 }
453 for field, value := range hash {
454 err = enc.writeString(field)
455 if err != nil {
456 return err
457 }
458 err = enc.writeString(unsafeBytes2Str(value))
459 if err != nil {
460 return err
461 }
462 if expire[field] == 0 {
463 binary.LittleEndian.PutUint64(ttl, math.MaxUint64) // -1 means no TTL
464 } else {
465 binary.LittleEndian.PutUint64(ttl, uint64(expire[field]))
466 }
467 err = enc.write(ttl)
468 if err != nil {
469 return err
470 }
471 }
472 return nil
473}
474
475func (enc *Encoder) tryWriteZipListHashMap(key string, hash map[string][]byte, options ...interface{}) (bool, error) {
476 if len(hash) > enc.hashZipListOpt.getMaxEntries() {

Callers 1

WriteHashMapObjectExMethod · 0.95

Calls 4

writeMethod · 0.95
writeStringMethod · 0.95
writeLengthMethod · 0.95
unsafeBytes2StrFunction · 0.70

Tested by

no test coverage detected