LCOV - code coverage report
Current view: top level - include - Encoder.h (source / functions) Hit Total Coverage
Test: cpp-bencoding code coverage Lines: 1 1 100.0 %
Date: 2018-04-21 15:28:44 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /**
       2             : * @file      Encoder.h
       3             : * @copyright (c) 2014 by Petr Zemek (s3rvac@gmail.com) and contributors
       4             : * @license   BSD, see the @c LICENSE file for more details
       5             : * @brief     Data encoder.
       6             : */
       7             : 
       8             : #ifndef BENCODING_ENCODER_H
       9             : #define BENCODING_ENCODER_H
      10             : 
      11             : #include <memory>
      12             : #include <string>
      13             : 
      14             : #include "BItemVisitor.h"
      15             : 
      16             : namespace bencoding {
      17             : 
      18             : class BItem;
      19             : 
      20             : /**
      21             : * @brief Data encoder.
      22             : *
      23             : * The format is based on the <a
      24             : * href="https://wiki.theory.org/BitTorrentSpecification#Bencoding">BitTorrent
      25             : * specification</a>.
      26             : *
      27             : * Use create() to create instances.
      28             : */
      29          24 : class Encoder: private BItemVisitor {
      30             : public:
      31             :     static std::unique_ptr<Encoder> create();
      32             : 
      33             :     std::string encode(std::shared_ptr<BItem> data);
      34             : 
      35             : private:
      36             :     Encoder();
      37             : 
      38             :     /// @name BItemVisitor Interface
      39             :     /// @{
      40             :     virtual void visit(BDictionary *bDictionary) override;
      41             :     virtual void visit(BInteger *bInteger) override;
      42             :     virtual void visit(BList *bList) override;
      43             :     virtual void visit(BString *bString) override;
      44             :     /// @}
      45             : 
      46             : private:
      47             :     /// Encoded items.
      48             :     std::string encodedData;
      49             : };
      50             : 
      51             : /// @name Encoding Without Explicit Encoder Creation
      52             : /// @{
      53             : std::string encode(std::shared_ptr<BItem> data);
      54             : /// @}
      55             : 
      56             : } // namespace bencoding
      57             : 
      58             : #endif

Generated by: LCOV version 1.13