Resolve the issue of garbled characters in the Golang language message body GzipDecoder.(解决Golang消费大消息体时,gzip解压乱码问题) #845
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
当客户发发送一个数据量大的消息体时,由于进行了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 }