Skip to content

GODRIVER-3071 Correct uint Encoding BSON Documentation #1500

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

Merged
merged 4 commits into from
Jan 12, 2024

Conversation

prestonvasquez
Copy link
Member

@prestonvasquez prestonvasquez commented Dec 18, 2023

GODRIVER-3071

Summary

Update documentation for when the Go Driver will marshal Go integer values (int, int8, int16, int32, int64, uint, uint8, uint16, uint32, or uint64) as the minimum BSON int size (either 32 or 64 bits) that can represent the integer value.

Background & Motivation

A user submitted this community issue describing how the Go Driver does not work as described in the following documentation:

uint, uint32, and uint64 marshal to a BSON int32 if the value is between math.MinInt32 and math.MaxInt32, inclusive, and BSON int64 otherwise.

The logic for this, added in GODRIVER-1358, is contradictory. The default case for the "min int" condition in the UintCodec is false / nil, which means that an type >= 32-bits will be considered int64. This can also be effected by EncodeContext.MinSize.

@prestonvasquez prestonvasquez requested a review from a team as a code owner December 18, 2023 22:33
@prestonvasquez prestonvasquez requested review from matthewdale and removed request for a team December 18, 2023 22:33
@prestonvasquez prestonvasquez added the priority-3-low Low Priority PR for Review label Dec 18, 2023
Copy link
Contributor

API Change Report

No changes found!

bson/doc.go Outdated
Comment on lines 73 to 75
// 6. When encoding with EncodeContext.MinSize set to true, uint, uint32, and uint64 will marshal to a BSON int32 if
// the value falls within the inclusive range of math.MinInt32 to math.MaxInt32. Otherwise, they will marshal to a
// BSON int64. See Encoder examples for usage of EncodeContext.MinSize.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EncodeContext.MinSize is deprecated, so we shouldn't recommend that people use it. They should use Encoder.IntMinSize instead.

prestonvasquez and others added 2 commits January 5, 2024 12:18
Co-authored-by: Matt Dale <[email protected]>
Co-authored-by: Matt Dale <[email protected]>
Copy link
Collaborator

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

@prestonvasquez prestonvasquez merged commit 6740ce0 into mongodb:v1 Jan 12, 2024
@prestonvasquez prestonvasquez deleted the GODRIVER-3071 branch January 12, 2024 21:10
blink1073 pushed a commit to blink1073/mongo-go-driver that referenced this pull request Jan 13, 2024
qingyang-hu pushed a commit that referenced this pull request Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-3-low Low Priority PR for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants