-
Notifications
You must be signed in to change notification settings - Fork 718
/
convert_down.go
310 lines (256 loc) · 7.09 KB
/
convert_down.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
package openrtb_ext
func ConvertDownTo25(r *RequestWrapper) error {
// schain
if err := moveSupplyChainFrom26To25(r); err != nil {
return err
}
// gdpr
if err := moveGDPRFrom26To25(r); err != nil {
return err
}
if err := moveConsentFrom26To25(r); err != nil {
return err
}
// ccpa
if err := moveUSPrivacyFrom26To25(r); err != nil {
return err
}
// eid
if err := moveEIDFrom26To25(r); err != nil {
return err
}
// imp
for _, imp := range r.GetImp() {
if err := moveRewardedFrom26ToPrebidExt(imp); err != nil {
return err
}
}
// Remove fields introduced in OpenRTB 2.6+. The previous OpenRTB 2.5 spec did not specify that
// bidders must tolerate new or unexpected fields.
clear26Fields(r)
clear202211Fields(r)
clear202303Fields(r)
return nil
}
// moveSupplyChainFrom26To25 modifies the request to move the OpenRTB 2.6 supply chain
// object (req.source.schain) to the OpenRTB 2.5 location (req.source.ext.schain). If the
// OpenRTB 2.5 location is already present it may be overwritten. The OpenRTB 2.5 location
// is expected to be empty.
func moveSupplyChainFrom26To25(r *RequestWrapper) error {
if r.Source == nil || r.Source.SChain == nil {
return nil
}
// read and clear 2.6 location
schain26 := r.Source.SChain
r.Source.SChain = nil
// move to 2.5 location
sourceExt, err := r.GetSourceExt()
if err != nil {
return err
}
sourceExt.SetSChain(schain26)
return nil
}
// moveGDPRFrom26To25 modifies the request to move the OpenRTB 2.6 GDPR signal
// field (req.regs.gdpr) to the OpenRTB 2.5 location (req.regs.ext.gdpr). If the
// OpenRTB 2.5 location is already present it may be overwritten. The OpenRTB 2.5
// location is expected to be empty.
func moveGDPRFrom26To25(r *RequestWrapper) error {
if r.Regs == nil || r.Regs.GDPR == nil {
return nil
}
// read and clear 2.6 location
gdpr26 := r.Regs.GDPR
r.Regs.GDPR = nil
// move to 2.5 location
regExt, err := r.GetRegExt()
if err != nil {
return err
}
regExt.SetGDPR(gdpr26)
return nil
}
// moveConsentFrom26To25 modifies the request to move the OpenRTB 2.6 GDPR consent
// field (req.user.consent) to the OpenRTB 2.5 location (req.user.ext.consent). If
// the OpenRTB 2.5 location is already present it may be overwritten. The OpenRTB 2.5
// location is expected to be empty.
func moveConsentFrom26To25(r *RequestWrapper) error {
if r.User == nil || len(r.User.Consent) == 0 {
return nil
}
// read and clear 2.6 location
consent26 := r.User.Consent
r.User.Consent = ""
// move to 2.5 location
userExt, err := r.GetUserExt()
if err != nil {
return err
}
userExt.SetConsent(&consent26)
return nil
}
// moveUSPrivacyFrom26To25 modifies the request to move the OpenRTB 2.6 US Privacy (CCPA)
// consent string (req.regs.us_privacy) to the OpenRTB 2.5 location (req.regs.ext.us_privacy).
// If the OpenRTB 2.5 location is already present it may be overwritten. The OpenRTB 2.5
// location is expected to be empty.
func moveUSPrivacyFrom26To25(r *RequestWrapper) error {
if r.Regs == nil || len(r.Regs.USPrivacy) == 0 {
return nil
}
// read and clear 2.6 location
usprivacy26 := r.Regs.USPrivacy
r.Regs.USPrivacy = ""
// move to 2.5 location
regExt, err := r.GetRegExt()
if err != nil {
return err
}
regExt.SetUSPrivacy(usprivacy26)
return nil
}
// moveEIDFrom26To25 modifies the request to move the OpenRTB 2.6 external identifiers
// (req.user.eids) to the OpenRTB 2.5 location (req.user.ext.eids). If the OpenRTB 2.5
// location is already present it may be overwritten. The OpenRTB 2.5 location is
// expected to be empty.
func moveEIDFrom26To25(r *RequestWrapper) error {
if r.User == nil || r.User.EIDs == nil {
return nil
}
// read and clear 2.6 location
eid26 := r.User.EIDs
r.User.EIDs = nil
// move to 2.5 location
userExt, err := r.GetUserExt()
if err != nil {
return err
}
userExt.SetEid(&eid26)
return nil
}
// moveRewardedFrom26ToPrebidExt modifies the impression to move the OpenRTB 2.6 rewarded
// signal (imp[].rwdd) to the OpenRTB 2.x Prebid specific location (imp[].ext.prebid.is_rewarded_inventory).
// If the Prebid specific location is already present, it may be overwritten. The Prebid specific
// location is expected to be empty.
func moveRewardedFrom26ToPrebidExt(i *ImpWrapper) error {
if i.Rwdd == 0 {
return nil
}
// read and clear 2.6 location
rwdd26 := i.Rwdd
i.Rwdd = 0
// move to Prebid specific location
impExt, err := i.GetImpExt()
if err != nil {
return err
}
impExtPrebid := impExt.GetOrCreatePrebid()
impExtPrebid.IsRewardedInventory = &rwdd26
impExt.SetPrebid(impExtPrebid)
return nil
}
// clear26Fields sets all fields introduced in OpenRTB 2.6 to default values, which
// will cause them to be omitted during json marshal.
func clear26Fields(r *RequestWrapper) {
r.WLangB = nil
r.CatTax = 0
if app := r.App; app != nil {
app.CatTax = 0
app.KwArray = nil
if content := r.App.Content; content != nil {
content.CatTax = 0
content.KwArray = nil
content.LangB = ""
content.Network = nil
content.Channel = nil
if producer := r.App.Content.Producer; producer != nil {
producer.CatTax = 0
}
}
if publisher := r.App.Publisher; publisher != nil {
publisher.CatTax = 0
}
}
if site := r.Site; site != nil {
site.CatTax = 0
site.KwArray = nil
if content := r.Site.Content; content != nil {
content.CatTax = 0
content.KwArray = nil
content.LangB = ""
content.Network = nil
content.Channel = nil
if producer := r.Site.Content.Producer; producer != nil {
producer.CatTax = 0
}
}
if publisher := r.Site.Publisher; publisher != nil {
publisher.CatTax = 0
}
}
if device := r.Device; device != nil {
device.SUA = nil
device.LangB = ""
}
if regs := r.Regs; regs != nil {
regs.GDPR = nil
regs.USPrivacy = ""
}
if source := r.Source; source != nil {
source.SChain = nil
}
if user := r.User; user != nil {
user.KwArray = nil
user.Consent = ""
user.EIDs = nil
}
for _, imp := range r.GetImp() {
imp.Rwdd = 0
imp.SSAI = 0
if audio := imp.Audio; audio != nil {
audio.PodDur = 0
audio.RqdDurs = nil
audio.PodID = ""
audio.PodSeq = 0
audio.SlotInPod = 0
audio.MinCPMPerSec = 0
}
if video := imp.Video; video != nil {
video.MaxSeq = 0
video.PodDur = 0
video.PodID = ""
video.PodSeq = 0
video.RqdDurs = nil
video.SlotInPod = 0
video.MinCPMPerSec = 0
}
}
}
// clear202211Fields sets all fields introduced in OpenRTB 2.6-202211 to default values
// which will cause them to be omitted during json marshal.
func clear202211Fields(r *RequestWrapper) {
r.DOOH = nil
if app := r.App; app != nil {
app.InventoryPartnerDomain = ""
}
if site := r.Site; site != nil {
site.InventoryPartnerDomain = ""
}
if regs := r.Regs; regs != nil {
regs.GPP = ""
regs.GPPSID = nil
}
for _, imp := range r.GetImp() {
imp.Qty = nil
imp.DT = 0
}
}
// clear202303Fields sets all fields introduced in OpenRTB 2.6-202303 to default values
// which will cause them to be omitted during json marshal.
func clear202303Fields(r *RequestWrapper) {
for _, imp := range r.GetImp() {
imp.Refresh = nil
if video := imp.Video; video != nil {
video.Plcmt = 0
}
}
}