Source File
iterator.go
Belonging Package
github.com/dgraph-io/badger/v4/y
/** SPDX-FileCopyrightText: © 2017-2025 Istari Digital, Inc.* SPDX-License-Identifier: Apache-2.0*/package yimport ()// ValueStruct represents the value info that can be associated with a key, but also the internal// Meta field.type ValueStruct struct {Meta byteUserMeta byteExpiresAt uint64Value []byteVersion uint64 // This field is not serialized. Only for internal usage.}func sizeVarint( uint64) ( int) {for {++>>= 7if == 0 {break}}return}// EncodedSize is the size of the ValueStruct when encodedfunc ( *ValueStruct) () uint32 {:= len(.Value) + 2 // meta, usermeta.:= sizeVarint(.ExpiresAt)return uint32( + )}// Decode uses the length of the slice to infer the length of the Value field.func ( *ValueStruct) ( []byte) {.Meta = [0].UserMeta = [1]var int.ExpiresAt, = binary.Uvarint([2:]).Value = [2+:]}// Encode expects a slice of length at least v.EncodedSize().func ( *ValueStruct) ( []byte) uint32 {[0] = .Meta[1] = .UserMeta:= binary.PutUvarint([2:], .ExpiresAt):= copy([2+:], .Value)return uint32(2 + + )}// EncodeTo should be kept in sync with the Encode function above. The reason// this function exists is to avoid creating byte arrays per key-value pair in// table/builder.go.func ( *ValueStruct) ( *bytes.Buffer) {.WriteByte(.Meta).WriteByte(.UserMeta)var [binary.MaxVarintLen64]byte:= binary.PutUvarint([:], .ExpiresAt).Write([:]).Write(.Value)}// Iterator is an interface for a basic iterator.type Iterator interface {Next()Rewind()Seek(key []byte)Key() []byteValue() ValueStructValid() bool// All iterators should be closed so that file garbage collection works.Close() error}
![]() |
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |