fix Type不能自动转byte的问题
This commit is contained in:
parent
a750964220
commit
3c157f531d
|
@ -71,7 +71,7 @@ func (d *DataFrame) SourceId() string {
|
|||
|
||||
// Encode return coder encoded bytes of `DataFrame`
|
||||
func (d *DataFrame) Encode() []byte {
|
||||
data := coder.NewNodePacketEncoder(d.Type())
|
||||
data := coder.NewNodePacketEncoder(byte(d.Type()))
|
||||
// MetaFrame
|
||||
data.AddBytes(d.metaFrame.Encode())
|
||||
// PayloadFrame
|
||||
|
@ -90,7 +90,7 @@ func DecodeToDataFrame(buf []byte) (*DataFrame, error) {
|
|||
|
||||
data := &DataFrame{}
|
||||
|
||||
if metaBlock, ok := packet.NodePackets[TagOfMetaFrame]; ok {
|
||||
if metaBlock, ok := packet.NodePackets[byte(TagOfMetaFrame)]; ok {
|
||||
meta, err := DecodeToMetaFrame(metaBlock.GetRawBytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -98,7 +98,7 @@ func DecodeToDataFrame(buf []byte) (*DataFrame, error) {
|
|||
data.metaFrame = meta
|
||||
}
|
||||
|
||||
if payloadBlock, ok := packet.NodePackets[TagOfPayloadFrame]; ok {
|
||||
if payloadBlock, ok := packet.NodePackets[byte(TagOfPayloadFrame)]; ok {
|
||||
payload, err := DecodeToPayloadFrame(payloadBlock.GetRawBytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -21,9 +21,9 @@ func (f *GoawayFrame) Type() Type {
|
|||
|
||||
// Encode to coder encoded bytes
|
||||
func (f *GoawayFrame) Encode() []byte {
|
||||
goaway := coder.NewNodePacketEncoder(f.Type())
|
||||
goaway := coder.NewNodePacketEncoder(byte(f.Type()))
|
||||
// message
|
||||
msgBlock := coder.NewPrimitivePacketEncoder(TagOfGoawayMessage)
|
||||
msgBlock := coder.NewPrimitivePacketEncoder(byte(TagOfGoawayMessage))
|
||||
msgBlock.SetStringValue(f.message)
|
||||
|
||||
goaway.AddPrimitivePacket(msgBlock)
|
||||
|
@ -46,7 +46,7 @@ func DecodeToGoawayFrame(buf []byte) (*GoawayFrame, error) {
|
|||
|
||||
goaway := &GoawayFrame{}
|
||||
// message
|
||||
if msgBlock, ok := node.PrimitivePackets[TagOfGoawayMessage]; ok {
|
||||
if msgBlock, ok := node.PrimitivePackets[byte(TagOfGoawayMessage)]; ok {
|
||||
msg, err := msgBlock.ToUTF8String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -39,24 +39,24 @@ func (h *HandshakeFrame) Type() Type {
|
|||
// Encode to coder encoding.
|
||||
func (h *HandshakeFrame) Encode() []byte {
|
||||
// name
|
||||
nameBlock := coder.NewPrimitivePacketEncoder(TagOfHandshakeName)
|
||||
nameBlock := coder.NewPrimitivePacketEncoder(byte(TagOfHandshakeName))
|
||||
nameBlock.SetStringValue(h.Name)
|
||||
// client ID
|
||||
idBlock := coder.NewPrimitivePacketEncoder(TagOfHandshakeId)
|
||||
idBlock := coder.NewPrimitivePacketEncoder(byte(TagOfHandshakeId))
|
||||
idBlock.SetStringValue(h.ClientId)
|
||||
// client type
|
||||
typeBlock := coder.NewPrimitivePacketEncoder(TagOfHandshakeType)
|
||||
typeBlock := coder.NewPrimitivePacketEncoder(byte(TagOfHandshakeType))
|
||||
typeBlock.SetBytesValue([]byte{h.ClientType})
|
||||
// observe data tags
|
||||
observeDataTagsBlock := coder.NewPrimitivePacketEncoder(TagOfHandshakeObserveDataTags)
|
||||
observeDataTagsBlock := coder.NewPrimitivePacketEncoder(byte(TagOfHandshakeObserveDataTags))
|
||||
observeDataTagsBlock.SetBytesValue(h.ObserveDataTags)
|
||||
// auth
|
||||
authNameBlock := coder.NewPrimitivePacketEncoder(TagOfHandshakeAuthName)
|
||||
authNameBlock := coder.NewPrimitivePacketEncoder(byte(TagOfHandshakeAuthName))
|
||||
authNameBlock.SetStringValue(h.authName)
|
||||
authPayloadBlock := coder.NewPrimitivePacketEncoder(TagOfHandshakeAuthPayload)
|
||||
authPayloadBlock := coder.NewPrimitivePacketEncoder(byte(TagOfHandshakeAuthPayload))
|
||||
authPayloadBlock.SetStringValue(h.authPayload)
|
||||
// handshake frame
|
||||
handshake := coder.NewNodePacketEncoder(h.Type())
|
||||
handshake := coder.NewNodePacketEncoder(byte(h.Type()))
|
||||
handshake.AddPrimitivePacket(nameBlock)
|
||||
handshake.AddPrimitivePacket(idBlock)
|
||||
handshake.AddPrimitivePacket(typeBlock)
|
||||
|
@ -77,7 +77,7 @@ func DecodeToHandshakeFrame(buf []byte) (*HandshakeFrame, error) {
|
|||
|
||||
handshake := &HandshakeFrame{}
|
||||
// name
|
||||
if nameBlock, ok := node.PrimitivePackets[TagOfHandshakeName]; ok {
|
||||
if nameBlock, ok := node.PrimitivePackets[byte(TagOfHandshakeName)]; ok {
|
||||
name, err := nameBlock.ToUTF8String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -85,7 +85,7 @@ func DecodeToHandshakeFrame(buf []byte) (*HandshakeFrame, error) {
|
|||
handshake.Name = name
|
||||
}
|
||||
// client id
|
||||
if idBlock, ok := node.PrimitivePackets[TagOfHandshakeId]; ok {
|
||||
if idBlock, ok := node.PrimitivePackets[byte(TagOfHandshakeId)]; ok {
|
||||
id, err := idBlock.ToUTF8String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -93,23 +93,23 @@ func DecodeToHandshakeFrame(buf []byte) (*HandshakeFrame, error) {
|
|||
handshake.ClientId = id
|
||||
}
|
||||
// client type
|
||||
if typeBlock, ok := node.PrimitivePackets[TagOfHandshakeType]; ok {
|
||||
if typeBlock, ok := node.PrimitivePackets[byte(TagOfHandshakeType)]; ok {
|
||||
clientType := typeBlock.ToBytes()
|
||||
handshake.ClientType = clientType[0]
|
||||
}
|
||||
// observe data tag list
|
||||
if observeDataTagsBlock, ok := node.PrimitivePackets[TagOfHandshakeObserveDataTags]; ok {
|
||||
if observeDataTagsBlock, ok := node.PrimitivePackets[byte(TagOfHandshakeObserveDataTags)]; ok {
|
||||
handshake.ObserveDataTags = observeDataTagsBlock.ToBytes()
|
||||
}
|
||||
// auth
|
||||
if authNameBlock, ok := node.PrimitivePackets[TagOfHandshakeAuthName]; ok {
|
||||
if authNameBlock, ok := node.PrimitivePackets[byte(TagOfHandshakeAuthName)]; ok {
|
||||
authName, err := authNameBlock.ToUTF8String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
handshake.authName = authName
|
||||
}
|
||||
if authPayloadBlock, ok := node.PrimitivePackets[TagOfHandshakeAuthPayload]; ok {
|
||||
if authPayloadBlock, ok := node.PrimitivePackets[byte(TagOfHandshakeAuthPayload)]; ok {
|
||||
authPayload, err := authPayloadBlock.ToUTF8String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -57,20 +57,20 @@ func (m *MetaFrame) SourceId() string {
|
|||
|
||||
// Encode implements Frame.Encode method.
|
||||
func (m *MetaFrame) Encode() []byte {
|
||||
meta := coder.NewNodePacketEncoder(TagOfMetaFrame)
|
||||
meta := coder.NewNodePacketEncoder(byte(TagOfMetaFrame))
|
||||
// transaction ID
|
||||
transactionId := coder.NewPrimitivePacketEncoder(TagOfTransactionId)
|
||||
transactionId := coder.NewPrimitivePacketEncoder(byte(TagOfTransactionId))
|
||||
transactionId.SetStringValue(m.tid)
|
||||
meta.AddPrimitivePacket(transactionId)
|
||||
|
||||
// source ID
|
||||
sourceId := coder.NewPrimitivePacketEncoder(TagOfSourceId)
|
||||
sourceId := coder.NewPrimitivePacketEncoder(byte(TagOfSourceId))
|
||||
sourceId.SetStringValue(m.sourceId)
|
||||
meta.AddPrimitivePacket(sourceId)
|
||||
|
||||
// metadata
|
||||
if m.metadata != nil {
|
||||
metadata := coder.NewPrimitivePacketEncoder(TagOfMetadata)
|
||||
metadata := coder.NewPrimitivePacketEncoder(byte(TagOfMetadata))
|
||||
metadata.SetBytesValue(m.metadata)
|
||||
meta.AddPrimitivePacket(metadata)
|
||||
}
|
||||
|
@ -89,17 +89,17 @@ func DecodeToMetaFrame(buf []byte) (*MetaFrame, error) {
|
|||
meta := &MetaFrame{}
|
||||
for k, v := range nodeBlock.PrimitivePackets {
|
||||
switch k {
|
||||
case TagOfTransactionId:
|
||||
case byte(TagOfTransactionId):
|
||||
val, err := v.ToUTF8String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
meta.tid = val
|
||||
break
|
||||
case TagOfMetadata:
|
||||
case byte(TagOfMetadata):
|
||||
meta.metadata = v.ToBytes()
|
||||
break
|
||||
case TagOfSourceId:
|
||||
case byte(TagOfSourceId):
|
||||
sourceId, err := v.ToUTF8String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -30,7 +30,7 @@ func (m *PayloadFrame) Encode() []byte {
|
|||
carriage := coder.NewPrimitivePacketEncoder(m.Tag)
|
||||
carriage.SetBytesValue(m.Carriage)
|
||||
|
||||
payload := coder.NewNodePacketEncoder(TagOfPayloadFrame)
|
||||
payload := coder.NewNodePacketEncoder(byte(TagOfPayloadFrame))
|
||||
payload.AddPrimitivePacket(carriage)
|
||||
|
||||
return payload.Encode()
|
||||
|
|
|
@ -21,9 +21,9 @@ func (f *RejectedFrame) Type() Type {
|
|||
|
||||
// Encode to coder encoded bytes
|
||||
func (f *RejectedFrame) Encode() []byte {
|
||||
rejected := coder.NewNodePacketEncoder(f.Type())
|
||||
rejected := coder.NewNodePacketEncoder(byte(f.Type()))
|
||||
// message
|
||||
msgBlock := coder.NewPrimitivePacketEncoder(TagOfRejectedMessage)
|
||||
msgBlock := coder.NewPrimitivePacketEncoder(byte(TagOfRejectedMessage))
|
||||
msgBlock.SetStringValue(f.message)
|
||||
|
||||
rejected.AddPrimitivePacket(msgBlock)
|
||||
|
@ -45,7 +45,7 @@ func DecodeToRejectedFrame(buf []byte) (*RejectedFrame, error) {
|
|||
}
|
||||
rejected := &RejectedFrame{}
|
||||
// message
|
||||
if msgBlock, ok := node.PrimitivePackets[TagOfRejectedMessage]; ok {
|
||||
if msgBlock, ok := node.PrimitivePackets[byte(TagOfRejectedMessage)]; ok {
|
||||
msg, e := msgBlock.ToUTF8String()
|
||||
if e != nil {
|
||||
return nil, e
|
||||
|
|
Loading…
Reference in New Issue