From 3c157f531d865ad1a5bf4b974ed62dc365a50005 Mon Sep 17 00:00:00 2001 From: wangjian Date: Sun, 26 Mar 2023 23:18:55 +0800 Subject: [PATCH] =?UTF-8?q?fix=20Type=E4=B8=8D=E8=83=BD=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=BD=ACbyte=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frame/data_frame.go | 6 +++--- frame/goaway_frame.go | 6 +++--- frame/handshake_frame.go | 26 +++++++++++++------------- frame/meta_frame.go | 14 +++++++------- frame/payload_frame.go | 2 +- frame/rejected_frame.go | 6 +++--- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/frame/data_frame.go b/frame/data_frame.go index ec0b547..217d943 100644 --- a/frame/data_frame.go +++ b/frame/data_frame.go @@ -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 diff --git a/frame/goaway_frame.go b/frame/goaway_frame.go index 33c0a8f..dd82a2c 100644 --- a/frame/goaway_frame.go +++ b/frame/goaway_frame.go @@ -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 diff --git a/frame/handshake_frame.go b/frame/handshake_frame.go index e00672e..4b4cda6 100644 --- a/frame/handshake_frame.go +++ b/frame/handshake_frame.go @@ -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 diff --git a/frame/meta_frame.go b/frame/meta_frame.go index 8f95d2a..e9beb32 100644 --- a/frame/meta_frame.go +++ b/frame/meta_frame.go @@ -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 diff --git a/frame/payload_frame.go b/frame/payload_frame.go index 2282682..2f1f43b 100644 --- a/frame/payload_frame.go +++ b/frame/payload_frame.go @@ -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() diff --git a/frame/rejected_frame.go b/frame/rejected_frame.go index bc27bfe..9cb5db4 100644 --- a/frame/rejected_frame.go +++ b/frame/rejected_frame.go @@ -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