-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support cat msg v2 * fixes * Fixes 2 * Fix unit * handle settings in storage cat interactions * Fxies
- Loading branch information
Showing
15 changed files
with
290 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package message | ||
|
||
import ( | ||
"encoding/binary" | ||
|
||
"github.com/yezzey-gp/yproxy/pkg/settings" | ||
) | ||
|
||
type CatMessageV2 struct { | ||
Decrypt bool | ||
Name string | ||
StartOffset uint64 | ||
|
||
Settings []settings.StorageSettings | ||
} | ||
|
||
var _ ProtoMessage = &CatMessage{} | ||
|
||
func NewCatMessageV2(name string, decrypt bool, StartOffset uint64, Settings []settings.StorageSettings) *CatMessageV2 { | ||
return &CatMessageV2{ | ||
Name: name, | ||
Decrypt: decrypt, | ||
StartOffset: StartOffset, | ||
Settings: Settings, | ||
} | ||
} | ||
|
||
func (c *CatMessageV2) Encode() []byte { | ||
bt := []byte{ | ||
byte(MessageTypeCatV2), | ||
0, | ||
0, | ||
0, | ||
} | ||
|
||
if c.Decrypt { | ||
bt[1] = byte(DecryptMessage) | ||
} else { | ||
bt[1] = byte(NoDecryptMessage) | ||
} | ||
|
||
bt = append(bt, []byte(c.Name)...) | ||
bt = append(bt, 0) | ||
bt = binary.BigEndian.AppendUint64(bt, c.StartOffset) | ||
|
||
bt = binary.BigEndian.AppendUint64(bt, uint64(len(c.Settings))) | ||
|
||
for _, s := range c.Settings { | ||
|
||
bt = append(bt, []byte(s.Name)...) | ||
bt = append(bt, 0) | ||
|
||
bt = append(bt, []byte(s.Value)...) | ||
bt = append(bt, 0) | ||
} | ||
|
||
ln := len(bt) + 8 | ||
|
||
bs := make([]byte, 8) | ||
binary.BigEndian.PutUint64(bs, uint64(ln)) | ||
return append(bs, bt...) | ||
} | ||
|
||
func (c *CatMessageV2) Decode(body []byte) { | ||
var off uint64 | ||
c.Name, off = GetCstring(body[4:]) | ||
if body[1] == byte(DecryptMessage) { | ||
c.Decrypt = true | ||
} | ||
c.StartOffset = binary.BigEndian.Uint64(body[4+len(c.Name)+1:]) | ||
|
||
settLen := binary.BigEndian.Uint64(body[4+8+off : 4+off+8+8]) | ||
|
||
totalOff := 4 + off + 8 + 8 | ||
|
||
c.Settings = make([]settings.StorageSettings, settLen) | ||
|
||
for i := 0; i < int(settLen); i++ { | ||
|
||
var currOff uint64 | ||
|
||
c.Settings[i].Name, currOff = GetCstring(body[totalOff:]) | ||
totalOff += currOff | ||
|
||
c.Settings[i].Value, currOff = GetCstring(body[totalOff:]) | ||
totalOff += currOff | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package message | ||
|
||
import "bytes" | ||
|
||
func GetCstring(b []byte) (string, uint64) { | ||
offset := uint64(0) | ||
buff := bytes.NewBufferString("") | ||
|
||
for i := 0; i < len(b); i++ { | ||
offset++ | ||
if b[i] == 0 { | ||
break | ||
} | ||
buff.WriteByte(b[i]) | ||
} | ||
|
||
return buff.String(), offset | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.