"Fossies" - the Fresh Open Source Software Archive

Member "tcpflow-1.6.1/src/be13_api/sbuf_stream.cpp" (19 Feb 2021, 4484 Bytes) of package /linux/misc/tcpflow-1.6.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "sbuf_stream.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.4.5_vs_1.5.0.

    1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #include "config.h"
    3 #include "bulk_extractor_i.h"
    4 #include "sbuf_stream.h"
    5 
    6 /*
    7  * Stream interfaces
    8  */
    9 sbuf_stream::sbuf_stream(const sbuf_t &sbuf_): sbuf(sbuf_),offset(0) {
   10 }
   11 
   12 sbuf_stream::~sbuf_stream() {
   13 }
   14 
   15 void sbuf_stream::seek(size_t offset_) {
   16   offset = offset_;
   17 }
   18 
   19 size_t sbuf_stream::tell() {
   20   return offset;
   21 }
   22 
   23 /*
   24  * unsigned integers, default little endian
   25  */
   26 uint8_t sbuf_stream::get8u() {
   27     uint8_t value = sbuf.get8u(offset);
   28     offset++;
   29     return value;
   30 }
   31 uint16_t sbuf_stream::get16u() {
   32     uint16_t value = sbuf.get16u(offset);
   33     offset+=2;
   34     return value;
   35 }
   36 uint32_t sbuf_stream::get32u() {
   37     uint32_t value = sbuf.get32u(offset);
   38     offset+=4;
   39     return value;
   40 }
   41 uint64_t sbuf_stream::get64u() {
   42     uint64_t value = sbuf.get64u(offset);
   43     offset+=8;
   44     return value;
   45 }
   46 
   47 /*
   48  * unsigned integers, big endian
   49  */
   50 uint8_t sbuf_stream::get8uBE() {
   51     uint8_t value = sbuf.get8uBE(offset);
   52     offset++;
   53     return value;
   54 }
   55 uint16_t sbuf_stream::get16uBE() {
   56     uint16_t value = sbuf.get16uBE(offset);
   57     offset+=2;
   58     return value;
   59 }
   60 uint32_t sbuf_stream::get32uBE() {
   61     uint32_t value = sbuf.get32uBE(offset);
   62     offset+=4;
   63     return value;
   64 }
   65 uint64_t sbuf_stream::get64uBE() {
   66     uint64_t value = sbuf.get64uBE(offset);
   67     offset+=8;
   68     return value;
   69 }
   70 
   71 /*
   72  * unsigned integers, byte order specified
   73  */
   74 uint8_t sbuf_stream::get8u(sbuf_t::byte_order_t bo) {
   75     uint8_t value = sbuf.get8u(offset, bo);
   76     offset++;
   77     return value;
   78 }
   79 uint16_t sbuf_stream::get16u(sbuf_t::byte_order_t bo) {
   80     uint16_t value = sbuf.get16u(offset, bo);
   81     offset+=2;
   82     return value;
   83 }
   84 uint32_t sbuf_stream::get32u(sbuf_t::byte_order_t bo) {
   85     uint32_t value = sbuf.get32u(offset, bo);
   86     offset+=4;
   87     return value;
   88 }
   89 uint64_t sbuf_stream::get64u(sbuf_t::byte_order_t bo) {
   90     uint64_t value = sbuf.get64u(offset, bo);
   91     offset+=8;
   92     return value;
   93 }
   94 
   95 /*
   96  * signed integers, default little endian
   97  */
   98 int8_t sbuf_stream::get8i() {
   99     int8_t value = sbuf.get8i(offset);
  100     offset++;
  101     return value;
  102 }
  103 int16_t sbuf_stream::get16i() {
  104     int16_t value = sbuf.get16i(offset);
  105     offset+=2;
  106     return value;
  107 }
  108 int32_t sbuf_stream::get32i() {
  109     int32_t value = sbuf.get32i(offset);
  110     offset+=4;
  111     return value;
  112 }
  113 int64_t sbuf_stream::get64i() {
  114     int64_t value = sbuf.get64i(offset);
  115     offset+=8;
  116     return value;
  117 }
  118 
  119 /*
  120  * signed integers, big endian
  121  */
  122 int8_t sbuf_stream::get8iBE() {
  123     int8_t value = sbuf.get8iBE(offset);
  124     offset++;
  125     return value;
  126 }
  127 int16_t sbuf_stream::get16iBE() {
  128     int16_t value = sbuf.get16iBE(offset);
  129     offset+=2;
  130     return value;
  131 }
  132 int32_t sbuf_stream::get32iBE() {
  133     int32_t value = sbuf.get32iBE(offset);
  134     offset+=4;
  135     return value;
  136 }
  137 int64_t sbuf_stream::get64iBE() {
  138     int64_t value = sbuf.get64iBE(offset);
  139     offset+=8;
  140     return value;
  141 }
  142 
  143 /*
  144  * signed integers, byte order specified
  145  */
  146 int8_t sbuf_stream::get8i(sbuf_t::byte_order_t bo) {
  147     uint8_t value = sbuf.get8i(offset, bo);
  148     offset++;
  149     return value;
  150 }
  151 int16_t sbuf_stream::get16i(sbuf_t::byte_order_t bo) {
  152     uint16_t value = sbuf.get16i(offset, bo);
  153     offset+=2;
  154     return value;
  155 }
  156 int32_t sbuf_stream::get32i(sbuf_t::byte_order_t bo) {
  157     uint32_t value = sbuf.get32i(offset, bo);
  158     offset+=4;
  159     return value;
  160 }
  161 int64_t sbuf_stream::get64i(sbuf_t::byte_order_t bo) {
  162     uint64_t value = sbuf.get64i(offset, bo);
  163     offset+=8;
  164     return value;
  165 }
  166 
  167 /*
  168  * string readers
  169  */
  170 void sbuf_stream::getUTF8(size_t num_octets_requested, string &utf8_string) {
  171     sbuf.getUTF8(num_octets_requested, utf8_string);
  172     offset += utf8_string.length();
  173     return;
  174 }
  175 void sbuf_stream::getUTF8(string &utf8_string) {
  176     sbuf.getUTF8(offset, utf8_string);
  177     size_t num_bytes = utf8_string.length();
  178     if (num_bytes > 0) {
  179         // if anything was read then also skip \0
  180         num_bytes ++;
  181     }
  182     offset += num_bytes;
  183     return;
  184 }
  185 
  186 void sbuf_stream::getUTF16(size_t code_units_requested, wstring &utf16_string) {
  187     sbuf.getUTF16(offset, code_units_requested, utf16_string);
  188     offset += utf16_string.length() * 2;
  189     return;
  190 }
  191 void sbuf_stream::getUTF16(wstring &utf16_string) {
  192     sbuf.getUTF16(offset, utf16_string);
  193     size_t num_bytes = utf16_string.length() * 2;
  194     if (num_bytes > 0) {
  195         // if anything was read then also skip \U0000
  196         num_bytes += 2;
  197     }
  198     offset += num_bytes;
  199     return;
  200 }
  201 
  202