Documentation ¶
Overview ¶
Package binmsg can marshal and unmarshal a binary encoded message with a timestamp (time, data) and GPS data: Lat., Lon., Alt., FixMode, and a HMAC hashsum.
Index ¶
Constants ¶
const PayloadOctets = messageOctets + shaSize
PayloadOctets is the amount of octets (bytes) the 'data' byte slice returned from (*Payload).MarshalBinary() (data []byte, err error) has.
Variables ¶
var ( //ErrHMACOctetsWrongSize is the error for HMACOctet with a wrong size. ErrHMACOctetsWrongSize = errors.New( "The Payload'sHMACOctets slice does not have a slice of " + "sha256.Size224 octets in length.") //ErrHMACcheckFailed is the error for failed SECURITY check. //The payload does _NOT_ has vaild data. ErrHMACcheckFailed = errors.New( "SECURITY: HMAC check failed") //ErrPayloadSizeTooSmall is the error for a payload byte slice with an //incorrect length. //(The initBinMsg function creates this error). ErrPayloadSizeTooSmall error //ErrNilHMACSecretKeySlice is the error for a nil or zero length HMACkey secret. ErrNilHMACSecretKeySlice = errors.New( "The 'HMACSecretKey' byte slice has not been set " + "(It is nil or its length is zero).") //ErrNiSaltSlice is the error for a nil or zero length salt secret. ErrNiSaltSlice = errors.New( "The 'Salt' byte slice has not been set " + "(It is nil or its length is zero).") //ErrNilMessageOctetsSlice is the error for a message byte slice with a //wrong length/size. ErrNilMessageOctetsSlice = errors.New( "The messageoctets byte slice is nil or has a zero length.") ErrNilByteSlice = errors.New( "<nil> byte slice") )
Functions ¶
Types ¶
type Gps ¶
type Gps struct { FixMode gpsfix.FixMode `json:"fixmode"` Latitude float32 `json:"latitude"` Longitude float32 `json:"longitude"` Altitude float32 `json:"altitude"` }
Gps is type that contain a FixMode and the 32-bit floating point values: Latitude, Longitude, and Altitude.
func (*Gps) SetAlt ¶
SetAlt sets the 32-bit floating point altitude value via a 64-bit floating point value.
type Message ¶
type Message struct { //TimeStamp octets: timeStampOctets(=8) bytes (type time.Duration is an int64 value) TimeStamp TimeStamp `json:"timestamp"` //Gps octets: gpsOctet bytes Gps Gps `json:"gps"` }
Message is a type that contains a TimeStamp type (when was this message created?), and a Gps type.
func (*Message) MarshalBinary ¶
MarshalBinary marshals the struct fields from type Message into a binary representation of type Message, which are returned in a byte slice.
func (*Message) UnmarshalBinary ¶
UnmarshalBinary unmarshals a binary representation of a Payload in a byte slice into the data a Payload type contains.
type Payload ¶
type Payload struct { Secrets Secrets `json:"-"` Message Message // contains filtered or unexported fields }
Payload is a type which is a representaion of the payload transmitted between RMSG.dk programs.
func New ¶
New creates a new Payload with the given 'hmacKey' and 'salt' byte slices. If ('Payload).Init(hmacKey, salt) returns an error, then a nil Payload and the error are returned.
func (*Payload) Init ¶
Init initializes a Payload type with the given 'hmacKey' and 'salt' slices. Init does a simple zero length/nil check on both given slices, and one of them has the zero length or is nil, then an error is reutned, if there are no errors, then the nil error is returned.
func (*Payload) MarshalBinary ¶
MarshalBinary marshals the data a payload type contains into a binary representation of a Payload, which are stored in a byte slice.
func (*Payload) UnmarshalBinary ¶
UnmarshalBinary unmarshals a binary representation of a Payload in a byte slice into the data a Payload type contains.
type Secrets ¶
type Secrets struct { HMACKey []byte //shared HMAC secret key Salt []byte //crypto.Rand generated garbage - lots of it, shared secret }
Secrets is a type that contains the shared secrets, while a Payload had been initialized.
type TimeStamp ¶
TimeStamp contains the timestamp, which is used to distinghish between an old message and a new message.
func (*TimeStamp) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. The time is a quoted string in RFC 3339 format, with sub-second precision added if present.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package cmd is tools for go-rmsggpsbinmsg
|
Package cmd is tools for go-rmsggpsbinmsg |