libebml_ng
binary.h
Go to the documentation of this file.
1 #ifndef EBML_NG_BINARY_H
2 #define EBML_NG_BINARY_H
3 
4 #include <string>
5 #include "../struct.h"
6 
7 namespace ebml {
8  DEF_SIZE(std::string) {
9  return value.size();
10  }
11 
12  DEF_PACK(std::string) {
13  if (size < value.size()) {
14  throw std::runtime_error("Size of string too large to fit.");
15  } else if (size > value.size()) {
16  memcpy(dest, value.data(), value.size());
17  dest[value.size()] = 0;
18  return size;
19  }
20  memcpy(dest, value.data(), value.size());
21  return value.size();
22  }
23 
24  DEF_PACK_ALT(std::string) {
25  memcpy(dest, value.data(), value.size());
26  return value.size();
27  }
28 
29  DEF_UNPACK(std::string) {
30  return std::string(src, size);
31  }
32 }
33 
34 #endif
DEF_SIZE(long long)
Definition: ll.h:7
DEF_UNPACK(float)
Definition: double.h:30
size_t size(const std::string &value)
Definition: binary.h:8
Definition: basictypes.h:40
DEF_PACK(long long)
Definition: ll.h:22
DEF_PACK_ALT(float)
Definition: double.h:10