Documentation
¶
Overview ¶
Package logencoder handles serialization and deserialization of logentry.*Command in to/from bytes. The resulting bytes should be written/read from the log.
Index ¶
Constants ¶
const DefaultLogVersion = 1
DefaultLogVersion is the log version a new empty log should start at.
const MaxVersionSupported = 1
MaxVersionSupported contains the maximum log version that the running process supports.
Variables ¶
This section is empty.
Functions ¶
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.
Types ¶
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 ¶
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.