Added version and re-ordered header... Breaking change
This commit is contained in:
		| @@ -13,23 +13,25 @@ const ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| type header struct { | type header struct { | ||||||
|  | 	Version  byte | ||||||
| 	StreamID byte | 	StreamID byte | ||||||
| 	Counter  uint64 // Init with time.Now().Unix << 30 to ensure monotonic. |  | ||||||
| 	SourceIP byte | 	SourceIP byte | ||||||
| 	DestIP   byte | 	DestIP   byte | ||||||
|  | 	Counter  uint64 // Init with time.Now().Unix << 30 to ensure monotonic. | ||||||
| } | } | ||||||
|  |  | ||||||
| func (h *header) Parse(b []byte) { | func (h *header) Parse(b []byte) { | ||||||
| 	h.StreamID = b[0] | 	h.Version = b[0] | ||||||
| 	h.Counter = *(*uint64)(unsafe.Pointer(&b[1])) | 	h.StreamID = b[1] | ||||||
| 	h.SourceIP = b[9] | 	h.SourceIP = b[2] | ||||||
| 	h.DestIP = b[10] | 	h.DestIP = b[3] | ||||||
|  | 	h.Counter = *(*uint64)(unsafe.Pointer(&b[4])) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (h *header) Marshal(buf []byte) { | func (h *header) Marshal(buf []byte) { | ||||||
| 	buf[0] = h.StreamID | 	buf[0] = h.Version | ||||||
| 	*(*uint64)(unsafe.Pointer(&buf[1])) = h.Counter | 	buf[1] = h.StreamID | ||||||
| 	buf[9] = h.SourceIP | 	buf[2] = h.SourceIP | ||||||
| 	buf[10] = h.DestIP | 	buf[3] = h.DestIP | ||||||
| 	buf[11] = 0 | 	*(*uint64)(unsafe.Pointer(&buf[4])) = h.Counter | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user