NAME

Protocol::IR::Format::CSV - IRDB CSV importer and exporter

VERSION

version 1.1

SYNOPSIS

use Protocol::IR::Converter;

my $converter = Protocol::IR::Converter->new();

# Parse an IRDB-style CSV string
my $csv = "functionname,protocol,device,subdevice,function\n"
        . "KEY_POWER,NEC1,4,0,8\n";
my $codes = $converter->import_format('CSV', $csv);

for my $code (@$codes) {
    print $code->alias . "\n";
    print $converter->export_code($code, 'Pronto') . "\n";
}

# Or load from a file path
my $codes = $converter->import_format('CSV', 'remote.csv');

DESCRIPTION

Protocol::IR::Format::CSV imports and exports IRDB-style CSV button listings as Protocol::IR::Code objects. It accepts either a CSV string or the path to a CSV file.

Example IRDB CSV (Samsung TV, NECx2 variant)
functionname,protocol,device,subdevice,function
POWER,NECx2,7,7,2
1,NECx2,7,7,4
2,NECx2,7,7,5

This is the delimited Remotec ZXT-120 style CSV used by the IRDB project (https://github.com/probonopd/irdb).

Column headers are detected automatically. Recognized header aliases:

  • functionname, function_name, key, alias, label, name -- button name (stored on the alias accessor)

  • protocol, proto -- protocol name

  • device, address, addr, dev -- device (address)

  • subdevice, subaddress, subaddr, subdev -- subdevice

  • function, command, cmd, code -- command

  • data, hex, raw -- a raw value for the protocol

A row is decoded either from a raw data value or, when no data column is present, from the device/subdevice/command columns. Protocol aliases such as NEC1 and nec are normalized to NEC; the IRDB NEC-family variants NEC2, NECx1, and NECx2 are kept as-is, so the variant identity survives the conversion. Each decoded code gets its alias set from the button name column.

METHODS

decode

my $codes = $class->decode($input, $registry);

Parses a CSV string or file and returns an arrayref of Protocol::IR::Code objects. Rows with an unregistered or unrecognized protocol are skipped.

export

my $csv = $class->export($codes, $registry);

Serializes a Protocol::IR::Code or an arrayref of codes as canonical IRDB CSV: a functionname,protocol,device,subdevice,function header followed by one row per code. A code with no addressable decoded fields (an UNKNOWN protocol) is skipped. Button names are quoted - with embedded quotes doubled - when they contain a comma, double quote, or newline. Round-tripping through decode reproduces the decoded fields.

SUPPORT

Source code: https://github.com/bwarden/perl-protocol-ir

Bug reports and feature requests: https://github.com/bwarden/perl-protocol-ir/issues

AUTHOR

Brett T. Warden <bwarden@cpan.org>

COPYRIGHT AND LICENSE

Copyright (c) 2026 Brett T. Warden

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.