8#include "daq/slc/base/Writer.h"
10#include "daq/slc/base/Serializable.h"
18void Writer::reverse(
void* buf,
size_t len)
20 for (
int c = 0 ; c < (int)len / 2 ; c ++) {
21 char tmp = *((
char*)buf + c);
22 *((
char*)buf + c) = *((
char*)buf + len - 1 - c);
23 *((
char*)buf + len - 1 - c) = tmp;
27void Writer::writeBool(
bool v)
29 write(&v,
sizeof(
bool));
32void Writer::writeChar(
char v)
34 write(&v,
sizeof(
char));
37void Writer::writeUChar(
unsigned char v)
39 write(&v,
sizeof(
unsigned char));
42void Writer::writeShort(
short v)
44#if defined(__ENDIAN_L__)
45 reverse(&v,
sizeof(
short));
47 write(&v,
sizeof(
short));
50void Writer::writeUShort(
unsigned short v)
52#if defined(__ENDIAN_L__)
53 reverse(&v,
sizeof(
unsigned short));
55 write(&v,
sizeof(
unsigned short));
58void Writer::writeInt(
int v)
60#if defined(__ENDIAN_L__)
61 reverse(&v,
sizeof(
int));
63 write(&v,
sizeof(
int));
66void Writer::writeUInt(
unsigned int v)
68#if defined(__ENDIAN_L__)
69 reverse(&v,
sizeof(
unsigned int));
71 write(&v,
sizeof(
unsigned int));
74void Writer::writeLong(
long long v)
76#if defined(__ENDIAN_L__)
77 reverse(&v,
sizeof(
long long));
79 write(&v,
sizeof(
long long));
82void Writer::writeULong(
unsigned long long v)
84#if defined(__ENDIAN_L__)
85 reverse(&v,
sizeof(
unsigned long long));
87 write(&v,
sizeof(
unsigned long long));
90void Writer::writeFloat(
float v)
92#if defined(__ENDIAN_L__)
93 reverse(&v,
sizeof(
float));
95 write(&v,
sizeof(
float));
98void Writer::writeDouble(
double v)
100#if defined(__ENDIAN_L__)
101 reverse(&v,
sizeof(
double));
103 write(&v,
sizeof(
double));
106void Writer::writeString(
const std::string& v)
108 writeInt((
int)v.size());
109 write(v.data(), v.size());
114 return v.writeObject(*
this);
Abstract base class for different kinds of events.