Marshaller.cpp 1.55 KB
Newer Older
1
2
3
4
5
6
#include "castor/tape/aggregator/Marshaller.hpp"

#include <arpa/inet.h>
#include <string.h>


7
8
9
10
11
12
13
14
15
16
17
18
19
20
//------------------------------------------------------------------------------
// marshallUint32
//------------------------------------------------------------------------------
char* castor::tape::aggregator::Marshaller::marshallUint32(char *const ptr,
  uint32_t value) throw() {

  value = htonl(value);

  memcpy(ptr, &value, sizeof(value));

  return ptr + sizeof(value);
}


21
22
23
24
25
26
27
28
29
30
31
32
//------------------------------------------------------------------------------
// marshallString
//------------------------------------------------------------------------------
char* castor::tape::aggregator::Marshaller::marshallString(char *const ptr,
  const char *const value) throw() {

  strcpy(ptr, value);

  return ptr + strlen(value) + 1;
}


33
34
35
36
37
38
39
40
41
42
43
44
//------------------------------------------------------------------------------
// marshallString
//------------------------------------------------------------------------------
char* castor::tape::aggregator::Marshaller::marshallString(char *const ptr,
  const std::string value) throw() {

  strcpy(ptr, value.c_str());

  return ptr + strlen(value.c_str()) + 1;
}


45
46
47
48
49
50
//------------------------------------------------------------------------------
// unmarshallInt32
//------------------------------------------------------------------------------
char* castor::tape::aggregator::Marshaller::unmarshallUint32(char *const ptr,
  uint32_t &value) throw() {

51
52
  memcpy(&value, ptr, sizeof(value));
  value = ntohl(value);
53
54
55

  return ptr + sizeof(value);
}