1 #ifndef _framing_FieldValue_h
2 #define _framing_FieldValue_h
70 virtual uint32_t encodedSize()
const = 0;
80 virtual void print(std::ostream& out)
const = 0;
89 bool empty()
const {
return data.get() == 0; }
97 template <
typename T>
bool convertsTo()
const {
return false; }
100 template <
class T,
int W> T getIntegerValue()
const;
101 template <
class T> T getIntegerValue()
const;
102 template <
class T,
int W> T getFloatingPointValue()
const;
103 template <
int W>
void getFixedWidthValue(
unsigned char*)
const;
104 template <
class T>
bool get(T&)
const;
113 std::auto_ptr<Data> data;
118 inline bool FieldValue::convertsTo<int>()
const {
return data->convertsToInt(); }
121 inline bool FieldValue::convertsTo<int64_t>()
const {
return data->convertsToInt(); }
124 inline bool FieldValue::convertsTo<std::string>()
const {
return data->convertsToString(); }
127 inline int FieldValue::get<int>()
const {
return static_cast<int>(data->getInt()); }
130 inline int64_t FieldValue::get<int64_t>()
const {
return data->getInt(); }
133 inline std::string FieldValue::get<std::string>()
const {
return data->getString(); }
149 for (
int i = 0; i < width; i++) octets[i] = data[i];
153 for (
int i = width; i > 1; --i) {
154 octets[i-1] = (
uint8_t) (0xFF & v); v >>= 8;
156 octets[0] = (
uint8_t) (0xFF & v);
163 if (rhs == 0)
return false;
164 else return std::equal(&octets[0], &octets[width], &rhs->octets[0]);
171 for (
int i = 0; i < width-1; ++i) {
172 v |= octets[i]; v <<= 8;
174 v |= octets[width-1];
180 void print(std::ostream& o)
const { o <<
"F" << width <<
":"; };
186 UuidData(
const unsigned char* bytes);
191 template <
class T,
int W>
198 for (
int i = 0; i < W-1; ++i) {
199 v |= octets[i]; v <<= 8;
216 throw InvalidConversionException();
220 template <
class T,
int W>
227 for (
size_t i = 0; i < W; ++i) target[i] = octets[i];
238 for (
size_t i = 0; i < W; ++i) value[i] = fwv->
rawOctets()[i];
245 inline float FieldValue::get<float>()
const {
246 return getFloatingPointValue<float, 4>();
250 inline double FieldValue::get<double>()
const {
251 return getFloatingPointValue<double, 8>();
265 void print(std::ostream& o)
const { o <<
"F0"; };
268 template <
int lenw
idth>
270 std::vector<uint8_t> octets;
278 buffer.
putUInt<lenwidth>(octets.size());
279 if (octets.size() > 0)
290 if (rhs == 0)
return false;
291 else return octets==rhs->octets;
295 std::string
getString()
const {
return std::string(octets.begin(), octets.end()); }
297 void print(std::ostream& o)
const { o <<
"V" << lenwidth <<
":" << octets.size() <<
":"; };
314 value.encode(buffer);
317 value.decode(buffer);
321 if (rhs == 0)
return false;
322 else return value==rhs->value;
325 void print(std::ostream& o)
const { o <<
"[" << value <<
"]"; };