34 lines
804 B
Go
34 lines
804 B
Go
package peer
|
|
|
|
import "unsafe"
|
|
|
|
type Nonce struct {
|
|
Timestamp int64
|
|
Counter uint64
|
|
SourceIP byte
|
|
ViaIP byte
|
|
DestIP byte
|
|
StreamID byte // The stream, see STREAM_* constants
|
|
PacketType byte // The packet type. See PACKET_* constants.
|
|
}
|
|
|
|
func (nonce *Nonce) Parse(nb []byte) {
|
|
nonce.Timestamp = *(*int64)(unsafe.Pointer(&nb[0]))
|
|
nonce.Counter = *(*uint64)(unsafe.Pointer(&nb[8]))
|
|
nonce.SourceIP = nb[16]
|
|
nonce.ViaIP = nb[17]
|
|
nonce.DestIP = nb[18]
|
|
nonce.StreamID = nb[19]
|
|
nonce.PacketType = nb[20]
|
|
}
|
|
|
|
func (nonce Nonce) Marshal(buf []byte) {
|
|
*(*int64)(unsafe.Pointer(&buf[0])) = nonce.Timestamp
|
|
*(*uint64)(unsafe.Pointer(&buf[8])) = nonce.Counter
|
|
buf[16] = nonce.SourceIP
|
|
buf[17] = nonce.ViaIP
|
|
buf[18] = nonce.DestIP
|
|
buf[19] = nonce.StreamID
|
|
buf[20] = nonce.PacketType
|
|
}
|