message

package
v0.0.0-...-56f60b4 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoCodec is a Codec representing no compression.
	NoCodec = iota
	// GZIPCodec is a Codec representing GZIP compression.
	GZIPCodec
)
View Source
const (

	// MsgHeaderSize defines the size in bytes of every Message's header.
	MsgHeaderSize = crcLength + magicLength + attrsLength + keySizeLength + valueSizeLength
)
View Source
const (

	// MsgOverhead defines the byte overhead for each Message within a MessageSet.
	MsgOverhead = msgSizeSize + msgOffsetSize
)

Variables

View Source
var (
	// ErrInvalid is an error returned whenever an invalid file is used with a
	// FileMessageSet.
	ErrInvalid = errors.New("invalid file")
)
View Source
var (
	ErrNoMessages = errors.New("no messages provided")
)

Errors returned by methods on a MessageSet.

Functions

func SizeOf

func SizeOf(msgs ...Message) (size uint32)

SizeOf computes the byte size of a MessageSet containing msgs Messages.

Types

type Codec

type Codec byte

Codec is a type representing a Message's compression codec.

func (Codec) Compress

func (c Codec) Compress(in []byte) ([]byte, error)

Compress compresses in with Codec c, returning the resulting byte slice and an error in exceptional cases.

func (Codec) Decompress

func (c Codec) Decompress(in []byte) ([]byte, error)

Decompress decompresses in with Codec c, returning the resulting byte slice and an error in exceptional cases.

func (Codec) String

func (c Codec) String() string

String implements the Stringer interface.

type FileMessageSet

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

FileMessageSet is a file backed MessageSet.

func NewFileMessageSet

func NewFileMessageSet(f *os.File, pos, n int64) (*FileMessageSet, error)

NewFileMessageSet returns a new FileMessageSet with the passed file. Iteration is windowed with an io.SectionReader instantiated with pos and n.

func (*FileMessageSet) Append

func (ms *FileMessageSet) Append(other *MessageSet) error

Append adds other MessageSet to the end of this FileMessageSet.

func (*FileMessageSet) Iterator

func (ms *FileMessageSet) Iterator() Iterator

Iterator implements the Iterator interface.

func (*FileMessageSet) Pos

func (ms *FileMessageSet) Pos(offset uint64) (uint32, error)

Pos searches this FileMessageSet for the given offset and returns its position or an error if not found.

func (*FileMessageSet) Size

func (ms *FileMessageSet) Size() uint32

Size returns the byte size of this FileMessageSet.

type Iterator

type Iterator interface {
	// Next returns a pointer to the next msg in the MessageSet or nil if the end
	// is reached.
	Next(lv Level) (*MessageOffset, error)
}

Iterator defines an interface for a MessageSet iterator.

type IteratorFunc

type IteratorFunc func(Level) (*MessageOffset, error)

IteratorFunc is an adapter to allow the use of ordinary functions as Iterators.

func (IteratorFunc) Next

func (fn IteratorFunc) Next(lv Level) (*MessageOffset, error)

Next implements the Iterator interface by calling wrapping fn with the right signature.

type Level

type Level uint8

Level defines the iteration level to use.

const (
	// Header defines an Iterator level which only reads a Message's header
	// on each iteration.
	Header Level = iota
	// Full defines an Iterator level which reads a full message on each
	// iteration.
	Full
)

type Magic

type Magic byte

Magic is a type representing a Message's magic byte which indicates the wire-format version.

const (
	// One is a Magic byte representing version one of the Message's wire-format.
	One Magic = 1
)

type Message

type Message []byte

Message is the individual datum handled throughout the system.

func NewMessage

func NewMessage(key, value []byte) Message

NewMessage returns a new Message with the given parameters.

func (Message) Checksum

func (m Message) Checksum() uint32

Checksum returns the Message's CRC32 checksum.

func (Message) Codec

func (m Message) Codec() Codec

Codec returns a Codec byte representing the Message's compression codec.

func (Message) Equal

func (m Message) Equal(other Message) bool

Equal returns whether other Message is equal to m.

func (Message) Hash

func (m Message) Hash() uint32

Hash computes and returns the Message's CRC32 checksum.

func (Message) Key

func (m Message) Key() []byte

Key returns the Message's key.

func (Message) Magic

func (m Message) Magic() Magic

Magic returns a Magic byte representing the Message's version.

func (Message) SetChecksum

func (m Message) SetChecksum()

SetChecksum computes and saves the Message's CRC32 checksum.

func (Message) SetCodec

func (m Message) SetCodec(codec Codec)

SetCodec sets the Message's compression codec.

func (Message) SetKey

func (m Message) SetKey(key []byte)

SetKey sets the Message's key.

func (Message) SetMagic

func (m Message) SetMagic(magic Magic)

SetMagic sets the Message's magic byte.

func (Message) SetValue

func (m Message) SetValue(value []byte)

SetValue sets the Message's value.

func (Message) Size

func (m Message) Size() uint32

Size returns the byte size of the Message.

func (Message) String

func (m Message) String() string

String implments the fmt.Stringer interface.

func (Message) Valid

func (m Message) Valid() bool

Valid returns whether the Message's integrity is intact by comparing the saved checksum field with a recomputed checksum.

func (Message) Value

func (m Message) Value() []byte

Value returns the Message's value.

type MessageOffset

type MessageOffset struct {
	// Offset is the Message logical offset within a MessageSet.
	Offset uint64
	// Pos is the Message physical byte offset within a MessageSet.
	Pos uint32
	// MsgSize is the Message byte size.
	MsgSize uint32
	// Message is the actual Message payload.
	Message
}

MessageOffset is an utility type wrapping a Message and its logical and physical offsets within a MessageSet.

func (*MessageOffset) Size

func (m *MessageOffset) Size() uint32

Size returns this Message's size within a MessageSet.

type MessageSet

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

MessageSet is an in-memory sequential Message container with a fixed serialization format.

With no compression enabled, each Message is laid out sequentially and preceded by a header containing its offset and size.

-----------------------------------------------------------------
| offset | size | message | ... | offset+N | size N | message N |
-----------------------------------------------------------------

With compression enabled, the previous byte slice is compressed and set as the value of a single Message within the MessageSet.

-----------------------------
| offset+N | size | message |
-----------------------------

func NewMessageSet

func NewMessageSet(offset uint64, codec Codec, msgs ...Message) (*MessageSet, error)

NewMessageSet returns a MessageSet containing the provided Messages. The first offset is set to the provided one and increments from there for each Message. Codec will be used to compress the messages.

func (*MessageSet) Equal

func (ms *MessageSet) Equal(other MessageSet) bool

Equal returns whether other MessageSet is equal to ms.

func (*MessageSet) Iterator

func (ms *MessageSet) Iterator() Iterator

Iterator implements the Iterator interface.

func (*MessageSet) Size

func (ms *MessageSet) Size() uint32

Size returns the byte size of the MessageSet.

func (*MessageSet) String

func (ms *MessageSet) String() string

String implements the fmt.Stringer interface.

func (*MessageSet) WriteTo

func (ms *MessageSet) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo interface.

Jump to

Keyboard shortcuts

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