logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

DIME::Payload - implementation of a payload of a DIME message

Author

       Domingo Alcazar Larrea, <dalcazar@cpan.org>

Chunked And Dynamic Content

       To create a chunked message you have to specify the Chunked key:

               # This create a dynamic payload with records of 16384 bytes

               my $payload = DIME::Payload->new();
               $payload->attach(Path => 'bigfile.avi',
                                Chunked => 16384,
                                Dynamic => 1);

               # You can encode all the payload at once:

               my $dime_encoded_message = ${$payload->print_data()};

               # Or, if you prefer, you can generate each chunk

               my $ret;
               do
               {
                       $chunk = ${$payload->print_chunk_data()};
               } while ($chunk ne '');

       The Dynamic key is used to avoid load all the file in memory. What DIME::Payload does is to open the file
       and, when it need more content, read from the file. If you don't set the Dynamic key, all the data is
       loaded in memory.

Content Type

       To specify the type of content of a Payload, you should use the MIMEType and URIType keys:

               # MIME media-type
               my $payload = DIME::Payload->new();
               $payload->attach(Path => 'image.jpg',
                                MIMEType => 'image/jpeg');

               # absolute URI
               my $payload = DIME::Payload->new();
               $payload->attach(Path => 'message.xml',
                                URIType => 'http://schemas.xmlsoap.org/soap/envelope/');

Description

       DIME::Payload represents the content of DIME message. A message is composed of one or many Payload
       objects.

       There are two types of DIME payloads: chunked and not chunked. A DIME message that isn't chunked has only
       one record with all the Payload content. A chunked message is splited in several records, allowing to
       sender and receiver process the content without know the total size of this.

Name

       DIME::Payload - implementation of a payload of a DIME message

Payload Identifier

       When you create a new Payload, a unique identifier is generated automatically. You can get/set it with
       the id() method:

               my $payload = DIME::Payload->new();
               print $payload->id();

Synopsis

         # Create a standard DIME message from an existing file
         # and a string

         use DIME::Payload;

         $payload1 = DIME::Payload->new();
         $payload1->attach(Path => 'existingfile.jpg',
                           MIMEType => 'image/jpeg',
                           Dynamic => 1);

         $payload2 = DIME::Payload->new();
         my $data = 'Hello World!!!';
         $payload2->attach(Data => \$data,
                           MIMEType => 'text/plain');

         my $message = DIME::Message->new();
         $message->add_payload($payload1);
         $message->add_payload($payload2);

See Also