NAME
DOCSIS::ConfigFile::Encode - Encode functions for a DOCSIS config-file.
SYNOPSIS
@uchar = snmp_object({
value => { oid => $str, type => $str, value => $str },
});
@uchar = bigint({ value => $bigint });
@uchar = int({ value => $int });
@uchar = uint({ value => $uint });
@uchar = ushort({ value => $ushort });
@uchar = uchar({ value => $char });
@uchar = vendorspec({
value => '0x001337', # vendors ID
nested => [
{
type => $int, # vendor specific type
value => $int, # vendor specific value
},
],
});
@uchar = ip({ value => '1.2.3.4' });
@uchar = ether({ value => '0x0123456789abcdef' });
@uchar = ether({ value => $uint });
@uchar = string({ value => '0x0123456789abcdef' });
@uchar = string({ value => 'string containing percent: %25' });
@uchar = hexstr({ value => '0x0123456789abcdef' });
() = mic({ value => $any });
DESCRIPTION
This module has functions which is used to encode "human" data into list of unsigned characters (0-255) (refered to as "bytes") later in the pod. This list can then be encoded into binary data using:
$bytestr = pack 'C*', @uchar;
FUNCTIONS
snmp_object
This function encodes a human-readable SNMP oid into a list of bytes:
@bytes = (
#-type---length---------value-----type---
0x30, $total_length, # object
0x06, int(@oid), @oid, # oid
$type, int(@value), @value, # value
);
bigint
Returns a list of bytes representing the $bigint
. This can be any number (negative or positive) which can be representing using 64 bits.
int
Returns a list of bytes representing the $int
. This can be any number (negative or positive) which can be representing using 32 bits.
uint
Returns a list of bytes representing the $uint
. This can be any positive number which can be representing using 32 bits.
ushort
Returns a list of bytes representing the $ushort
. This can be any positive number which can be representing using 16 bits.
uchar
Returns a list with one byte representing the $uchar
. This can be any positive number which can be representing using 8 bits.
vendorspec
Will byte-encode a complex vendorspec datastructure.
ip
Returns a list of four bytes representing the $ip
. The $ip
must be in in the format "1.2.3.4".
ether
This function use either "uint" or "hexstr" to encode the input value. It will figure out the function to use by checking the input for either integer value or a string looking like a hex-string.
objectid
Encodes MIB number as value of OBJECTID
can be in format: 1.2.3.4, .1.2.3.4
string
Returns a list of bytes representing the $str
. Will use "hexstr" to decode it if it looks like a hex string (a string starting with leading "0x"). In other cases, it will decode it itself. The input string might also be encoded with a simple uri-encode format: "%20" will be translated to a space, and "%25" will be translated into "%", before encoded using ord()
.
stringz
Returns a list of bytes representing the $str
with a zero terminator at the end. The "\0" byte will be added unless seen as the last element in the list.
Only ServiceClassName needs this, see DOCSIS::ConfigFile::Syminfo for more details.
hexstr
Will encode any hex encoded string into a list of bytes. The string can have an optional leading "0x".
mic
Cannot encode CM/CMTS mic without complete information about the config file, so this function returns an empty list.
no_value
This method will return an empty list. It is used by DOCSIS types, which has zero length.
vendor
Will byte-encode a complex vendorspec datastructure.
AUTHOR
Jan Henning Thorsen - jhthorsen@cpan.org