Change Regs.COPPA, Banner.TopFrame, Video.MinBitRate to pointer types - #29
Open
sujanchalla0510 wants to merge 1 commit into
Open
Change Regs.COPPA, Banner.TopFrame, Video.MinBitRate to pointer types#29sujanchalla0510 wants to merge 1 commit into
sujanchalla0510 wants to merge 1 commit into
Conversation
These fields were typed as plain int8/int64 with `json:"...,omitempty"`.
encoding/json's omitempty treats a value type's zero value as empty, so
explicitly setting one of these fields to a meaningful 0 was
indistinguishable, once marshaled, from never having set the field:
- Regs.COPPA: 0 means "not subject to COPPA" - a real, often
compliance-relevant signal, not "unknown".
- Banner.TopFrame: 0 means "not in the top frame".
- Video.MinBitRate: a real 0 Kbps floor is a valid value.
All three were silently dropped from the marshaled JSON when set to 0,
so a sender explicitly signaling "no"/"0" produced wire output
identical to never having set the attribute at all.
This repo already uses pointer types for the identical "0/1, omission
means Unknown" semantic on sibling fields in the same structs -
Regs.GDPR, Banner.Vcm, and Device.DNT - so this brings COPPA, TopFrame,
and MinBitRate in line with that existing, established pattern rather
than introducing a new one. Uses the existing Int8Ptr/Int64Ptr helpers
from ptr.go.
Adds zero_value_fields_test.go, verified to fail to even compile against
the old value types and pass against the fix.
Fixes prebid#13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #13.
Summary
Regs.COPPA,Banner.TopFrame, andVideo.MinBitRatewere typed asplain
int8/int64withjson:"...,omitempty".encoding/json'somitemptytreats a value type's zero value as empty, so explicitlysetting one of these fields to a meaningful
0was indistinguishable,once marshaled, from never having set the field at all:
Regs.COPPA:0means "not subject to COPPA" — a real,compliance-relevant signal, not "unknown".
Banner.TopFrame:0means "not in the top frame".Video.MinBitRate: a real0Kbps floor is a valid value, per thespec.
All three were silently dropped from the marshaled JSON when set to
0, so a sender explicitly signaling "no"/"0" produced wire outputidentical to never having set the attribute at all.
Fix
This repo already uses pointer types for the identical "0/1, omission
means Unknown" semantic on sibling fields in the same structs —
Regs.GDPR,Banner.Vcm, andDevice.DNT— so this bringsCOPPA,TopFrame, andMinBitRatein line with that existing, establishedpattern rather than introducing a new one. Uses the existing
Int8Ptr/Int64Ptrhelpers fromptr.go.Breaking change
This is a source-breaking change for any caller directly assigning
these three fields as value types (e.g.
banner.TopFrame = 1becomesbanner.TopFrame = openrtb2.Int8Ptr(1)). Per the README this repofollows semver with major-version releases for breaking changes (the
module is already at
v20), so I'm assuming that's the expected pathhere — happy to adjust if you'd prefer a different approach.
Test plan
zero_value_fields_test.go, which marshals each field setexplicitly to
0and asserts it survives in the output. Verifiedthese tests fail to even compile against the old value types
(proving the fix is necessary), and pass against the fix.
go build ./...,go vet ./...,go test ./...all pass.gofmtclean.