MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
bitfields.h
Go to the documentation of this file.
1 #include <string>
2 
3 namespace Util{
4  bool stringToBool(std::string & str);
5 }
6 
7 namespace Bit{
8  //bitfield getters
9  unsigned long long getMSB(char * pointer, unsigned int offsetBits, unsigned int dataBits);
10  unsigned long long getByName(char * pointer);
11  //bitfield setters
12  void setMSB(char * pointer, unsigned int offsetBits, unsigned int dataBits, unsigned long long value);
13  void setByName(char * pointer);
14 
15  //Host to binary/binary to host functions - similar to kernel ntoh/hton functions.
16 
18  inline unsigned short btohs(char * p) {
19  return ((unsigned short)p[0] << 8) | p[1];
20  }
21 
23  inline void htobs(char * p, unsigned short val) {
24  p[0] = (val >> 8) & 0xFF;
25  p[1] = val & 0xFF;
26  }
27 
29  inline unsigned long btohl(const char * p) {
30  return ((unsigned long)p[0] << 24) | ((unsigned long)p[1] << 16) | ((unsigned long)p[2] << 8) | p[3];
31  }
32 
34  inline void htobl(char * p, unsigned long val) {
35  p[0] = (val >> 24) & 0xFF;
36  p[1] = (val >> 16) & 0xFF;
37  p[2] = (val >> 8) & 0xFF;
38  p[3] = val & 0xFF;
39  }
40 
42  inline unsigned long btoh24(char * p) {
43  return ((unsigned long)p[0] << 16) | ((unsigned long)p[1] << 8) | p[2];
44  }
45 
47  inline void htob24(char * p, unsigned long val) {
48  p[0] = (val >> 16) & 0xFF;
49  p[1] = (val >> 8) & 0xFF;
50  p[2] = val & 0xFF;
51  }
52 
54  inline unsigned long long btohll(char * p) {
55  return ((unsigned long long)p[0] << 56) | ((unsigned long long)p[1] << 48) | ((unsigned long long)p[2] << 40) | ((unsigned long long)p[3] << 32) | ((unsigned long)p[4] << 24) | ((unsigned long)p[5] << 16) | ((unsigned long)p[6] << 8) | p[7];
56  }
57 
59  inline void htobll(char * p, unsigned long long val) {
60  p[0] = (val >> 56) & 0xFF;
61  p[1] = (val >> 48) & 0xFF;
62  p[2] = (val >> 40) & 0xFF;
63  p[3] = (val >> 32) & 0xFF;
64  p[4] = (val >> 24) & 0xFF;
65  p[5] = (val >> 16) & 0xFF;
66  p[6] = (val >> 8) & 0xFF;
67  p[7] = val & 0xFF;
68  }
69 
70 }
71 
bool stringToBool(std::string &str)
Parses a string reference to a boolean.
Definition: bitfields.cpp:69
void setByName(char *pointer)
void htobl(char *p, unsigned long val)
Stores a long value of val in network order to the pointer p.
Definition: bitfields.h:34
unsigned long btohl(const char *p)
Retrieves a long in network order from the pointer p.
Definition: bitfields.h:29
unsigned short btohs(char *p)
Retrieves a short in network order from the pointer p.
Definition: bitfields.h:18
void htob24(char *p, unsigned long val)
Stores a long value of val in network order to the pointer p.
Definition: bitfields.h:47
Contains utility code, not directly related to streaming media.
Definition: bitfields.h:3
Definition: bitfields.h:7
void htobll(char *p, unsigned long long val)
Stores a long value of val in network order to the pointer p.
Definition: bitfields.h:59
unsigned long long getByName(char *pointer)
unsigned long long btohll(char *p)
Retrieves a long long in network order from the pointer p.
Definition: bitfields.h:54
unsigned long btoh24(char *p)
Retrieves a long in network order from the pointer p.
Definition: bitfields.h:42
void htobs(char *p, unsigned short val)
Stores a short value of val in network order to the pointer p.
Definition: bitfields.h:23
void setMSB(char *pointer, unsigned int offsetBits, unsigned int dataBits, unsigned long long value)
Takes a pointer, offset bitcount and data bitcount, setting to given value.
Definition: bitfields.cpp:39
unsigned long long getMSB(char *pointer, unsigned int offsetBits, unsigned int dataBits)
Takes a pointer, offset bitcount and data bitcount, returning the unsigned int read from the givens...
Definition: bitfields.cpp:8