database

package
v0.0.0-...-5198e25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

For key value stores where buckets are not supported, we add a byte to the key to represent a bucket. For now, all buckets are hard coded, but we could change that in the future.

Buckets are not really enough to index everything we wish to index. So we have labels as well. Labels are shifted 8 bits left, so they can be combined with the buckets to create a unique key.

This allows us to put the raw directory block at DBlockBucket+L_raw, and meta data about the directory block at DBlockBucket+MetaLabel

For key value stores where buckets are not supported, we add a byte to the key to represent a bucket. For now, all buckets are hard coded, but we could change that in the future.

Buckets are not really enough to index everything we wish to index. So we have labels as well. Labels are shifted 8 bits left, so they can be combined with the buckets to create a unique key.

This allows us to put the raw directory block at DBlockBucket+L_raw, and meta data about the directory block at DBlockBucket+MetaLabel

Index

Constants

View Source
const (
	DBlockBucket      = iota + 1 // Index information about directory blocks
	ObjectBucket                 // Index information about general objects in Factom
	MerkleStateBucket            // Index information about merklestates
	BitcoinBucket                //
	EthereumBucket
	TestBucket
)

buckets

View Source
const (
	MetaLabel = (iota + 1) << 16
	RawLabel
)

labels

Variables

This section is empty.

Functions

func BoolBytes

func BoolBytes(b bool) []byte

BoolBytes Marshal a Bool

func BytesBool

func BytesBool(data []byte) (f bool, newData []byte)

BytesBool Unmarshal a Uint8

func BytesInt64

func BytesInt64(data []byte) (int64, []byte)

BytesInt64 Unmarshal a int64 (big endian) We only need this function on top of BytesUint64 to avoid a type conversion when dealing with int64 values

func BytesUint16

func BytesUint16(data []byte) (uint16, []byte)

BytesUint16 Unmarshal a uint32 (big endian)

func BytesUint32

func BytesUint32(data []byte) (uint32, []byte)

BytesUint32 Unmarshal a uint32 (big endian)

func BytesUint64

func BytesUint64(data []byte) (uint64, []byte)

BytesUint64 Unmarshal a uint64 (big endian)

func GetHomeDir

func GetHomeDir() string

GetHomeDir Used to find the Home Directory from which the configuration directory for the ValAcc application to use for its database. This is not a terribly refined way of configuring the ValAcc and may be refined in the future.

func GetKey

func GetKey(bucket int, key []byte) (CKey []byte)

GetKey Given a bucket and a key, return the combined key

func Int64Bytes

func Int64Bytes(i int64) []byte

Int64Bytes Marshal a int64 (big endian) We only need this function on top of Uint64Bytes to avoid a type conversion when dealing with int64 values

func Uint16Bytes

func Uint16Bytes(i uint16) []byte

Uint16Bytes Marshal a int32 (big endian)

func Uint32Bytes

func Uint32Bytes(i uint32) []byte

Uint32Bytes Marshal a int32 (big endian)

func Uint64Bytes

func Uint64Bytes(i uint64) []byte

Uint64Bytes Marshal a uint64 (big endian)

Types

type DB

type DB struct {
	DBHome string
	// contains filtered or unexported fields
}

func GetDB

func GetDB() *DB

func (*DB) Get

func (d *DB) Get(bucket int, key []byte) (value []byte)

Get Look in the given bucket, and return the key found. Returns nil if no value is found for the given key

func (*DB) GetInt32

func (d *DB) GetInt32(bucket int, ikey uint32) (value []byte)

func (*DB) InitDB

func (d *DB) InitDB()

Initialize the database. This will certainly open an existing database, but will also initialize an new, empty database.

func (*DB) Put

func (d *DB) Put(bucket int, key []byte, value []byte) error

Put Put a key/value in the database. We return an error if there was a problem writing the key/value pair to the database.

func (*DB) PutInt32

func (d *DB) PutInt32(bucket int, ikey int, value []byte) error

PutInt Put a key/value in the database, where the key is an index. We return an error if there was a problem writing the key/value pair to the database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL