66 "github.com/changsongl/delay-queue/job"
77)
88
9+ // |tag|[length]|data
10+
911// tag s
1012const (
1113 TagID uint64 = iota
@@ -32,7 +34,7 @@ func NewCompress() Encoder {
3234 return & compress {}
3335}
3436
35- // Encode compress encode
37+ // Encode compress encode, not using reflect
3638func (c * compress ) Encode (j * job.Job ) ([]byte , error ) {
3739 buf := make ([]byte , c .bufLength (j ))
3840 written := 0
@@ -42,8 +44,6 @@ func (c *compress) Encode(j *job.Job) ([]byte, error) {
4244 if ! j .TTR .IsEmpty () {
4345 written += c .PutUInt64 (TagTTR , uint64 (j .TTR ), buf [written :])
4446 }
45- written += c .PutUInt64 (TagVersion , j .Version .UInt64 (), buf [written :])
46-
4747 if ! j .ID .IsEmpty () {
4848 written += c .PutString (TagID , string (j .ID ), buf [written :])
4949 }
@@ -53,6 +53,7 @@ func (c *compress) Encode(j *job.Job) ([]byte, error) {
5353 if ! j .Topic .IsEmpty () {
5454 written += c .PutString (TagTopic , string (j .Topic ), buf [written :])
5555 }
56+ written += c .PutUInt64 (TagVersion , j .Version .UInt64 (), buf [written :])
5657
5758 return buf [:written ], nil
5859}
@@ -100,7 +101,7 @@ func (c *compress) Decode(b []byte, j *job.Job) error {
100101func (c * compress ) bufLength (j * job.Job ) int {
101102 l := (TagLength + MaxUInt64Length )* 5 + len (j .ID ) + len (j .Topic )
102103 if j .Body != "" {
103- l += TagLength + MaxUInt64Length + len (j .Topic )
104+ l += TagLength + MaxUInt64Length + len (j .Body )
104105 }
105106 return l
106107}
0 commit comments