Documentation ¶
Index ¶
- Constants
- Variables
- func SizeOf(msgs ...Message) (size uint32)
- type Codec
- type FileMessageSet
- type Iterator
- type IteratorFunc
- type Level
- type Magic
- type Message
- func (m Message) Checksum() uint32
- func (m Message) Codec() Codec
- func (m Message) Equal(other Message) bool
- func (m Message) Hash() uint32
- func (m Message) Key() []byte
- func (m Message) Magic() Magic
- func (m Message) SetChecksum()
- func (m Message) SetCodec(codec Codec)
- func (m Message) SetKey(key []byte)
- func (m Message) SetMagic(magic Magic)
- func (m Message) SetValue(value []byte)
- func (m Message) Size() uint32
- func (m Message) String() string
- func (m Message) Valid() bool
- func (m Message) Value() []byte
- type MessageOffset
- type MessageSet
Constants ¶
const ( // NoCodec is a Codec representing no compression. NoCodec = iota // GZIPCodec is a Codec representing GZIP compression. GZIPCodec )
const (
// MsgHeaderSize defines the size in bytes of every Message's header.
MsgHeaderSize = crcLength + magicLength + attrsLength + keySizeLength + valueSizeLength
)
const (
// MsgOverhead defines the byte overhead for each Message within a MessageSet.
MsgOverhead = msgSizeSize + msgOffsetSize
)
Variables ¶
var ( // ErrInvalid is an error returned whenever an invalid file is used with a // FileMessageSet. ErrInvalid = errors.New("invalid file") )
var (
ErrNoMessages = errors.New("no messages provided")
)
Errors returned by methods on a MessageSet.
Functions ¶
Types ¶
type Codec ¶
type Codec byte
Codec is a type representing a Message's compression codec.
func (Codec) Compress ¶
Compress compresses in with Codec c, returning the resulting byte slice and an error in exceptional cases.
func (Codec) Decompress ¶
Decompress decompresses in with Codec c, returning the resulting byte slice and an error in exceptional cases.
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 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 ¶
NewMessage returns a new Message with the given parameters.
func (Message) SetChecksum ¶
func (m Message) SetChecksum()
SetChecksum computes and saves the Message's CRC32 checksum.
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.