Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <sys/types.h>
00020 #include <iostream>
00021 #include <stdio.h>
00022
00023 #ifndef _SDNV_H_
00024 #define _SDNV_H_
00025
00044 namespace dtn
00045 {
00046 namespace data
00047 {
00048 class SDNV
00049 {
00050 public:
00055 static const size_t MAX_LENGTH = 10;
00056
00061 SDNV(const u_int64_t value);
00062
00066 SDNV();
00067
00072 size_t getLength() const;
00073
00074 static size_t getLength(const u_int64_t &value);
00075 static size_t getLength(const unsigned char *data);
00076
00081 u_int64_t getValue() const;
00082
00089 size_t decode(const char *data, const size_t len);
00090
00097 size_t encode(char *data, const size_t len) const;
00098
00099 size_t operator=(const size_t &value);
00100
00101 bool operator==(const SDNV &value) const;
00102 bool operator!=(const SDNV &value) const;
00103
00104 SDNV operator+(const SDNV &value);
00105 SDNV& operator+=(const SDNV &value);
00106
00107 SDNV operator-(const SDNV &value);
00108 SDNV& operator-=(const SDNV &value);
00109
00110 bool operator&(const size_t &value) const;
00111
00112 private:
00113 friend std::ostream &operator<<(std::ostream &stream, const dtn::data::SDNV &obj);
00114 friend std::istream &operator>>(std::istream &stream, dtn::data::SDNV &obj);
00115
00116
00117 inline static size_t encoding_len(u_int16_t val){ return encoding_len((u_int64_t)val); }
00118 inline static size_t encoding_len(u_int32_t val){ return encoding_len((u_int64_t)val); }
00119 inline static int encode(u_int16_t val, char* bp, size_t len){ return encode((u_int64_t)val, (u_char*)bp, len); }
00120 inline static int encode(u_int32_t val, char* bp, size_t len){ return encode((u_int64_t)val, (u_char*)bp, len); }
00121 inline static int encode(u_int64_t val, char* bp, size_t len){ return encode(val, (u_char*)bp, len); }
00122 inline static int encode(float val, char* bp, size_t len){ return encode(val, (u_char*)bp, len); }
00123 inline static int decode(char* bp, size_t len, u_int64_t* val){ return decode((u_char*)bp, len, val); }
00124 inline static int decode(char* bp, size_t len, u_int32_t* val){ return decode((u_char*)bp, len, val); }
00125
00126 static size_t encoding_len(u_int64_t val);
00127 static size_t encoding_len(float val_f);
00128 static int encode(u_int64_t val, u_char* bp, size_t len);
00129 static int encode(float val_f, u_char* bp, size_t len);
00130 static int decode(const u_char* bp, size_t len, float* val_f);
00131 static int decode(const u_char* bp, size_t len, u_int64_t* val);
00132 static int decode(const u_char* bp, size_t len, u_int32_t* val);
00133 static int decode(const u_char* bp, size_t len, u_int16_t* val);
00134 static size_t len(const u_char* bp);
00135
00136 u_int64_t _value;
00137 };
00138 }
00139 }
00140
00141 #endif