NAME

GDPR::IAB::TCFv2::BitField - Transparency & Consent String version 2 bitfield parser

SYNOPSIS

my $data = unpack "B*", decode_base64url('tcf v2 consent string base64 encoded');

my $max_id_consent = << get 16 bits from $data offset 213 >>

my $bit_field = GDPR::IAB::TCFv2::BitField->Parse(
    data      => substr($data, OFFSET),
    data_size => length($data),
    max_id    => $max_id_consent,
    options   => { json => ... },
);

say "bit field contains id 284" if $bit_field->contains(284);

CONSTRUCTOR

Constructor Parse receives an hash of 4 parameters:

  • Key data is the binary data

  • Key data_size is the original binary data size

  • Key max_id is the max id (used to validate the ranges if all data is between 1 and max_id)

  • Key options is the GDPR::IAB::TCFv2 options (includes the json field to modify the "TO_JSON" method output.

METHODS

contains

Return the vendor id bit status (if enable or not) from the bit field. Will return false if id is bigger than max vendor id.

my $ok = $bit_field->contains(284);

max_id

Returns the max vendor id.

all

Returns an array of all vendors mapped with the bit enabled.

TO_JSON

By default it returns an hashref mapping id to a boolean, that represent if the id is active or not in the bitfield.

The json option verbose controls if all ids between 1 to "max_id" will be present on the json or only the ones that are true.

The json option compact change the response, will return an arrayref of all ids active on the bitfield.