github.com/prebid/prebid-server@v0.275.0/usersync/decoder.go (about)

     1  package usersync
     2  
     3  import (
     4  	"encoding/base64"
     5  	"encoding/json"
     6  )
     7  
     8  type Decoder interface {
     9  	// Decode takes an encoded string and decodes it into a cookie
    10  	Decode(v 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 = json.Unmarshal(jsonValue, &cookie); err != nil {
    23  		return NewCookie()
    24  	}
    25  
    26  	return &cookie
    27  }