yxdb

package module
v0.0.0-...-4abef55 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 12 Imported by: 0

README

yxdb-go

yxdb is a package for reading YXDB files into Go applications. Install it using:

go get github.com/tlarsendataguy-yxdb/yxdb-go

The library does not have external dependencies.

The public API is contained in the YxdbReader interface. Instantiate a YxdbReader using one of the two functions:

  • ReadFile(String) - load from a file
  • ReadStream(io.ReadCloser) - load from a reader

Iterate through the records in the file using the Next() method in a for loop:

for reader.Next() {
    // do something
}

Fields can be access via the ReadXxxWithName() and ReadXxxWithIndex() methods on YxdbReader. There are readers for each kind of data field supported by YXDB files:

  • ReadByteWithX() - read Byte fields
  • ReadBlobWithX() - read Blob and SpatialObj fields
  • ReadBooleanWithX() - read Bool fields
  • ReadTimeWithX() - read Date and DateTime fields
  • ReadFloat64WithX() - read FixedDecimal, Float, and Double fields
  • ReadInt64WithX() - read Int16, Int32, and Int64 fields
  • ReadStringWithX() - read String, WString, V_String, and V_WString fields

The WithName() methods read a field by its name. The WithIndex() methods read a field by its index in the file.

If either the index number or field name is invalid, the application will panic.

To read spatial objects, use the ToGeoJSON() function located in yxdb/spatial. The ToGeoJSON() function translates the binary SpatialObj format into a GeoJSON string.

Documentation

Overview

Package yxdb reads and parses .yxdb data files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader interface {
	io.Closer

	// ListFields returns the list of fields contained in the .yxdb file and their data type.
	ListFields() []yxrecord.YxdbField

	// Next iterates through the records in a .yxdb file, returning true if there are more records and false if
	// all records have been read.
	Next() bool

	// NumRecords returns the number of records in the .yxdb file.
	NumRecords() int64

	// MetaInfoStr returns the XML metadata, as a string, of the fields contained in the .yxdb file.
	MetaInfoStr() string

	// ReadByteWithIndex reads a byte field at the specified field index.
	//
	// If the field at the specified index is not a byte field, ReadByteWithIndex will panic.
	ReadByteWithIndex(int) (byte, bool)

	// ReadByteWithName reads a byte field with the specified name.
	//
	// If the name is not valid or the field with the specified name is not a byte field, ReadByteWithName will panic.
	ReadByteWithName(string) (byte, bool)

	// ReadBoolWithIndex reads a boolean field at the specified field index.
	//
	// If the field at the specified index is not a boolean field, ReadBoolWithIndex will panic.
	ReadBoolWithIndex(int) (bool, bool)

	// ReadBoolWithName reads a boolean field with the specified name.
	//
	// If the name is not valid or the field with the specified name is not a boolean field, ReadBoolWithName will panic.
	ReadBoolWithName(string) (bool, bool)

	// ReadInt64WithIndex reads an integer field at the specified field index.
	//
	// If the field at the specified index is not an integer field, ReadInt64WithIndex will panic.
	ReadInt64WithIndex(int) (int64, bool)

	// ReadInt64WithName reads an integer field with the specified name.
	//
	// If the name is not valid or the field with the specified name is not an integer field, ReadInt64WithName will panic.
	ReadInt64WithName(string) (int64, bool)

	// ReadFloat64WithIndex reads a numeric field at the specified field index.
	//
	// If the field at the specified index is not a numeric field, ReadFloat64WithIndex will panic.
	ReadFloat64WithIndex(int) (float64, bool)

	// ReadFloat64WithName reads a numeric field with the specified name.
	//
	// If the name is not valid or the field with the specified name is not a numeric field, ReadFloat64WithName will panic.
	ReadFloat64WithName(string) (float64, bool)

	// ReadStringWithIndex reads a string field at the specified field index.
	//
	// If the field at the specified index is not a string field, ReadStringWithIndex will panic.
	ReadStringWithIndex(int) (string, bool)

	// ReadStringWithName reads a string field with the specified name.
	//
	// If the name is not valid or the field with the specified name is not a string field, ReadStringWithName will panic.
	ReadStringWithName(string) (string, bool)

	// ReadTimeWithIndex reads a date/datetime field at the specified field index.
	//
	// If the field at the specified index is not a date/datetime field, ReadTimeWithIndex will panic.
	ReadTimeWithIndex(int) (time.Time, bool)

	// ReadTimeWithName reads a date/datetime field with the specified name.
	//
	// If the name is not valid or the field with the specified name is not a date/datetime field, ReadTimeWithName will panic.
	ReadTimeWithName(string) (time.Time, bool)

	// ReadBlobWithIndex reads a binary field at the specified field index.
	//
	// If the field at the specified index is not a binary field, ReadBlobWithIndex will panic.
	ReadBlobWithIndex(int) []byte

	// ReadBlobWithName reads a binary field with the specified name.
	//
	// If the name is not valid or the field with the specified name is not a binary field, ReadBlobWithName will panic.
	ReadBlobWithName(string) []byte
}

A Reader is the interface that reads and parses .yxdb files.

Instantiate a Reader using the ReadFile and ReadStream functions.

func ReadFile

func ReadFile(path string) (Reader, error)

ReadFile instantiates a Reader from the specified file path.

If the file does not exist, cannot be opened, or is not a valid .yxdb file, ReadFile will return an error.

func ReadStream

func ReadStream(stream io.ReadCloser) (Reader, error)

ReadStream instantiates a Reader from the specified io.ReadCloser.

If the stream encounters an error or is not a valid .yxdb files, ReadStream will return an error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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