/*
 * SPDX-FileCopyrightText: © 2017-2025 Istari Digital, Inc.
 * SPDX-License-Identifier: Apache-2.0
 */

package y

import (
	
	
)

// ValueStruct represents the value info that can be associated with a key, but also the internal
// Meta field.
type ValueStruct struct {
	Meta      byte
	UserMeta  byte
	ExpiresAt uint64
	Value     []byte

	Version uint64 // This field is not serialized. Only for internal usage.
}

func sizeVarint( uint64) ( int) {
	for {
		++
		 >>= 7
		if  == 0 {
			break
		}
	}
	return 
}

// EncodedSize is the size of the ValueStruct when encoded
func ( *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() []byte
	Value() ValueStruct
	Valid() bool

	// All iterators should be closed so that file garbage collection works.
	Close() error
}