IBR-DTNSuite  0.8
ibrdtn/ibrdtn/data/CompressedPayloadBlock.h
Go to the documentation of this file.
00001 /*
00002  * CompressedPayloadBlock.h
00003  *
00004  *  Created on: 20.04.2011
00005  *      Author: morgenro
00006  */
00007 
00008 #include <ibrdtn/data/Block.h>
00009 #include <ibrdtn/data/SDNV.h>
00010 #include <ibrdtn/data/ExtensionBlock.h>
00011 #include "ibrdtn/data/Bundle.h"
00012 
00013 #ifndef COMPRESSEDPAYLOADBLOCK_H_
00014 #define COMPRESSEDPAYLOADBLOCK_H_
00015 
00016 namespace dtn
00017 {
00018         namespace data
00019         {
00020                 class CompressedPayloadBlock : public dtn::data::Block
00021                 {
00022                 public:
00023                         class Factory : public dtn::data::ExtensionBlock::Factory
00024                         {
00025                         public:
00026                                 Factory() : dtn::data::ExtensionBlock::Factory(CompressedPayloadBlock::BLOCK_TYPE) {};
00027                                 virtual ~Factory() {};
00028                                 virtual dtn::data::Block* create();
00029                         };
00030 
00031                         static const char BLOCK_TYPE = 202;
00032 
00033                         enum COMPRESS_ALGS
00034                         {
00035                                 COMPRESSION_UNKNOWN = 0,
00036                                 COMPRESSION_ZLIB = 1,
00037                                 COMPRESSION_BZ2 = 2
00038                         };
00039 
00040                         CompressedPayloadBlock();
00041                         virtual ~CompressedPayloadBlock();
00042 
00043                         virtual size_t getLength() const;
00044                         virtual std::ostream &serialize(std::ostream &stream, size_t &length) const;
00045                         virtual std::istream &deserialize(std::istream &stream, const size_t length);
00046 
00047                         void setAlgorithm(COMPRESS_ALGS alg);
00048                         COMPRESS_ALGS getAlgorithm() const;
00049 
00050                         void setOriginSize(size_t s);
00051                         size_t getOriginSize() const;
00052 
00053                         static void compress(dtn::data::Bundle &b, COMPRESS_ALGS alg);
00054                         static void extract(dtn::data::Bundle &b);
00055 
00056                 private:
00057                         static void compress(CompressedPayloadBlock::COMPRESS_ALGS alg, std::istream &is, std::ostream &os);
00058                         static void extract(CompressedPayloadBlock::COMPRESS_ALGS alg, std::istream &is, std::ostream &os);
00059 
00060                         dtn::data::SDNV _algorithm;
00061                         dtn::data::SDNV _origin_size;
00062                 };
00063 
00067                 static CompressedPayloadBlock::Factory __CompressedPayloadBlockFactory__;
00068         }
00069 }
00070 
00071 #endif /* COMPRESSEDPAYLOADBLOCK_H_ */