GODRIVER-3303 Remove redundant code; Add test cases.#1753
GODRIVER-3303 Remove redundant code; Add test cases.#1753qingyang-hu merged 5 commits intomongodb:v1from
Conversation
API Change Report./x/mongo/driver/wiremessageincompatible changesReadCompressedCompressedMessage: removed |
| if !ok { | ||
| return 0, nil, errors.New("malformed OP_COMPRESSED: missing compressor ID") | ||
| } | ||
| compressedSize := len(wm) - 9 // original opcode (4) + uncompressed size (4) + compressor ID (1) |
There was a problem hiding this comment.
We don't have to calculate the length as long as the above ReadCompressedOriginalOpCode, ReadCompressedUncompressedSize, and ReadCompressedCompressorID are correct. compressedSize must be strictly equal to len(rem) because it is where rem comes from. Therefore, the ReadCompressedCompressedMessage is unnecessary as well.
| identifier, rem, ret, ok := ReadMsgSectionRawDocumentSequence(src) | ||
| if !ok { | ||
| return "", nil, rem, false | ||
| return "", nil, ret, false |
There was a problem hiding this comment.
Why return ret here instead of rem? Should we always return either src or []byte{} in the !ok condition instead?
There was a problem hiding this comment.
The ret returned by ReadMsgSectionRawDocumentSequence is the rem in the original logic. I just kept the returned variable names of ReadMsgSectionRawDocumentSequence to avoid confusion there. However, you are right that we only need to return an empty slice or even nil on false cases including those underneath.
Co-authored-by: Kobrin Ilay <ilayko3110@yandex.ru> (cherry picked from commit 87ae788)
GODRIVER-3303
Summary
As a follow-up of PR #1735
Background & Motivation