# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright 2024 Raritan Inc. All rights reserved.
#
# This file was generated by IdlC from Net.idl.

use strict;

package Raritan::RPC::net::PortForwardingInfo_3_0_0;

use Raritan::RPC::net::PortForwardingPrimaryUnitAddrInfo;
use Raritan::RPC::net::PortForwardingPrimaryUnitAddrInfo;

sub encode {
    my ($in) = @_;
    my $encoded = {};
    $encoded->{'enabled'} = ($in->{'enabled'}) ? JSON::true : JSON::false;
    $encoded->{'nodeIndexValid'} = ($in->{'nodeIndexValid'}) ? JSON::true : JSON::false;
    $encoded->{'nodeIndex'} = 1 * $in->{'nodeIndex'};
    $encoded->{'expansionUnitConnected'} = ($in->{'expansionUnitConnected'}) ? JSON::true : JSON::false;
    $encoded->{'primaryUnitDownstreamIfName'} = "$in->{'primaryUnitDownstreamIfName'}";
    $encoded->{'primaryUnitIPv4AddrInfos'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'primaryUnitIPv4AddrInfos'}}; $i0++) {
        $encoded->{'primaryUnitIPv4AddrInfos'}->[$i0] = Raritan::RPC::net::PortForwardingPrimaryUnitAddrInfo::encode($in->{'primaryUnitIPv4AddrInfos'}->[$i0]);
    }
    $encoded->{'primaryUnitIPv6AddrInfos'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'primaryUnitIPv6AddrInfos'}}; $i0++) {
        $encoded->{'primaryUnitIPv6AddrInfos'}->[$i0] = Raritan::RPC::net::PortForwardingPrimaryUnitAddrInfo::encode($in->{'primaryUnitIPv6AddrInfos'}->[$i0]);
    }
    $encoded->{'linkLocalIPv6Address'} = "$in->{'linkLocalIPv6Address'}";
    return $encoded;
}

sub decode {
    my ($agent, $in) = @_;
    my $decoded = {};
    $decoded->{'enabled'} = ($in->{'enabled'}) ? 1 : 0;
    $decoded->{'nodeIndexValid'} = ($in->{'nodeIndexValid'}) ? 1 : 0;
    $decoded->{'nodeIndex'} = $in->{'nodeIndex'};
    $decoded->{'expansionUnitConnected'} = ($in->{'expansionUnitConnected'}) ? 1 : 0;
    $decoded->{'primaryUnitDownstreamIfName'} = $in->{'primaryUnitDownstreamIfName'};
    $decoded->{'primaryUnitIPv4AddrInfos'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'primaryUnitIPv4AddrInfos'}}; $i0++) {
        $decoded->{'primaryUnitIPv4AddrInfos'}->[$i0] = Raritan::RPC::net::PortForwardingPrimaryUnitAddrInfo::decode($agent, $in->{'primaryUnitIPv4AddrInfos'}->[$i0]);
    }
    $decoded->{'primaryUnitIPv6AddrInfos'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'primaryUnitIPv6AddrInfos'}}; $i0++) {
        $decoded->{'primaryUnitIPv6AddrInfos'}->[$i0] = Raritan::RPC::net::PortForwardingPrimaryUnitAddrInfo::decode($agent, $in->{'primaryUnitIPv6AddrInfos'}->[$i0]);
    }
    $decoded->{'linkLocalIPv6Address'} = $in->{'linkLocalIPv6Address'};
    return $decoded;
}

1;
