Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve the issue of garbled characters in the Golang language message body GzipDecoder.(解决Golang消费大消息体时,gzip解压乱码问题) #845

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

leader318
Copy link

当客户发发送一个数据量大的消息体时,由于进行了gzip 压缩,golang 版本的代码,消费数据时,原先GZIPDecode 方法有问题,故新增了一个BytesGzipDecode 方法,测试无问题,可以正常消费。

旧函数:
`
func GZIPDecode(in []byte) ([]byte, error) {
reader, err := gzip.NewReader(bytes.NewReader(in))
if err != nil {
var out []byte
return out, err
}
defer reader.Close()
return ioutil.ReadAll(reader)
}

`

新增函数:

func BytesGzipDecode(src []byte) ([]byte, error) { // Create a zlib reader byteArrayInputStream := bytes.NewReader(src) inflatesInputStream, err := zlib.NewReader(byteArrayInputStream) if err != nil { return nil, err } defer inflatesInputStream.Close() // Create a buffer to store decompressed data var byteArrayOutputStream bytes.Buffer _, err = io.Copy(&byteArrayOutputStream, inflatesInputStream) if err != nil { return nil, err } return byteArrayOutputStream.Bytes(), nil }

@leader318
Copy link
Author

当发送的消息体数据过大时,消费时,golang 会出现乱码,就是之前GZIPDecode 这个方法解压时出现的问题,希望官方帮忙解决一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant