The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

GDPR::IAB::TCFv2::RangeSection - Transparency & Consent String version 2 range section 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 ($range_section, $next_offset) = GDPR::IAB::TCFv2::RangeSection->Parse(
        data      => $data,
        data_size => length($data),
        offset    => 230,             # offset for vendor ranges
        max_id    => $max_id_consent,
        prefetch  => 284,             # will cache the result of vendor id 284
    );

    say "range section contains id 284" if $range_section->contains(284);

CONSTRUCTOR

Constructor Parse receives an hash parameters:

  • Key data is the binary data

  • Key data_size is the original binary data size

  • Key offset is the binary data offset. Can be 0.

  • 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.

  • Key prefetch is an optional arrayref of vendor ids to populate the result as cache.

Will die if any parameter is missing.

Will die if data does not contain all bits required.

Will die if the range sections are malformed.

Will return an array of two elements: the object itself and the next offset.

METHODS

contains

Return the vendor id bit status (if enable or not) from one of the range sections.

Will return false if id is bigger than max vendor id.

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

max_id

Returns the max vendor id.

all

Returns an arrayref 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 present or not in all ranges sections.

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 present on the ranges section.