The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Audio::TagLib::ByteVector - A byte vector

SYNOPSIS

  use Audio::TagLib::ByteVector;
  
  my $i = Audio::TagLib::ByteVector->new();
  $i->setData("blah blah blah");
  print $i->data(), "\n"; # got "blah blah blah"

DESCRIPTION

This class provides a byte vector with some methods that are useful for tagging purposes. Many of the search functions are tailored to what is useful for finding tag related paterns in a data array.

new()

Constructs an empty byte vector.

new(UV $size, PV $value = 0)

Construct a vector of size $size with all values set to $value by default.

new(ByteVector $v)

Contructs a byte vector that is a copy of $v.

new(PV $data)

Contructs a byte vector that contains $data if length($data) is 1.

Constructs a byte vector that copies $data up to the first null byte. The behavior is undefined if $data is not null terminated. This is particularly useful for constructing byte arrays from string constants.

new(PV $data, IV $length)

Constructs a byte vector that copies $data for up to $length bytes.

DESTROY()

Destroys this ByteVector instance.

void setData(PV $data, UV $length)

Sets the data for the byte array using the first $length bytes of $data.

void setData(PV $data)

Sets the data for the byte array copies $data up to the first null byte. The behavior is undefined if \a data is not null terminated.

PV data()

Returns a copy to the internal data structure.

ByteVector mid(UV $index, UV $length = 0xffffffff)

Returns a byte vector made up of the bytes starting at $index and for $length bytes. If $length is not specified it will return the bytes from $index to the end of the vector.

PV at(UV $index)

Returns a char at the specific $index. If the index is out of bounds, it will return a null byte.

IV find(ByteVector $pattern, UV $offset = 0, IV $byteAlign = 1)

Searches the ByteVector for $pattern starting at $offset and returns the offset. Returns -1 if the pattern was not found. If $byteAlign is specified the pattern will only be matched if it starts on a byteDivisible by $byteAlign.

IV rfind(ByteVector $pattern, UV $offset = 0, IV $byteAlign = 1)

Searches the ByteVector for $pattern starting from either the end of the vector or $offset and returns the offset. Returns -1 if the pattern was not found. If $byteAlign is specified the pattern will only be matched if it starts on a byteDivisible by $byteAlign.

BOOL containsAt(ByteVector $pattern, UV $offset, UV $patternOffset = 0, UV $patternLength = Oxffffffff)

Checks to see if the vector contains the $pattern starting at position $offset. Optionally, if you only want to search for part of the pattern you can specify an offset within the pattern to start from. Also, you can specify to only check for the first $patternLength bytes of $pattern with the $patternLength argument.

BOOL startsWith(ByteVector $pattern)

Returns true if the vector starts with $pattern.

BOOL endsWith(ByteVector $pattern)

Returns true if the vector ends with $pattern.

IV endsWithPartialMatch(ByteVector $pattern)

Checks for a partial match of $pattern at the end of the vector. It returns the offset of the partial match within the vector, or -1 if the pattern is not found. This method is particularly useful when searching for patterns that start in one vector and end in another. When combined with startsWith() it can be used to find a pattern that overlaps two buffers.

note This will not match the complete pattern at the end of the string; use endsWith() for that.

void append(ByteVector $v)
 Appends $v to the end of the ByteVector.
void clear()

Clears the data.

UV size()

Returns the size of the array.

ByteVector resize(UV $size, PV padding = 0)

Resize the vector to $size. If the vector is currently less than $size, pad the remaining spaces with $padding. Returns a reference to the resized vector.

Iterator begin()

Returns an Iterator that points to the front of the vector.

Iterator end()

Returns an Iterator that points to the back of the vector.

BOOL isNull()

Returns true if the vector is null.

note A vector may be empty without being null.

see isEmpty()

BOOL isEmpty()

Returns true if the ByteVector is empty.

see size() see isNull()

UV checksum()

Returns a CRC checksum of the byte vector's data.

UV toUInt(BOOL $mostSignificantByteFirst = true)

Converts the first 4 bytes of the vector to an unsigned integer.

If $mostSignificantByteFirst is true this will operate left to right evaluating the integer. For example if $mostSignificantByteFirst is true then $00 $00 $00 $01 == 0x00000001 == 1, if false, $01 00 00 00 == 0x01000000 == 1.

see fromUInt()

IV toShort(BOOL $mostSignificantByteFirst = true)

Converts the first 2 bytes of the vector to a short.

If $mostSignificantByteFirst is true this will operate left to right evaluating the integer. For example if $mostSignificantByteFirst is true then $00 $01 == 0x0001 == 1, if false, $01 00 == 0x01000000 == 1.

see fromShort()

IV toLongLong(BOOL $mostSignificantByteFirst = true)

Converts the first 8 bytes of the vector to a (signed) long long.

If $mostSignificantByteFirst is true this will operate left to right evaluating the integer. For example if $mostSignificantByteFirst is true then $00 00 00 00 00 00 00 01 == 0x0000000000000001 == 1, if false, $01 00 00 00 00 00 00 00 == 0x0100000000000000 == 1.

see fromUInt()

ByteVector fromUInt(UV $value, BOOL $mostSignificantByteFirst = true) [static]

Creates a 4 byte ByteVector based on $value. If $mostSignificantByteFirst is true, then this will operate left to right in building the ByteVector. For example if $mostSignificantByteFirst is true then $00 00 00 01 == 0x00000001 == 1, if false, $01 00 00 00 == 0x01000000 == 1.

see toUInt()

ByteVector fromShort(IV $value, BOOL $bool mostSignificantByteFirst = true) [static]

Creates a 2 byte ByteVector based on $value. If $mostSignificantByteFirst is true, then this will operate left to right in building the ByteVector. For example if $mostSignificantByteFirst is true then $00 01 == 0x0001 == 1, if false, $01 00 == 0x0100 == 1.

see toShort()

ByteVector fromLongLong(IV $value, BOOL $mostSignificantByteFirst = true) [static]

Creates a 8 byte ByteVector based on $value. If $mostSignificantByteFirst is true, then this will operate left to right in building the ByteVector. For example if $mostSignificantByteFirst is true then $00 00 00 01 == 0x0000000000000001 == 1, if false, $01 00 00 00 00 00 00 00 == 0x0100000000000000 == 1.

see toLongLong()

ByteVector fromCString(PV $s, UV $length = 0xffffffff) [static]

Returns a ByteVector based on the CString $s.

void setItem(IV $index, PV $c)

Sets the char at $index to $c.

copy(ByteVector $v)

Inplements operator=.

ByteVector null() [static]

Returns the static object Audio::TagLib::ByteVector::null.

OVERLOADED OPERATORS

@{} == eq != ne < lt gt + "">

EXPORT

None by default.

SEE ALSO

Audio::TagLib

AUTHOR

Dongxu Ma, <dongxu@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2005 by Dongxu Ma

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.