tio

package
v0.0.0-...-687e8eb Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BufferedReaderFlagDelimiter enables reading for a delimiter. This flag is
	// ignored if an MLE flag is set.
	BufferedReaderFlagDelimiter = BufferedReaderFlags(0)

	// BufferedReaderFlagMLE enables reading if length encoded messages.
	// Runlength is read as ASCII (to uint64) until the first byte (ASCII char)
	// of the delimiter string.
	// Only one MLE flag is supported at a time.
	BufferedReaderFlagMLE = BufferedReaderFlags(1)

	// BufferedReaderFlagMLE8 enables reading if length encoded messages.
	// Runlength is read as binary (to uint8).
	// Only one MLE flag is supported at a time.
	BufferedReaderFlagMLE8 = BufferedReaderFlags(2)

	// BufferedReaderFlagMLE16 enables reading if length encoded messages.
	// Runlength is read as binary (to uint16).
	// Only one MLE flag is supported at a time.
	BufferedReaderFlagMLE16 = BufferedReaderFlags(3)

	// BufferedReaderFlagMLE32 enables reading if length encoded messages.
	// Runlength is read as binary (to uint32).
	// Only one MLE flag is supported at a time.
	BufferedReaderFlagMLE32 = BufferedReaderFlags(4)

	// BufferedReaderFlagMLE64 enables reading if length encoded messages.
	// Runlength is read as binary (to uint64).
	// Only one MLE flag is supported at a time.
	BufferedReaderFlagMLE64 = BufferedReaderFlags(5)

	// BufferedReaderFlagMLEFixed enables reading messages with a fixed length.
	// Only one MLE flag is supported at a time.
	BufferedReaderFlagMLEFixed = BufferedReaderFlags(6)

	// BufferedReaderFlagMaskMLE is a bitmask to mask out everything but MLE flags
	BufferedReaderFlagMaskMLE = BufferedReaderFlags(7)

	// BufferedReaderFlagBigEndian sets binary reading to big endian encoding.
	BufferedReaderFlagBigEndian = BufferedReaderFlags(8)

	// BufferedReaderFlagEverything will keep MLE and/or delimiters when
	// building a message.
	BufferedReaderFlagEverything = BufferedReaderFlags(16)
)

Variables

View Source
var BufferDataInvalid = bufferError("Invalid data")

BufferDataInvalid is returned when a parsing encounters an error

Functions

func CommonPath

func CommonPath(path1, path2 string) string

CommonPath returns the longest common path of both paths given.

func FileCRC32

func FileCRC32(path string) (uint32, error)

FileCRC32 returns the checksum of a given file

func FileExists

func FileExists(filePath string) bool

FileExists does a proper check on wether a file exists or not.

func IsDirectory

func IsDirectory(filePath string) bool

IsDirectory returns true if a given path points to a directory.

func ListFilesByDateMatching

func ListFilesByDateMatching(directory string, pattern string) ([]os.FileInfo, error)

ListFilesByDateMatching gets all files from a directory that match a given regular expression pattern and orders them by modification date (ascending). Directories and symlinks are excluded from the returned list.

func OpenNamedPipe

func OpenNamedPipe(name string, perm uint32) (*os.File, error)

OpenNamedPipe opens or attaches to a named pipe given by name. If the pipe is created, perm will be used as file permissions. This function is not available on windows.

func SplitPath

func SplitPath(filePath string) (dir string, base string, ext string)

SplitPath separates a file path into directory, filename (without extension) and file extension (with dot). If no directory could be derived "." is returned as a directory. If no file extension could be derived "" is returned as a file extension.

Types

type BufferReadCallback

type BufferReadCallback func(msg []byte)

BufferReadCallback defines the function signature for callbacks passed to ReadAll.

type BufferedReader

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

BufferedReader is a helper struct to read from any io.Reader into a byte slice. The data can arrive "in pieces" and will be assembled. A data "piece" is considered complete if a delimiter or a certain runlength has been reached. The latter has to be enabled by flag and will disable the default behavior, which is looking for a delimiter string.

func NewBufferedReader

func NewBufferedReader(bufferSize int, flags BufferedReaderFlags, offsetOrLength int, delimiter string) *BufferedReader

NewBufferedReader creates a new buffered reader that reads messages from a continuous stream of bytes. Messages can be separated from the stream by using common methods such as fixed size, encoded message length or delimiter string. The internal buffer is grown statically (by its original size) if necessary. bufferSize defines the initial size / grow size of the buffer flags configures the parsing method offsetOrLength sets either the runlength offset or fixed message size delimiter defines the delimiter used for textual message parsing

func (*BufferedReader) ReadAll

func (buffer *BufferedReader) ReadAll(reader io.Reader, callback BufferReadCallback) error

ReadAll calls ReadOne as long as there are messages in the stream. Messages will be send to the given write callback. If callback is nil, data will be read and discarded.

func (*BufferedReader) ReadOne

func (buffer *BufferedReader) ReadOne(reader io.Reader) (data []byte, more bool, err error)

ReadOne reads the next message from the given stream (if possible) and generates a sequence number for this message. The more return parameter is set to true if there are still messages or parts of messages in the stream. Data and seq is only set if a complete message could be parsed. Errors are returned if reading from the stream failed or the parser encountered an error.

func (*BufferedReader) Reset

func (buffer *BufferedReader) Reset(sequence uint64)

Reset clears the buffer by resetting its internal state

type BufferedReaderFlags

type BufferedReaderFlags byte

BufferedReaderFlags is an enum to configure a buffered reader

type ByteStream

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

ByteStream is a more lightweight variant of bytes.Buffer. The managed byte array is increased to the exact required size and never shrinks. Writing moves an internal offset (for appends) but reading always starts at offset 0.

func NewByteStream

func NewByteStream(capacity int) ByteStream

NewByteStream creates a new byte stream of the desired capacity

func NewByteStreamFrom

func NewByteStreamFrom(data []byte) ByteStream

NewByteStreamFrom creates a new byte stream that starts with the given byte array.

func (ByteStream) Bytes

func (stream ByteStream) Bytes() []byte

Bytes returns a slice of the underlying byte array containing all written data up to this point.

func (ByteStream) Cap

func (stream ByteStream) Cap() int

Cap returns the capacity of the underlying array. This is equal to cap(stream.Bytes()).

func (ByteStream) Len

func (stream ByteStream) Len() int

Len returns the length of the underlying array. This is equal to len(stream.Bytes()).

func (*ByteStream) Read

func (stream *ByteStream) Read(target []byte) (int, error)

Read implements the io.Reader interface. The underlying array is copied to target and io.EOF is returned once no data is left to be read. Please note that ResetRead can rewind the internal read index for this operation.

func (*ByteStream) Reset

func (stream *ByteStream) Reset()

Reset sets the internal write offset to 0 and calls ResetRead

func (*ByteStream) ResetRead

func (stream *ByteStream) ResetRead()

ResetRead sets the internal read offset to 0. The read offset is only used within the Read function to assure io.Reader compatibility

func (*ByteStream) SetCapacity

func (stream *ByteStream) SetCapacity(capacity int)

SetCapacity assures that capacity bytes are available in the buffer, growing the managed byte array if needed. The buffer will grow by at least 64 bytes if growing is required.

func (ByteStream) String

func (stream ByteStream) String() string

String returns a string of the underlying byte array containing all written data up to this point.

func (*ByteStream) Write

func (stream *ByteStream) Write(source []byte) (int, error)

Write implements the io.Writer interface. This function assures that the capacity of the underlying byte array is enough to store the incoming amount of data. Subsequent writes will allways append to the end of the stream until Reset() is called.

func (*ByteStream) WriteByte

func (stream *ByteStream) WriteByte(source byte) error

WriteByte writes a single byte to the stream. Capacity will be ensured.

func (*ByteStream) WriteString

func (stream *ByteStream) WriteString(source string) (int, error)

WriteString is a convenience wrapper for Write([]byte(source))

type ByteWriter

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

ByteWriter wraps a slice so that it can be passed to io.Writer compatible functions. The referenced slice will be resized.

func NewByteWriter

func NewByteWriter(buffer *[]byte) ByteWriter

NewByteWriter creates a new writer on the referenced byte slice.

func (ByteWriter) Reset

func (b ByteWriter) Reset()

Reset sets the length of the slize to 0.

func (ByteWriter) Write

func (b ByteWriter) Write(data []byte) (int, error)

Write writes data to the wrapped slice if there is enough space available. If not, data is written until the wrapped slice has reached its capacity and io.EOF is returned.

type FilesByDate

type FilesByDate []os.FileInfo

FilesByDate implements the Sort interface by Date for os.FileInfo arrays

func (FilesByDate) Len

func (files FilesByDate) Len() int

Len returns the number of files in the array

func (FilesByDate) Less

func (files FilesByDate) Less(a, b int) bool

Less compares the date of the files stored at a and b as in "[a] modified < [b] modified". If both files were created in the same second the file names are compared by using a lexicographic string compare.

func (FilesByDate) Swap

func (files FilesByDate) Swap(a, b int)

Swap exchanges the values stored at indexes a and b

Jump to

Keyboard shortcuts

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