Documentation ¶
Overview ¶
Package messages objects and methods for basic serialization of data into structured messages that can be read by this project.
Integers are encoded using config.encoding BigInts are encoded using GOB Binary values are stored as a single byte, a 0 value byte is considered 0, any other value is considered 1
A struture of a message for the consensus is as follows:
A 4 byte encoded integer indicating the total size of the message in bytes (not including these 4 bytes)
A series of header/contents
A 4 byte integer indicating the size of the header (including these 4 bytes).
A 4 byte encoded integer indicating the header type.
If the header is signed, an encoded consensus id indicating the consensus index this header belongs to, which can be either:
An 8 byte encoded integer.
Or a hash (encoding defined by the hash type defined in the configuration).
An uint64 encoded as a uvarint indicating the number of additional consensus ids this header belongs to (if total order is being used this will be 0, see causal ordering for more details on where this is used).
The additional consensus indices as given by the previous field.
If the header contains at least 1 consensus index then a 32 byte unique ID for this consensus (see CsID) which is included in every signed header (TODO insure only messages with indices can be signed).
The contents are then defined custom for each header type
For signed headers, the signed part starts after the size and includes the consensus index, the consensus unique ID, and any other contents as determined by the result of the call to InternalSignedMsgHeader.SerializeInternal for the message type.
Index ¶
- func AppendMessage(front *Message, end *Message)
- func CreateSingleMsgBytes(header SeralizeHeader) []byte
- func DecodeHelperMsg(msg *MsgBuffer) (n int, buff []byte, err error)
- func DeserializeHelper(headerID HeaderID, item types.BasicEncodeInterface, m *Message) (n int, err error)
- func DeserialzeInternalSignedHeader(hdr InternalSignedMsgHeader, unmarFunc types.ConsensusIndexFuncs, m *Message) (index types.ConsensusIndex, bytesRead, signOffset, signEndOffset int, ...)
- func GetBytesHelper(m *Message) ([]byte, error)
- func GetMsgSizeLen() int
- func IsProposalHeader(msgIndex types.ConsensusIndex, hdr InternalSignedMsgHeader) bool
- func PeekHeaderHead(unmarFunc types.ConsensusIndexFuncs, m *MsgBuffer) (index types.ConsensusIndex, err error)
- func ReadHeaderHead(id HeaderID, unmarFunc types.ConsensusIDUnMarshaler, m *MsgBuffer) (l int, index types.ConsensusID, additionalIndices []types.ConsensusID, ...)
- func SerializeHelper(headerID HeaderID, item types.BasicEncodeInterface, m *Message) (n int, err error)
- func SerializeInternalSignedHeader(index types.ConsensusIndex, hdr InternalSignedMsgHeader, m *Message) (bytesWritten, signOffset, signEndOffset, sizeOffset int, err error)
- func SerializeSingleItem(header MsgHeader) []byte
- func WriteHeaderHead(index types.ConsensusID, additionalIndecies []types.ConsensusID, id HeaderID, ...) (l int, sizeOffset int, offset int)
- type Any
- type BasicMsgID
- type EventInfoMsgID
- type HeaderID
- type InternalSignedMsgHeader
- type Message
- func AppendHeader(msg *Message, header MsgHeader) (*Message, error)
- func AppendHeaders(msg *Message, headers []MsgHeader) (*Message, error)
- func AppendSerialize(msg *Message, header SeralizeHeader) (*Message, error)
- func CreateMsg(headers []MsgHeader) (*Message, error)
- func CreateMsgFromBytes(buf []byte) (*Message, error)
- func CreateMsgSingle(header MsgHeader) (*Message, error)
- func InitMsgSetup(hdrs []MsgHeader, t *testing.T) *Message
- func NewMessage(buff []byte) *Message
- func SerializeHeader(header MsgHeader) (*Message, error)
- func SerializeHeaders(headers []MsgHeader) (*Message, error)
- func (m *Message) CheckHash(offset int, endoffset int, includesHash bool) (types.HashBytes, int, error)
- func (m *Message) ComputeHash(offset, endoffset int, includeHash bool) (types.HashBytes, int, error)
- func (m *Message) GetBytes() []byte
- func (m *Message) GetDebug() []byte
- func (m *Message) Len() int
- func (m *Message) PeekHeaderType() (HeaderID, error)
- func (m *Message) PeekHeaderTypeAt(offs int) (HeaderID, error)
- func (m *Message) PeekMsgConsID(unmarFunc types.ConsensusIDUnMarshaler) (cid types.ConsensusID, err error)
- func (m *Message) PeekMsgIndex() (types.ConsensusInt, error)
- func (m *Message) PopHeaderType() (int, error)
- func (m *Message) PopMsgSize() (int, error)
- func (m *Message) ResetOffset()
- type MsgBuffer
- func (mb *MsgBuffer) AddBigInt(v *big.Int) (int, int)
- func (mb *MsgBuffer) AddBin(v types.BinVal, allowCoin bool) int
- func (mb *MsgBuffer) AddBool(v bool) int
- func (mb *MsgBuffer) AddByte(v byte) int
- func (mb *MsgBuffer) AddBytes(v []byte) (int, int)
- func (mb *MsgBuffer) AddConsensusID(v types.ConsensusID) (int, int)
- func (mb *MsgBuffer) AddConsensusRound(v types.ConsensusRound) (int, int)
- func (mb *MsgBuffer) AddHeaderID(v HeaderID) (int, int)
- func (mb *MsgBuffer) AddSizeBytes(buff []byte) (int, int)
- func (mb *MsgBuffer) AddUint32(v uint32) (int, int)
- func (mb *MsgBuffer) AddUint64(v uint64) (int, int)
- func (mb *MsgBuffer) AddUvarint(v uint64) (n int, offest int)
- func (mb *MsgBuffer) GetReadOffset() int
- func (mb *MsgBuffer) GetRemainingBytes() []byte
- func (mb *MsgBuffer) GetSlice(start, end int) ([]byte, error)
- func (mb *MsgBuffer) GetSliceFrom(start int) ([]byte, error)
- func (mb *MsgBuffer) GetWriteOffset() int
- func (mb *MsgBuffer) PeekConsIDAt(offs int, unmarFunc types.ConsensusIDUnMarshaler) (types.ConsensusID, int, error)
- func (mb *MsgBuffer) PeekUint32() (uint32, error)
- func (mb *MsgBuffer) PeekUint32At(offs int) (uint32, error)
- func (mb *MsgBuffer) PeekUint64() (uint64, error)
- func (mb *MsgBuffer) PeekUint64At(offs int) (uint64, error)
- func (mb *MsgBuffer) PeekUvarintAt(offset int) (v uint64, n int, err error)
- func (mb *MsgBuffer) Read(p []byte) (n int, err error)
- func (mb *MsgBuffer) ReadBigInt() (*big.Int, int, error)
- func (mb *MsgBuffer) ReadBin(allowCoin bool) (types.BinVal, error)
- func (mb *MsgBuffer) ReadBool() (bool, error)
- func (mb *MsgBuffer) ReadByte() (byte, error)
- func (mb *MsgBuffer) ReadBytes(n int) ([]byte, error)
- func (mb *MsgBuffer) ReadConsensusID(unmarFunc types.ConsensusIDUnMarshaler) (types.ConsensusID, int, error)
- func (mb *MsgBuffer) ReadConsensusIndex() (types.ConsensusInt, int, error)
- func (mb *MsgBuffer) ReadConsensusRound() (types.ConsensusRound, int, error)
- func (mb *MsgBuffer) ReadHeaderID() (HeaderID, int, error)
- func (mb *MsgBuffer) ReadSizeBytes() ([]byte, int, error)
- func (mb *MsgBuffer) ReadUint32() (uint32, int, error)
- func (mb *MsgBuffer) ReadUint64() (uint64, int, error)
- func (mb *MsgBuffer) ReadUvarint() (v uint64, n int, err error)
- func (mb *MsgBuffer) RemainingLen() int
- func (mb *MsgBuffer) ResetOffset()
- func (mb *MsgBuffer) Write(p []byte) (n int, err error)
- func (mb *MsgBuffer) WriteAt(offset int, p []byte) (n int, err error)
- func (mb *MsgBuffer) WriteByte(p byte) error
- func (mb *MsgBuffer) WriteUint32At(offset int, v uint32) error
- func (mb *MsgBuffer) WriteUint32AtStart(v uint32) error
- type MsgHeader
- type MsgID
- type MsgIDHeader
- type MsgIDInfo
- type SeralizeBuff
- type SeralizeHeader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendMessage ¶
AppendMessage appends two messages together into a single message and upates the size Only front is updated
func CreateSingleMsgBytes ¶
func CreateSingleMsgBytes(header SeralizeHeader) []byte
SerializeSingle serializes a header by itself into a byte slice
func DecodeHelperMsg ¶
DecodeHelperMsg reads a slice of bytes that was written to the message by utils.EncodeHelper
func DeserializeHelper ¶
func DeserialzeInternalSignedHeader ¶
func DeserialzeInternalSignedHeader(hdr InternalSignedMsgHeader, unmarFunc types.ConsensusIndexFuncs, m *Message) (index types.ConsensusIndex, bytesRead, signOffset, signEndOffset int, size uint32, err error)
func GetBytesHelper ¶
func GetMsgSizeLen ¶
func GetMsgSizeLen() int
func IsProposalHeader ¶
func IsProposalHeader(msgIndex types.ConsensusIndex, hdr InternalSignedMsgHeader) bool
func PeekHeaderHead ¶
func PeekHeaderHead(unmarFunc types.ConsensusIndexFuncs, m *MsgBuffer) (index types.ConsensusIndex, err error)
PeekHeaderHead is a helper method used before deserialization, it returns the indices of the message.
func ReadHeaderHead ¶
func ReadHeaderHead(id HeaderID, unmarFunc types.ConsensusIDUnMarshaler, m *MsgBuffer) (l int, index types.ConsensusID, additionalIndices []types.ConsensusID, size uint32, offset int, err error)
ReadHeaderHead is a helper method used during MsgHeader.Serialize to read the first part of the header to message m. It reads the HeaderID and header size according to the message format described in the root documentation of this package. It checks the HeaderID is correct as well as the CsID. It returns the number of bytes read, the size of the full header, and the offset in the message where the header starts. IMPORTANT: if unmarFunc is nil it expects not to have any indecies, which meas it will not include CsID either.
func SerializeHelper ¶
func SerializeInternalSignedHeader ¶
func SerializeInternalSignedHeader(index types.ConsensusIndex, hdr InternalSignedMsgHeader, m *Message) (bytesWritten, signOffset, signEndOffset, sizeOffset int, err error)
func SerializeSingleItem ¶
SerializeSingleItem serializes a header by itself into a byte slice
func WriteHeaderHead ¶
func WriteHeaderHead(index types.ConsensusID, additionalIndecies []types.ConsensusID, id HeaderID, size uint32, m *MsgBuffer) (l int, sizeOffset int, offset int)
WriteHeaderHead is a helper method used during MsgHeader.Serialize to write the first part of the header to message m. It reads the HeaderID and header size according to the message format described in the root documentation of this package. It writes the size of the header, the HeaderID and the CsID. It returns the number of bytes written, the offset in the message where the size is stored, and the offset in the message where the header starts. Important: if index is nil, it will not write any indecies and will not include the CsID.
Types ¶
type BasicMsgID ¶
type BasicMsgID HeaderID
BasicMsgID implements the MsgID interface as a HeaderID. So every message header with the same HeaderID will have equal MsgIDs.
func (BasicMsgID) IsMsgID ¶
func (BasicMsgID) IsMsgID() bool
IsMsgID to satisfy the interface and returns true
func (BasicMsgID) ToBytes ¶
func (bm BasicMsgID) ToBytes(index types.ConsensusIndex) []byte
func (BasicMsgID) ToMsgIDInfo ¶
func (bm BasicMsgID) ToMsgIDInfo() MsgIDInfo
ToMsgIDInfo converts the MsgID to a MsgIDInfo
type EventInfoMsgID ¶
EventInfoMsgID implements the MsgID interface as a Hash, so every different message is different
func (EventInfoMsgID) IsMsgID ¶
func (EventInfoMsgID) IsMsgID() bool
IsMsgID to satisfy the interface and returns true
func (EventInfoMsgID) ToBytes ¶
func (bm EventInfoMsgID) ToBytes(types.ConsensusIndex) []byte
func (EventInfoMsgID) ToMsgIDInfo ¶
func (bm EventInfoMsgID) ToMsgIDInfo() MsgIDInfo
ToMsgIDInfo converts the MsgID to a MsgIDInfo
type HeaderID ¶
type HeaderID uint32
HeaderID Each message type has a its own header id, this will identify serialized messages
const ( HdrBcons HeaderID = iota // A binary consensus message HdrBconsAux // A binary consensus aux message HdrTest // A test message HdrNetworkTest // A network test message HdrTestTimeout // A timeout test message HdrNoProgress // A message indicating a node has not made progress towards a decision after a timeout HdrConsMsg // A consensus message HdrBinState // A message containing multiple consensus messages HdrSimpleCons // A message for the simple consensus test protocol HdrPropose // A message containing a consensus proposal, used in the sime consensus and tests HdrBinPropose // A message containing a single binary value consensus proposal HdrMvPropose // A message containing a multi-value proposal HdrEcsig // A message containing an EC signature HdrEcpub // A message containing an EC public key HdrEcpriv // A message containing an EC private key HdrSignTest // A message for a signature test HdrAuxProof // A message containing proof supporting an aux binary value HdrAuxStage0 // A message containing proof supporting an aux binary value HdrAuxStage1 // A message containing proof supporting an aux binary value HdrAuxBoth // A message containing proof supporting an aux binary value or both binary values HdrBV0 // A binary value message for 0 HdrBV1 // A binary message for 1 HdrCoin // A message used to compute a random coin for a round for StrongCoin1. HdrCoinPre // A message sent before the coin to change a t+1 coin to an n-t one HdrCoinProof // A proof for a coin. HdrAuxProofTimeout // A round timeout in binary consensus HdrMvInitTimeout // An init message timeout in multivalue consensus HdrMvInitVRFTimeout // An init message timeout in multivalue consensus HdrMvEchoTimeout // An echo message timeout in multivalue consensus HdrMvCommitTimeout // A commit message timeout in multivalue consensus HdrMvInit // A multivalue consensus init message HdrMvMultiInit // A multivalue consensus init message with multiple proposals HdrMvInitSupport // A multivalue consensus init message with pointers to a previous init message HdrMvEcho // A multivalue consensus echo message HdrMvEchoHash // A multivalue consensus echo message with an additional hash HdrMvCommit // A multivalue consensus commit message HdrMvRecoverTimeout // A multivalue consensus recovery timeout message HdrMvRequestRecover // A multivalue consensus message requesting the decided value // HdrDSSPartSig // A partial threshold signature message // HdrDSSPartPub // A partial threshold public key message HdrEdsig // An EDDSA signature message HdrEdpub // An EDDSA public key message HdrSleepPub // A Sleep pub message HdrSleepCoin // A sleep coin message HdrSchnorrsig // A schnorr signature message HdrSleepSig // A sleep signature message HdrSchnorrpub // A schnorr public key message HdrBlssig // A BLS signature message HdrBlspub // A BLS public key message HdrEdPartPub // A partial threshold signature HdrDualPub // A dual pub message HdrPartialMsg // A message that is broken into several parts HdrHash // A message that contains a hash HdrIdx // A message that contains an index for each node HdrIdxRecover // Same as HdrIdx except used during recovery HdrEventInfo // A message that contains a hash event info HdrVrfProof // A message that contains a VRF proof HdrQsafeSig // A quantum safe signature HdrQsafePub // A quantum safe public key )
Each message type is encoded in a 4 byte integer
func (HeaderID) StringShort ¶
type InternalSignedMsgHeader ¶
type InternalSignedMsgHeader interface { MsgIDHeader // GetBaseMsgHeader returns the header pertaning to the message contents (in most cases just directly returns the same header). GetBaseMsgHeader() InternalSignedMsgHeader // SerializeInternal serializes the header contents, returning the number of bytes written and the end of the part of the message that should be signed. SerializeInternal(m *Message) (bytesWritten, signEndOffset int, err error) // DeserializeInternal deserializes the header contents, returning the number of bytes read and the end of the signed part of the message. DeserializeInternal(m *Message) (bytesRead, signEndOffset int, err error) // ShallowCopy preforms a shallow copy of the header. ShallowCopy() InternalSignedMsgHeader // NeedsSMValidation should return a byte slice if the message should be validated by the state machine before being processed, // otherwise it should return nil. // If proposal is non-nil idx should be the state machine index that will be used to validate this message. // It takes as input the current index. // If the message has multiple proposals then proposalIdx is the index of the proposal being requested. // If causal ordering is used then the idx returned is not used. NeedsSMValidation(msgIndex types.ConsensusIndex, proposalIdx int) (idx types.ConsensusIndex, proposal []byte, err error) // NeedsCoinProof returns true if this message must include a proof for a coin message. GetSignType() types.SignType }
type Message ¶
type Message MsgBuffer
func AppendHeader ¶
AppendHeader adds a serialized header to the end of msg and updates the size
func AppendHeaders ¶
AppendHeaders serialized the list of headers and appends them to the end of msg
func AppendSerialize ¶
func AppendSerialize(msg *Message, header SeralizeHeader) (*Message, error)
AppendSerialize adds a serialized header to the end of msg and updates the size
func CreateMsgFromBytes ¶
CreateMsgFromBytes creates a serialzed messages from bytes.
func CreateMsgSingle ¶
CreateMsgSingle creates a serialized message containing a single header.
func InitMsgSetup ¶
InitMsgSetup is used by tests to create a serialized message from hdrs.
func NewMessage ¶
func SerializeHeader ¶
Serialize seralizes a header
func SerializeHeaders ¶
Serialize seralizes a header
func (*Message) ComputeHash ¶
func (*Message) PeekHeaderType ¶
func (*Message) PeekMsgConsID ¶
func (m *Message) PeekMsgConsID(unmarFunc types.ConsensusIDUnMarshaler) (cid types.ConsensusID, err error)
func (*Message) PeekMsgIndex ¶
func (m *Message) PeekMsgIndex() (types.ConsensusInt, error)
func (*Message) PopHeaderType ¶
func (*Message) PopMsgSize ¶
func (*Message) ResetOffset ¶
func (m *Message) ResetOffset()
type MsgBuffer ¶
type MsgBuffer struct {
// contains filtered or unexported fields
}
MsgBuffer is for serializing a message. Read/get and write/put operations can be performed on the buffer. Read operations read based on the index of the previous read, where each operation incraments the index. E.g. the first ReadUint32 reads bytes 0-3, and the follow reads 3-7 Peek operations do not change the index. Write operations write to the end of the buffer. ReadAt/WriteAt operations read/write at a specific index in the buffer.
func NewMsgBufferSize ¶
NewMsgBuffer creates a new buffer using the following: "make([]byte, i, n)"
func ToMsgBuffer ¶
ToMsgBuffer creates a MsgBuffer object from the bytes, the read offset is set to the beginning and the writeoffset is set to the end
func (*MsgBuffer) AddBigInt ¶
AddBinInt encodes v and appends it to the end of the buffer. It returns the number of bytes written, and the offset of where it was written.
func (*MsgBuffer) AddBin ¶
AddBin appends binary value v to the end of the buffer. It returns the offset where v was written to the buffer.
func (*MsgBuffer) AddBool ¶
AddBool appends a boolean value v to the end of the buffer. It returns the offset where v was written to the buffer.
func (*MsgBuffer) AddByte ¶
AddByte appends v to the end of the buffer. It returns the offset where v was written in the buffer.
func (*MsgBuffer) AddBytes ¶
AddBytes append v to the end of the buffer. It reutrns len(v) and the offset where v was written in the buffer.
func (*MsgBuffer) AddConsensusID ¶
func (mb *MsgBuffer) AddConsensusID(v types.ConsensusID) (int, int)
AddConsensusID encodes the id and appends to the end of the buffer. It returns the number of bytes written and where v was written in the buffer.
func (*MsgBuffer) AddConsensusRound ¶
func (mb *MsgBuffer) AddConsensusRound(v types.ConsensusRound) (int, int)
AddConsensusRound encodes the round and appends to the end of the buffer. It returns the number of bytes written and where v was written in the buffer.
func (*MsgBuffer) AddHeaderID ¶
AddHeaderID encodes v and appends it to the end of the buffer. It returns 4 and the offset of where v was written in the buffer.
func (*MsgBuffer) AddSizeBytes ¶
WriteSizeBytes writes a slice of bytes to be read by ReadSizeBytes (it contains a serialized number followed by the bytes) It returns the number of bytes written and the offset where the values were written in the buffer.
func (*MsgBuffer) AddUint32 ¶
AddUint32 encodes v and appends it to the end of the buffer. It returns 4 and the offset of where v was written in the buffer.
func (*MsgBuffer) AddUint64 ¶
AddUint64 encodes v and appends it to the end of the buffer. It returns 8 and the index where v was written
func (*MsgBuffer) AddUvarint ¶
AddUvarint writes a unsigned variable size integer. It returns the number of bytes written and where v was written in the buffer.
func (*MsgBuffer) GetReadOffset ¶
GetReadOffset returns the current read offset
func (*MsgBuffer) GetRemainingBytes ¶
GetRemainingBytes returns the remaining bytes from the current read offset.
func (*MsgBuffer) GetSliceFrom ¶
GetSlice from returns the slice starting at start until the end of the buffer
func (*MsgBuffer) GetWriteOffset ¶
GetWriteOffest returns the current write offset (this will always be the end of the buffer)
func (*MsgBuffer) PeekConsIDAt ¶
func (mb *MsgBuffer) PeekConsIDAt(offs int, unmarFunc types.ConsensusIDUnMarshaler) (types.ConsensusID, int, error)
PeekConsIDAt gets the consensusID at the given offset using the unmarshal function. It returns the id and the number of bytes read.
func (*MsgBuffer) PeekUint32 ¶
PeekUint32 returns the uint32 at the current read offset
func (*MsgBuffer) PeekUint32At ¶
PeekUint32 returns the uint32 at the current offset plus offs
func (*MsgBuffer) PeekUint64 ¶
PeekUint64 returns the uint64 at the current read offset
func (*MsgBuffer) PeekUint64At ¶
PeekUint64At returns the uint64 at the current read offset plus offs
func (*MsgBuffer) PeekUvarintAt ¶
PeekUvarintAt returns the uvarint at the current read offset plus offset. It returns the uint64 and the number of bytes read
func (*MsgBuffer) ReadBigInt ¶
ReadBigInt reads a big integer from the buffer, It returns the big int, and the new read index
func (*MsgBuffer) ReadBin ¶
ReadBin reads a binary value from the buffer and increments the read offset. A binVal is 1 byte, any non-zero value is 1.
func (*MsgBuffer) ReadBool ¶
ReadBool reads a boolean value from the buffer and increments the read offset. A bool is encoded as a byte, any non-zero value is considered true.
func (*MsgBuffer) ReadConsensusID ¶
func (mb *MsgBuffer) ReadConsensusID(unmarFunc types.ConsensusIDUnMarshaler) (types.ConsensusID, int, error)
ReadConsensusID reads a consensus id from the buffer. It returns the value read, the number of bytes read, and any errors. It also increments the read offset.
func (*MsgBuffer) ReadConsensusIndex ¶
func (mb *MsgBuffer) ReadConsensusIndex() (types.ConsensusInt, int, error)
ReadConsensusIndex reads a consensus index from the buffer. It returns the value read, the number of bytes read, and any errors. It also increments the read offset.
func (*MsgBuffer) ReadConsensusRound ¶
func (mb *MsgBuffer) ReadConsensusRound() (types.ConsensusRound, int, error)
ReadConsensusRound reads a consensus round from the buffer. It returns the value read, the number of bytes read, and any errors. It also increments the read offset.
func (*MsgBuffer) ReadHeaderID ¶
ReadHeaderID reads a HeaderID from the buffer. It returns the value read, the number of bytes read, and any errors. It also increments the read offset.
func (*MsgBuffer) ReadSizeBytes ¶
ReadSizeBytes reads a slice of bytes written by AddSizeBytes, it returns the nubmer of bytes read (i.e. a serialized number followed by that many bytes)
func (*MsgBuffer) ReadUint32 ¶
ReadUint32 reads a uint32 from the buffer. It returns the value read, the number of bytes read, and any errors. It also increments the read offset.
func (*MsgBuffer) ReadUint64 ¶
ReadKey return the uint64 at the current offset, the number of bytes read, and any error. It also increments the read offset.
func (*MsgBuffer) ReadUvarint ¶
ReadUvarint reads an unsigned variable sized integer from the buffer. It returns the value read, the number of bytes read and any errors.
func (*MsgBuffer) RemainingLen ¶
RemainingLen returns the number of bytes from the current read offset to the end of the buffer.
func (*MsgBuffer) ResetOffset ¶
func (mb *MsgBuffer) ResetOffset()
ResetOffest sets the read offset to 0, so the following read will read from the beginning of the buffer
func (*MsgBuffer) WriteUint32At ¶
WriteUint32At encodes v and overwrites the bytes at offset
func (*MsgBuffer) WriteUint32AtStart ¶
WriteUint32 encodes and overwrites the beggning of the message with v
type MsgHeader ¶
type MsgHeader interface { MsgIDHeader SeralizeHeader // PeekHeader returns the indices related to the messages without impacting m. PeekHeaders(m *Message, unmarFunc types.ConsensusIndexFuncs) (index types.ConsensusIndex, err error) Deserialize(m *Message, unmarFunc types.ConsensusIndexFuncs) (int, error) // Deserialize deserialzes a header into the object, returning the number of bytes read GetBytes(m *Message) ([]byte, error) // GetBytes returns the bytes that make up the header }
MsgHeader is a component of a messsage that contains an id (an encoded 4 byte integer), followed by any data The interface allows for serialization and deserialzation of the message
func AppendCopyMsgHeader ¶
AppendCopyMsgHeader appends the input into a new slice.
type MsgID ¶
type MsgID interface { IsMsgID() bool // IsMsgID to satisfy the interface and returns true ToBytes(index types.ConsensusIndex) []byte // Returns the byte representation of MsgID ToMsgIDInfo() MsgIDInfo // ToMsgIDInfo converts the MsgID to a MsgIDInfo }
MsgID: Each message has a MsgID, that may differentiate it between messages of the same type for example a binary messages have the same MsgID for the same round (for both 1 and 0) but have different MsgIDs for different rounds this is only used internally and not serialized The idea is so we can cout how many messages of each type we have gotten. For example if we want to have 'n-t' messages of type 'aux' for round 1 of binary consensus, we will use the MsgID to count these, since they will have the same MsgID even if they support different binary values. Note it is importat that MsgID is comparable with == (i.e. if it returns a pointer to a new object then every message header will have a different MsgID) TODO maybe this check should happen in a method instead like 'CheckEqual'
type MsgIDHeader ¶
type SeralizeBuff ¶
type SeralizeBuff []byte
Interface for using byte slice with the serialize method
type SeralizeHeader ¶
type SeralizeHeader interface {
Serialize(m *Message) (int, error) // Serialize appends a serialized header to the message m, and returns the size of bytes written
}
SerializeHeader implements the serialize method