-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsegment_publisher_tc.go
55 lines (45 loc) · 1.78 KB
/
segment_publisher_tc.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
package iabtcfv2
import "encoding/base64"
type PublisherTC struct {
SegmentType int
PubPurposesConsent map[int]bool
PubPurposesLITransparency map[int]bool
NumCustomPurposes int
CustomPurposesConsent map[int]bool
CustomPurposesLITransparency map[int]bool
}
// Returns true if user has given consent to standard purpose id
func (p *PublisherTC) IsPurposeAllowed(id int) bool {
return p.PubPurposesConsent[id]
}
// Returns true if legitimate interest is established for standard purpose id
// and user didn't exercise their right to object
func (p *PublisherTC) IsPurposeLIAllowed(id int) bool {
return p.PubPurposesLITransparency[id]
}
// Returns true if user has given consent to custom purpose id
func (p *PublisherTC) IsCustomPurposeAllowed(id int) bool {
return p.CustomPurposesConsent[id]
}
// Returns true if legitimate interest is established for custom purpose id
// and user didn't exercise their right to object
func (p *PublisherTC) IsCustomPurposeLIAllowed(id int) bool {
return p.CustomPurposesLITransparency[id]
}
// Returns structure as a base64 raw url encoded string
func (p *PublisherTC) Encode() string {
var bitSize int
bitSize += bitsSegmentType
bitSize += bitsPubPurposesConsent
bitSize += bitsPubPurposesLITransparency
bitSize += bitsNumCustomPurposes
bitSize += p.NumCustomPurposes * 2
e := NewTCEncoderFromSize(bitSize)
e.WriteInt(p.SegmentType, bitsSegmentType)
e.WriteBools(p.IsPurposeAllowed, bitsPubPurposesConsent)
e.WriteBools(p.IsPurposeLIAllowed, bitsPubPurposesLITransparency)
e.WriteInt(p.NumCustomPurposes, bitsNumCustomPurposes)
e.WriteBools(p.IsCustomPurposeAllowed, p.NumCustomPurposes)
e.WriteBools(p.IsCustomPurposeLIAllowed, p.NumCustomPurposes)
return base64.RawURLEncoding.EncodeToString(e.Bytes)
}