@@ -29,11 +29,7 @@ const MAX_EIDS_COOKIE_BYTES: usize = 8 * 1024;
2929struct LegacyCookieEid {
3030 source : String ,
3131 id : String ,
32- #[ allow(
33- dead_code,
34- reason = "legacy cookie field is deserialized for compatibility but not emitted"
35- ) ]
36- atype : u8 ,
32+ atype : i32 ,
3733}
3834
3935/// OpenRTB-style `ts-eids` cookie entry.
@@ -48,7 +44,7 @@ struct StructuredCookieEid {
4844struct StructuredCookieUid {
4945 id : String ,
5046 #[ serde( default ) ]
51- atype : Option < u8 > ,
47+ atype : Option < i32 > ,
5248 #[ serde( default ) ]
5349 ext : Option < JsonValue > ,
5450}
@@ -318,14 +314,15 @@ fn structured_cookie_uid_to_openrtb(uid: StructuredCookieUid) -> Option<Uid> {
318314 return None ;
319315 }
320316
317+ let atype = uid. atype . filter ( |atype| * atype >= 0 ) ;
321318 let ext = match uid. ext {
322319 Some ( JsonValue :: Object ( _) ) => uid. ext ,
323320 _ => None ,
324321 } ;
325322
326323 Some ( Uid {
327324 id : uid. id ,
328- atype : uid . atype ,
325+ atype,
329326 ext,
330327 } )
331328}
@@ -338,7 +335,7 @@ fn legacy_cookie_eids_to_openrtb(entries: Vec<LegacyCookieEid>) -> Vec<Eid> {
338335 source : entry. source ,
339336 uids : vec ! [ Uid {
340337 id: entry. id,
341- atype: Some ( entry. atype) ,
338+ atype: ( entry . atype >= 0 ) . then_some ( entry. atype) ,
342339 ext: None ,
343340 } ] ,
344341 } )
@@ -407,15 +404,25 @@ mod tests {
407404 let eids = vec ! [
408405 json!( { "source" : "id5-sync.com" , "id" : "ID5_abc" , "atype" : 1 } ) ,
409406 json!( { "source" : "liveramp.com" , "id" : "LR_xyz" , "atype" : 3 } ) ,
407+ json!( { "source" : "google.com" , "id" : "pair-id" , "atype" : 571187 } ) ,
410408 ] ;
411409 let encoded = BASE64 . encode ( serde_json:: to_vec ( & eids) . expect ( "should serialize" ) ) ;
412410
413411 let decoded = parse_prebid_eids_cookie ( & encoded) . expect ( "should decode valid payload" ) ;
414- assert_eq ! ( decoded. len( ) , 2 , "should parse both EIDs" ) ;
412+ assert_eq ! ( decoded. len( ) , 3 , "should parse all EIDs" ) ;
415413 assert_eq ! ( decoded[ 0 ] . source, "id5-sync.com" ) ;
416414 assert_eq ! ( decoded[ 0 ] . uids[ 0 ] . id, "ID5_abc" ) ;
417415 assert_eq ! ( decoded[ 1 ] . source, "liveramp.com" ) ;
418416 assert_eq ! ( decoded[ 1 ] . uids[ 0 ] . id, "LR_xyz" ) ;
417+ assert_eq ! (
418+ decoded[ 2 ] . source, "google.com" ,
419+ "should preserve PAIR source"
420+ ) ;
421+ assert_eq ! (
422+ decoded[ 2 ] . uids[ 0 ] . atype,
423+ Some ( 571187 ) ,
424+ "should preserve PAIR vendor-specific atype"
425+ ) ;
419426 }
420427
421428 #[ test]
@@ -424,22 +431,45 @@ mod tests {
424431 "source" : "sharedid.org" ,
425432 "uids" : [
426433 { "id" : "shared_123" , "atype" : 3 } ,
427- { "id" : "shared_456" , "ext" : { "provider" : "example" } }
434+ { "id" : "shared_456" , "ext" : { "provider" : "example" } } ,
435+ { "id" : "shared_invalid" , "atype" : -1 }
428436 ]
429437 } ) ] ;
430438 let encoded = BASE64 . encode ( serde_json:: to_vec ( & eids) . expect ( "should serialize" ) ) ;
431439
432440 let decoded = parse_prebid_eids_cookie ( & encoded) . expect ( "should decode valid payload" ) ;
433441 assert_eq ! ( decoded. len( ) , 1 , "should parse one structured EID entry" ) ;
434442 assert_eq ! ( decoded[ 0 ] . source, "sharedid.org" ) ;
435- assert_eq ! ( decoded[ 0 ] . uids. len( ) , 2 , "should preserve multiple UIDs" ) ;
443+ assert_eq ! ( decoded[ 0 ] . uids. len( ) , 3 , "should preserve multiple UIDs" ) ;
436444 assert_eq ! ( decoded[ 0 ] . uids[ 0 ] . id, "shared_123" ) ;
437445 assert_eq ! ( decoded[ 0 ] . uids[ 0 ] . atype, Some ( 3 ) ) ;
438446 assert_eq ! (
439447 decoded[ 0 ] . uids[ 1 ] . ext,
440448 Some ( json!( { "provider" : "example" } ) ) ,
441449 "should preserve UID ext objects"
442450 ) ;
451+ assert_eq ! (
452+ decoded[ 0 ] . uids[ 2 ] . atype, None ,
453+ "should drop negative atype values"
454+ ) ;
455+ }
456+
457+ #[ test]
458+ fn parse_prebid_eids_cookie_preserves_pair_atype ( ) {
459+ let encoded = encode_json ( & json ! ( [
460+ {
461+ "source" : "google.com" ,
462+ "uids" : [ { "id" : "pair-id" , "atype" : 571187 } ]
463+ }
464+ ] ) ) ;
465+
466+ let decoded = parse_prebid_eids_cookie ( & encoded) . expect ( "should decode PAIR EID" ) ;
467+
468+ assert_eq ! (
469+ decoded[ 0 ] . uids[ 0 ] . atype,
470+ Some ( 571187 ) ,
471+ "should preserve PAIR's vendor-specific atype"
472+ ) ;
443473 }
444474
445475 #[ test]
0 commit comments