2 Star 1 Fork 0

李玮 / trireme-lib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
claimsheader.go 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
李玮 提交于 2020-01-29 13:23 . v1
package claimsheader
// NewClaimsHeader returns claims header handler
func NewClaimsHeader(opts ...Option) *ClaimsHeader {
c := &ClaimsHeader{}
for _, opt := range opts {
opt(c)
}
return c
}
// ToBytes generates the 32-bit header in bytes
// 0 1 2 3 4
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | D |CT|E| R (reserved) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// D [0:5] - Datapath version
// CT [6,7] - Compressed tag type
// E [8] - Encryption enabled
// R [9:31] - Reserved
func (c *ClaimsHeader) ToBytes() HeaderBytes {
claimsHeaderData := make([]byte, maxHeaderLen)
claimsHeaderData[0] |= c.datapathVersion.toMask().toUint8()
claimsHeaderData[0] |= c.compressionType.toMask().toUint8()
claimsHeaderData[1] |= boolToUint8(c.encrypt)
return claimsHeaderData
}
// CompressionType is the compression type
func (c *ClaimsHeader) CompressionType() CompressionType {
return c.compressionType
}
// Encrypt is the encrypt in bool
func (c *ClaimsHeader) Encrypt() bool {
return c.encrypt
}
// DatapathVersion is the datapath version
func (c *ClaimsHeader) DatapathVersion() DatapathVersion {
return c.datapathVersion
}
// SetCompressionType sets the compression type
func (c *ClaimsHeader) SetCompressionType(ct CompressionType) {
c.compressionType = ct
}
// SetEncrypt sets the encrypt
func (c *ClaimsHeader) SetEncrypt(e bool) {
c.encrypt = e
}
// SetDatapathVersion sets the datapath version
func (c *ClaimsHeader) SetDatapathVersion(dv DatapathVersion) {
c.datapathVersion = dv
}
1
https://gitee.com/emmoblin/trireme-lib.git
git@gitee.com:emmoblin/trireme-lib.git
emmoblin
trireme-lib
trireme-lib
7726874a2b9a

搜索帮助