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