Skip to content

Commit

Permalink
Fix unit
Browse files Browse the repository at this point in the history
  • Loading branch information
reshke committed Aug 26, 2024
1 parent 3d646af commit 90337de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
20 changes: 5 additions & 15 deletions pkg/message/cat_message_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,11 @@ func (c *CatMessageV2) Encode() []byte {
bt[1] = byte(NoDecryptMessage)
}

if c.StartOffset != 0 {
bt[2] = byte(ExtendedMesssage)
}

bt = append(bt, []byte(c.Name)...)
bt = append(bt, 0)
if c.StartOffset != 0 {
bt = binary.BigEndian.AppendUint64(bt, c.StartOffset)
}
bt = binary.BigEndian.AppendUint64(bt, c.StartOffset)

slen := make([]byte, 8)
binary.BigEndian.PutUint64(slen, uint64(len(c.Settings)))
bt = append(bt, slen...)
bt = binary.BigEndian.AppendUint64(bt, uint64(len(c.Settings)))

for _, s := range c.Settings {

Expand All @@ -75,13 +67,11 @@ func (c *CatMessageV2) Decode(body []byte) {
if body[1] == byte(DecryptMessage) {
c.Decrypt = true
}
if body[2] == byte(ExtendedMesssage) {
c.StartOffset = binary.BigEndian.Uint64(body[4+len(c.Name)+1:])
}
c.StartOffset = binary.BigEndian.Uint64(body[4+len(c.Name)+1:])

settLen := binary.BigEndian.Uint64(body[4+off : 4+off+8])
settLen := binary.BigEndian.Uint64(body[4+8+off : 4+off+8+8])

totalOff := 4 + off + 8
totalOff := 4 + off + 8 + 8

c.Settings = make([]settings.StorageSettings, settLen)

Expand Down
3 changes: 3 additions & 0 deletions pkg/message/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestPutV2Msg(t *testing.T) {

assert.Equal(msg.Name, msg2.Name)
assert.Equal(msg.Encrypt, msg2.Encrypt)
assert.Equal(msg.Settings, msg2.Settings)
}
}

Expand Down Expand Up @@ -171,6 +172,8 @@ func TestCatMsgV2(t *testing.T) {

assert.Equal(msg.Name, msg2.Name)
assert.Equal(msg.Decrypt, msg2.Decrypt)
assert.Equal(msg.StartOffset, msg2.StartOffset)
assert.Equal(msg.Settings, msg2.Settings)
}
}

Expand Down

0 comments on commit 90337de

Please sign in to comment.