Skip to content

Commit 9421e17

Browse files
Changed librabry from jsoniterator to json parser
1 parent 8e49141 commit 9421e17

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

modules/pubmatic/openwrap/sdk/googlesdk/request.go

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -276,46 +276,32 @@ func modifyRequestWithStaticData(request *openrtb2.BidRequest) {
276276

277277
// change data type of user.ext.consented_providers_settings.consented_providers from []string to []int
278278
if request.User != nil && request.User.Ext != nil {
279-
var userExt map[string]interface{}
280-
var err error
281-
282-
err = jsoniterator.Unmarshal(request.User.Ext, &userExt)
283-
if err != nil {
284-
return
285-
}
286-
287-
providerSettings, ok := userExt["consented_providers_settings"].(map[string]interface{})
288-
if !ok {
289-
return
290-
}
291-
292-
consentedProviders, ok := providerSettings["consented_providers"].([]interface{})
293-
if !ok {
279+
consentedProvidedBytes, dataType, _, err := jsonparser.Get(request.User.Ext, "consented_providers_settings", "consented_providers")
280+
if err != nil || dataType != jsonparser.Array {
294281
return
295282
}
296283

297-
var consentedProvidersInt []int
298-
for i := range consentedProviders {
299-
provider, ok := consentedProviders[i].(string)
300-
if !ok {
301-
continue
284+
var consentedProviders []int
285+
_, err = jsonparser.ArrayEach(consentedProvidedBytes, func(provider []byte, dataType jsonparser.ValueType, offset int, err error) {
286+
if err != nil || dataType != jsonparser.String {
287+
return
302288
}
303289

304-
providerInt, err := strconv.Atoi(provider)
305-
if err != nil {
306-
continue
290+
providerInt, err := strconv.Atoi(string(provider))
291+
if err == nil {
292+
consentedProviders = append(consentedProviders, providerInt)
307293
}
308-
309-
consentedProvidersInt = append(consentedProvidersInt, providerInt)
294+
})
295+
if err != nil {
296+
return
310297
}
311298

312-
providerSettings["consented_providers"] = consentedProvidersInt
313-
userExt["consented_providers_settings"] = providerSettings
314-
315-
request.User.Ext, err = jsoniterator.Marshal(userExt)
299+
providesBytes, err := jsoniterator.Marshal(consentedProviders)
316300
if err != nil {
317-
glog.Errorf("[GoogleSDK] [Error]: failed to marshal user ext %v", err)
301+
glog.Errorf("[GoogleSDK] [Error]: failed to marshal consented providers %v", err)
318302
}
303+
304+
request.User.Ext, _ = jsonparser.Set(request.User.Ext, providesBytes, "consented_providers_settings", "consented_providers")
319305
}
320306
}
321307

0 commit comments

Comments
 (0)