Add coder/decoder size to coder

This commit is contained in:
2024-07-31 13:05:13 +02:00
parent 7001f2c51a
commit d0c868ca5c
4 changed files with 22 additions and 13 deletions

View File

@@ -19,7 +19,7 @@ func (c *GSM7Coder) Encode(s *string, buf *bytes.Buffer) error {
bitshift byte = 0
leap, shift bool
)
encodedSize := GSM7EncodesInto(s)
encodedSize := c.EncodesInto(s)
cap := buf.Cap()
if cap < encodedSize {
buf.Grow(encodedSize - cap)
@@ -77,7 +77,7 @@ func (c *GSM7Coder) Decode(buf *bytes.Buffer) (string, error) {
bitshift byte = 0
leap bool
)
outLength := GSM7DecodesInto(buf)
outLength := c.DecodesInto(buf)
lengthDiff := outLength - len(gsm7)
gsm7 = append(gsm7, make([]byte, lengthDiff)...)
start := len(gsm7) - 2
@@ -121,7 +121,7 @@ func InsertAt(data *[]byte, index int, value byte) {
(*data)[index] = value
}
func GSM7EncodesInto(s *string) int {
func (c GSM7Coder) EncodesInto(s *string) int {
slen := len(*s)
enclen := slen * 7 / 8
if slen%8 != 0 {
@@ -129,7 +129,7 @@ func GSM7EncodesInto(s *string) int {
}
return enclen
}
func GSM7DecodesInto(buf *bytes.Buffer) int {
func (c GSM7Coder) DecodesInto(buf *bytes.Buffer) int {
blen := buf.Len()
declen := blen * 8 / 7
return declen