github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/controller/pkg/claimsheader/bytes.go (about) 1 package claimsheader 2 3 // HeaderBytes is the claimsheader in bytes 4 type HeaderBytes []byte 5 6 // ToClaimsHeader parses the bytes and returns the ClaimsHeader 7 func (h HeaderBytes) ToClaimsHeader() *ClaimsHeader { 8 9 if h == nil || len(h) != maxHeaderLen { 10 return NewClaimsHeader() 11 } 12 13 compressionTypeMask := compressionTypeMask(h.extractHeaderAttribute(h[0], compressionTypeBitMask.toUint8())) 14 datapathVersionMask := datapathVersionMask(h.extractHeaderAttribute(h[0], datapathVersionBitMask.toUint8())) 15 16 return &ClaimsHeader{ 17 compressionType: compressionTypeMask.toType(), 18 encrypt: uint8ToBool(encrypt, h.extractHeaderAttribute(h[1], encryptionEnabledBit)), 19 ping: uint8ToBool(ping, h.extractHeaderAttribute(h[1], pingEnabledBit)), 20 datapathVersion: datapathVersionMask.toType(), 21 } 22 } 23 24 // extractHeaderAttribute returns the attribute from byte 25 // mask - mask specific to the attribute 26 func (h HeaderBytes) extractHeaderAttribute(attr byte, mask uint8) uint8 { 27 28 return attr & mask 29 }