github.com/prebid/prebid-server/v2@v2.18.0/usersync/decoder.go (about)

     1  package usersync
     2  
     3  import (
     4  	"encoding/base64"
     5  
     6  	"github.com/prebid/prebid-server/v2/util/jsonutil"
     7  )
     8  
     9  type Decoder interface {
    10  	Decode(encodedValue string) *Cookie
    11  }
    12  
    13  type Base64Decoder struct{}
    14  
    15  func (d Base64Decoder) Decode(encodedValue string) *Cookie {
    16  	jsonValue, err := base64.URLEncoding.DecodeString(encodedValue)
    17  	if err != nil {
    18  		return NewCookie()
    19  	}
    20  
    21  	var cookie Cookie
    22  	if err = jsonutil.UnmarshalValid(jsonValue, &cookie); err != nil {
    23  		return NewCookie()
    24  	}
    25  
    26  	return &cookie
    27  }