Net::OBEX::Response::Generic - interpret OBEX protocol generic response packets
use strict; use warnings; use Net::OBEX::Response::Generic; my $res = Net::OBEX::Response::Generic->new; # read 3 bytes of the packet from the socket there somewhere # now parse it: my $response_ref = $res->parse_info( $data_from_the_socket ); if ( $response_ref->{headers_length} ) { # ok, looks like we got some headers in this packet # read $response_ref->{headers_length} bytes from the socket # here and parse the headers. } # OMG SO COMPLICATED!! # Why not use Net::OBEX::Response parse_sock() method instead?
WARNING!!! this module is still in early alpha stage. It is recommended that you use it only for testing.
This module is used internally by Net::OBEX::Response and that's what you probably should be using. The module provides means to interpret raw OBEX protocol responses. For parsing Connect responses see Net::OBEX::Response::Connect
Connect
my $res = Net::OBEX::Response::Generic->new;
Takes no arguments, returns a freshly baked Net::OBEX::Response::Generic object ready to be used and abused.
$res->packet( $data_from_wire ); my $generic_response = $res->parse_info; # or my $generic_response = $res->parse_info( $data_from_wire );
Takes one optional argument which is the raw data from the wire representing the packet. If called without arguments will use the data which you set via packet() method (see below) Returns a hashref with the following keys/values:
packet()
Sample return (descriptions are below):
$VAR1 = { 'packet_length' => 3, 'response_code' => 200, 'headers_length' => 0, 'response_code_meaning' => 'OK, Success' };
{ 'packet_length' => 3 }
The packet_length key will contain the length of the packet in bytes.
packet_length
{ 'headers_length' => 24 }
The headers_length key will contain the length of packet's headers in bytes. You would use this value to finish reading the entire packet from the socket, however, see the parse_sock() method described below.
headers_length
parse_sock()
{ 'response_code' => 200 }
The response_code key will contain a response code, this will pretty much be HTTP response codes since that what OBEX prefers to use.
response_code
{ 'response_code_meaning' => 'OK, Success' }
The response_code_meaning key will contain a human parseable explanation of response_code.
response_code_meaning
my ( $http_code, $meaning ) = $res->code_meaning( "\xA0" );
Takes one argument which is the byte representing the response code. Returns a list of two elements, the first one is the HTTP code of the response (such as 404) the second element is the human parseable meaning of the code (such as Not Found).
404
Not Found
my $old_packet = $res->packet; $res->packet( $new_data_from_the_wire );
Returns a currently set data of the packet. When called with an optional argument will set the current data to parse to whatever you specify in the argument.
my $info_ref = $res->info;
Must be called after a call to parse_info(). Takes no arguments, returns a hashref which is the same as the return value of the last call to parse_info() method. See the description of parse_info() method above for more information.
parse_info()
my $length_of_packet_headers = $res->headers_length;
Must be called after a call to parse_info(). Takes no arguments, returns the length of packet headers in bytes (this is what you still need to read from the socket to get a complete packet). Note: this is the same as the contents of headers_length key of the parse_info() return.
Net::OBEX::Packet::Headers, Net::OBEX::Response, Net::OBEX::Response::Connect
Fork this module on GitHub: https://github.com/zoffixznet/Net-OBEX
To report bugs or request features, please use https://github.com/zoffixznet/Net-OBEX/issues
If you can't access GitHub, you can email your request to bug-Net-OBEX at rt.cpan.org
bug-Net-OBEX at rt.cpan.org
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.
LICENSE
To install Net::OBEX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::OBEX
CPAN shell
perl -MCPAN -e shell install Net::OBEX
For more information on module installation, please visit the detailed CPAN module installation guide.