Version: v0.0.0-...-6719cd2 Latest Latest

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

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 5 Imported by: 0



Package logencoder handles serialization and deserialization of logentry.*Command in to/from bytes. The resulting bytes should be written/read from the log.



View Source
const DefaultLogVersion = 1

DefaultLogVersion is the log version a new empty log should start at.

View Source
const MaxVersionSupported = 1

MaxVersionSupported contains the maximum log version that the running process supports.


This section is empty.


func Encode

func Encode(cmd ProtobufCommand) []byte

Encode will take the supplied command and serialize into a format suitable for persisting to the log. cmd should be one of the *Command types from the logentry package. If its unable to serialize the Command, that implies a programmer error somewhere, and it will panic.

func LogInitialPosition

func LogInitialPosition() rpc.LogPosition

LogInitialPosition returns a log position that should be used to start reading the log for an new empty log.


type Entry

type Entry struct {
	// Position contains the log index & version that applies for this entry.
	Position rpc.LogPosition
	// Command is a pointer to one of logentry.*Command types. Typically you'd
	// type switch on this to process the entry. Its never nil for an Entry
	// returned from Decode.
	Command ProtobufCommand

Entry represent a log entry that has been decoded back to its Command structure.

func Decode

func Decode(ver Version, e blog.Entry) (decoded Entry, nextPos rpc.LogPosition, err error)

Decode will parse the supplied log entry and apply any adjustments required by the supplied version. It returns the decoded Entry and the next position that should be read.

It will apply versioning checks to the log entry if its a VersionCommand

*) It will not allow the version to be set higher than maxVersion.
   If it detects this it will log details & exit the process.

*) It will not allow the version to be set lower than the version of
   the log entry that contained the VersionCommand. i.e. versions
   can not go backwards. If this is detected the VersionCommand is
   ignored and the previously active version remains inforce.
   e.g. if there are log entries to move the version to 3, then 4, then 3
   the last attempt to change to version 3 is ignored, and the active
   version remains at version 4.

The caller will need to remember the returned nextPos in order that it can provide the version for the call to decode for the next log entry.

Returns an error in the event the entry cannot be correctly decoded.

type ProtobufCommand

type ProtobufCommand interface {
	Size() int
	MarshalTo([]byte) (int, error)
	Unmarshal([]byte) error

ProtobufCommand defines a base interface that all protobuf generated types implement

type Version

type Version = int32

Version represents a version of the log entry format/semantics. Details about each version are in the commands.proto file in the parent package.

Jump to

Keyboard shortcuts

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