From b7e43ac8fe3bbc31f7b4453cd5a44fbb6b7d57fe Mon Sep 17 00:00:00 2001 From: wangjian Date: Sat, 8 Oct 2022 21:19:25 +0800 Subject: [PATCH] bug fix --- coder.go | 4 ++-- decoder.go | 6 +++--- encoder.go | 12 ++++++------ encoder_sugar.go | 4 ++-- packet.go | 2 +- spec/spec.go | 2 +- spec/tlv.t.go | 6 +++--- spec/tvl.l.go | 1 - 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/coder.go b/coder.go index 06557c5..9f86d98 100644 --- a/coder.go +++ b/coder.go @@ -35,8 +35,8 @@ type Packet interface { // BytesV 返回流字节 BytesV() []byte - // UTF8StringV 返回流的utf8字符串值 - UTF8StringV() string + // Utf8StringV 返回流的utf8字符串值 + Utf8StringV() string // Int32V 返回流的int32值 Int32V() (val int32, err error) // UInt32V 返回流的uint32值 diff --git a/decoder.go b/decoder.go index 70c6470..3fcd5cb 100644 --- a/decoder.go +++ b/decoder.go @@ -21,8 +21,8 @@ func NewDecoder(reader io.Reader) *Decoder { } } -// SeqID return the SequenceID of the decoding packet -func (d *Decoder) SeqID() int { +// SeqId return the SequenceID of the decoding packet +func (d *Decoder) SeqId() int { return d.tag.Sid() } @@ -68,7 +68,7 @@ func (d *Decoder) GetFullFilledPacket() (packet Packet, err error) { packet = &StreamPacket{ t: d.tag, l: *d.len, - vbuf: buf.Bytes(), + vBuf: buf.Bytes(), chunkMode: false, } diff --git a/encoder.go b/encoder.go index 66eaf30..dc627d8 100644 --- a/encoder.go +++ b/encoder.go @@ -19,7 +19,7 @@ type Encoder struct { isStreamMode bool valBuf *bytes.Buffer done bool - seqID int + seqId int isNodeMode bool } @@ -29,8 +29,8 @@ func (b *Encoder) SetSeqId(seqId int, isNode bool) { // init b.valBuf = new(bytes.Buffer) b.nodes = make(map[int]Packet) - // set seqID - b.seqID = seqId + // set seqId + b.seqId = seqId b.isNodeMode = isNode } @@ -119,7 +119,7 @@ func (b *Encoder) Packet() (Packet, error) { t: b.tag, l: *b.len, vr: b.valReader, - vbuf: b.valBuf.Bytes(), + vBuf: b.valBuf.Bytes(), chunkMode: true, chunkSize: b.valReaderSize, }, err @@ -129,14 +129,14 @@ func (b *Encoder) Packet() (Packet, error) { return &StreamPacket{ t: b.tag, l: *b.len, - vbuf: b.valBuf.Bytes(), + vBuf: b.valBuf.Bytes(), chunkMode: false, }, err } // will generate T of a TLV. func (b *Encoder) generateT() error { - t, err := spec.NewT(b.seqID) + t, err := spec.NewT(b.seqId) t.SetNodeMode(b.isNodeMode) if err != nil { return err diff --git a/encoder_sugar.go b/encoder_sugar.go index dcba977..1bc92f9 100644 --- a/encoder_sugar.go +++ b/encoder_sugar.go @@ -4,8 +4,8 @@ import ( "git.hpds.cc/Component/mq_coder/encoding" ) -// SetUTF8StringV set utf-8 string type value as V -func (b *Encoder) SetUTF8StringV(v string) { +// SetUtf8StringV set utf-8 string type value as V +func (b *Encoder) SetUtf8StringV(v string) { buf := []byte(v) b.SetBytesV(buf) } diff --git a/packet.go b/packet.go index e322cde..b4328ca 100644 --- a/packet.go +++ b/packet.go @@ -102,7 +102,7 @@ func (p *StreamPacket) BytesV() []byte { } // UTF8StringV return V as utf-8 string -func (p *StreamPacket) UTF8StringV() string { +func (p *StreamPacket) Utf8StringV() string { return string(p.vBuf) } diff --git a/spec/spec.go b/spec/spec.go index b2a5244..350e525 100644 --- a/spec/spec.go +++ b/spec/spec.go @@ -6,7 +6,7 @@ import ( ) const ( - maxSeqID = 0x3F + maxSeqId = 0x3F flagBitNode = 0x80 wipeFlagBits = 0x3F msb = 0x80 diff --git a/spec/tlv.t.go b/spec/tlv.t.go index ec12dc4..985e41f 100644 --- a/spec/tlv.t.go +++ b/spec/tlv.t.go @@ -10,12 +10,12 @@ type T byte // NewT returns a T with sequenceID. If this packet contains other // packets, this packet will be a "node packet", the T of this packet // will set MSB to T. -func NewT(seqID int) (T, error) { - if seqID < 0 || seqID > maxSeqID { +func NewT(seqId int) (T, error) { + if seqId < 0 || seqId > maxSeqId { return 0, errInvalidSeqId } - return T(seqID), nil + return T(seqId), nil } // Sid returns the sequenceId of this packet. diff --git a/spec/tvl.l.go b/spec/tvl.l.go index db762a4..9397608 100644 --- a/spec/tvl.l.go +++ b/spec/tvl.l.go @@ -6,7 +6,6 @@ import ( "io" "git.hpds.cc/Component/mq_coder/encoding" - //"mq_coder/encoding" ) // L is the Length in a TLV structure