flatdata

package
v0.0.0-...-494f773 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

flatdata-go

Common library for flatdata Go implementation

Requirements

Library requires Go 1.9 and higher.

Dependencies

Use dep to properly add flatdata-go to your project.
Otherwise, you can always install dependencies manually:

go get -u golang.org/x/exp/mmap
go get -u github.com/stretchr/testify
Tests and coverage

Run tests and show coverage info

go test -v -race ./... -coverprofile=coverage.out

Open coverage in browser

go tool cover -html=coverage.out
Benchmarks
go test -bench=.

Documentation

Overview

Package flatdata represents Go implementation for Flatdata

Index

Constants

View Source
const (

	// ErrorInvalidResource returns in case of size of resource is smaller than minimal
	ErrorInvalidResource = "invalid flatdata resource"
	// ErrorCantAccessResource returns if resource wasn't been memory-mapped
	ErrorCantAccessResource = "can't open flatdata resource"
	// ErrorCantOpenSchemaForResource returns if schema for resource wasn't open
	ErrorCantOpenSchemaForResource = "can't open schema for resource"
	// ErrorSchemaEmpty returns in case when schema is empty
	ErrorSchemaEmpty = "schema for resource is empty"
	// ErrorSchemaDidntMatch returns if provided schema is not equal to schema in generated sources
	ErrorSchemaDidntMatch = "schemas didn't match"
)

Variables

This section is empty.

Functions

func Read

func Read(descriptor MemoryDescriptor, offset, size uint, signed bool) int

Read allows to read data from flatdata memory layout

Types

type FileResourceStorage

type FileResourceStorage struct {
	// contains filtered or unexported fields
}

FileResourceStorage implements ResourceStorage interface for memory-mapped file

func NewFileResourceStorage

func NewFileResourceStorage(path string) *FileResourceStorage

NewFileResourceStorage - constructor for FileResourceStorage

func (*FileResourceStorage) GetBasePath

func (r *FileResourceStorage) GetBasePath() string

GetBasePath returns base path to opened archive

func (*FileResourceStorage) GetMemoryDescriptor

func (r *FileResourceStorage) GetMemoryDescriptor(name string) (MemoryDescriptor, string, error)

GetMemoryDescriptor returns memory descriptor for specified resource

type InMemoryResourceStorage

type InMemoryResourceStorage struct {
	Descriptors map[string]MemoryDescriptor
	Schemas     map[string]string
}

InMemoryResourceStorage implements ResourceStorage interface for working with in-memory data

func (*InMemoryResourceStorage) GetBasePath

func (r *InMemoryResourceStorage) GetBasePath() string

GetBasePath returns empty string in case of InMemoryResourceStorage

func (*InMemoryResourceStorage) GetMemoryDescriptor

func (r *InMemoryResourceStorage) GetMemoryDescriptor(name string) (MemoryDescriptor, string, error)

GetMemoryDescriptor returns memory descriptor for specified resource

type MemoryDescriptor

type MemoryDescriptor interface {
	io.ReaderAt
	Close() error
	Len() int
	At(i int) byte
}

MemoryDescriptor represents internal low level data access

type ResourceStorage

type ResourceStorage interface {
	GetMemoryDescriptor(name string) (MemoryDescriptor, string, error)
	GetBasePath() string
}

ResourceStorage represents abstraction for getting resource handle

type TestMemoryDescriptor

type TestMemoryDescriptor struct {
	Array []byte
}

TestMemoryDescriptor implements MemoryDescriptor interface with reading date from []byte for internal usage

func (*TestMemoryDescriptor) At

func (b *TestMemoryDescriptor) At(i int) byte

At return byte on position i

func (*TestMemoryDescriptor) Close

func (b *TestMemoryDescriptor) Close() error

Close should close memory descriptor

func (*TestMemoryDescriptor) Len

func (b *TestMemoryDescriptor) Len() int

Len returns length of internal byte array

func (*TestMemoryDescriptor) ReadAt

func (b *TestMemoryDescriptor) ReadAt(p []byte, off int64) (n int, err error)

ReadAt number of bytes equal to p starting from offset off

Jump to

Keyboard shortcuts

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