Marshaller.cpp 24 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/******************************************************************************
 *                      Marshaller.cpp
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *
 *
 *
 * @author Steven Murray Steven.Murray@cern.ch
 *****************************************************************************/

26
#include "castor/exception/Internal.hpp"
27
#include "castor/tape/aggregator/Marshaller.hpp"
28
29
#include "h/rtcp_constants.h"
#include "h/vdqm_constants.h"
30
31

#include <arpa/inet.h>
32
33
#include <errno.h>
#include <iostream>
34
35
36
#include <string.h>


37
38
39
40
41
42
//------------------------------------------------------------------------------
// marshallUint8
//------------------------------------------------------------------------------
void castor::tape::aggregator::Marshaller::marshallUint8(uint8_t src,
  char * &dst) throw (castor::exception::Exception) {

43
44
  marshall(src, dst);
}
45
46


47
48
49
50
51
//------------------------------------------------------------------------------
// unmarshallUint8
//------------------------------------------------------------------------------
void castor::tape::aggregator::Marshaller::unmarshallUint8(const char * &src,
  size_t &srcLen, uint8_t &dst) throw(castor::exception::Exception) {
52

53
  unmarshall(src, srcLen, dst);
54
55
56
57
58
59
60
61
62
}


//------------------------------------------------------------------------------
// marshallUint16
//------------------------------------------------------------------------------
void castor::tape::aggregator::Marshaller::marshallUint16(uint16_t src,
  char * &dst) throw (castor::exception::Exception) {

63
  src = htons(src);
64
65
  marshall(src, dst);
}
66
67


68
69
70
71
72
//------------------------------------------------------------------------------
// unmarshallUint16
//------------------------------------------------------------------------------
void castor::tape::aggregator::Marshaller::unmarshallUint16(const char * &src,
  size_t &srcLen, uint16_t &dst) throw(castor::exception::Exception) {
73

74
  unmarshall(src, srcLen, dst);
75
  dst = ntohs(dst);
76
77
78
}


79
80
81
//------------------------------------------------------------------------------
// marshallUint32
//------------------------------------------------------------------------------
82
83
void castor::tape::aggregator::Marshaller::marshallUint32(uint32_t src,
  char * &dst) throw (castor::exception::Exception) {
84

85
  src = htonl(src);
86
  marshall(src, dst);
87
88
89
}


90
//------------------------------------------------------------------------------
91
// unmarshallUint32
92
//------------------------------------------------------------------------------
93
void castor::tape::aggregator::Marshaller::unmarshallUint32(const char * &src,
94
95
  size_t &srcLen, uint32_t &dst) throw(castor::exception::Exception) {

96
  unmarshall(src, srcLen, dst);
97
  dst = ntohl(dst);
98
99
100
}


101
102
103
//------------------------------------------------------------------------------
// marshallString
//------------------------------------------------------------------------------
104
105
106
107
108
109
void castor::tape::aggregator::Marshaller::marshallString(const char * src,
  char * &dst) throw(castor::exception::Exception) {

  if(dst == NULL) {
    castor::exception::Exception ex(EINVAL);

110
111
    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Pointer to destination buffer is NULL";
112
113
    throw ex;
  }
114

115
  strcpy(dst, src);
116

117
  dst += strlen(src) + 1;
118
119
120
}


121
//------------------------------------------------------------------------------
122
// marshallString
123
//------------------------------------------------------------------------------
124
125
126
127
128
void castor::tape::aggregator::Marshaller::marshallString(
  const std::string &src, char * &dst) throw(castor::exception::Exception) {

  if(dst == NULL) {
    castor::exception::Exception ex(EINVAL);
129

130
131
    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Pointer to destination buffer is NULL";
132
133
    throw ex;
  }
134

135
136
137
138
139
140
141
142
143
  strcpy(dst, src.c_str());

  dst += strlen(src.c_str()) + 1;
}


//------------------------------------------------------------------------------
// unmarshallString
//------------------------------------------------------------------------------
144
void castor::tape::aggregator::Marshaller::unmarshallString(const char * &src,
145
146
147
148
149
150
  size_t &srcLen, char *dst, const size_t dstLen)
  throw (castor::exception::Exception) {

  if(src == NULL) {
    castor::exception::Exception ex(EINVAL);

151
152
    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Pointer to source buffer is NULL";
153
154
155
156
157
158
    throw ex;
  }

  if(srcLen == 0) {
    castor::exception::Exception ex(EINVAL);

159
160
    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Source buffer length is 0";
161
162
163
164
165
166
    throw ex;
  }

  if(dst == NULL) {
    castor::exception::Exception ex(EINVAL);

167
168
    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Pointer to destination buffer is NULL";
169
170
171
172
173
174
    throw ex;
  }

  if(dstLen == 0) {
    castor::exception::Exception ex(EINVAL);

175
176
    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Destination buffer length is 0";
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
    throw ex;
  }

  // Calculate the maximum number of bytes that could be unmarshalled
  size_t maxlen = 0;
  if(srcLen < dstLen) {
    maxlen = srcLen;
  } else {
    maxlen = dstLen;
  }

  bool strTerminatorReached = false;

  // While there are potential bytes to copy and the string terminator has not
  // been reached
  for(size_t i=0; i<maxlen && !strTerminatorReached; i++) {
    // If the string terminator has been reached
    if((*dst++ = *src++) == '\0') {
      strTerminatorReached = true;
    }

    srcLen--;
  }

  // If all potential bytes were copied but the string terminator was not
  // reached
  if(!strTerminatorReached) {
    castor::exception::Exception ex(EINVAL);

206
207
    ex.getMessage() << __PRETTY_FUNCTION__
      << ": String terminator of source buffer was not reached";
208
209
    throw ex;
  }
210
}
211
212
213


//-----------------------------------------------------------------------------
214
// marshallMessageHeader
215
//-----------------------------------------------------------------------------
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
size_t castor::tape::aggregator::Marshaller::marshallMessageHeader(
  char *const dst, const size_t dstLen, const MessageHeader &src)
  throw(castor::exception::Exception) {

  if(dst == NULL) {
    castor::exception::Exception ex(EINVAL);

    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Pointer to destination buffer is NULL";
    throw ex;
  }

  // Calculate the length of the message header
  const uint32_t totalLen = 3 * sizeof(uint32_t);  // magic + reqtype + len

  // Check that the message header buffer is big enough
  if(totalLen > dstLen) {
    castor::exception::Exception ex(EMSGSIZE);

    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Buffer too small for message header: "
      "Required size: " << totalLen << " Actual size: " << dstLen;

    throw ex;
  }

  // Marshall the message header
  char *p = dst;
  marshallUint32(src.magic  , p);
  marshallUint32(src.reqtype, p);
  marshallUint32(src.len    , p);

  // Calculate the number of bytes actually marshalled
  const size_t nbBytesMarshalled = p - dst;

  // Check that the number of bytes marshalled was what was expected
  if(totalLen != nbBytesMarshalled) {
    castor::exception::Internal ie;

    ie.getMessage() << __PRETTY_FUNCTION__
      << ": Mismatch between the expected total length of the "
         "message header and the actual number of bytes marshalled"
         ": Expected: " << totalLen
      << ": Marshalled: " << nbBytesMarshalled;

    throw ie;
  }

  return totalLen;
}


//-----------------------------------------------------------------------------
// unmarshallMessageHeader
//-----------------------------------------------------------------------------
void castor::tape::aggregator::Marshaller::unmarshallMessageHeader(
  const char * &src, size_t &srcLen, MessageHeader &dst)
  throw(castor::exception::Exception) {

  unmarshallUint32(src, srcLen, dst.magic);
  unmarshallUint32(src, srcLen, dst.reqtype);
  unmarshallUint32(src, srcLen, dst.len);
}


//-----------------------------------------------------------------------------
// marshallRcpJobRequestMessage
//-----------------------------------------------------------------------------
size_t castor::tape::aggregator::Marshaller::marshallRcpJobRequestMessage(
  char *const dst, const size_t dstLen, const RcpJobRequestMessage &src)
286
287
288
289
290
  throw (castor::exception::Exception) {

  if(dst == NULL) {
    castor::exception::Exception ex(EINVAL);

291
292
    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Pointer to destination buffer is NULL";
293
294
295
296
297
    throw ex;
  }

  // Calculate the length of the message body
  const uint32_t len =
298
299
300
301
302
    4*sizeof(uint32_t)          +
    strlen(src.clientHost)      +
    strlen(src.deviceGroupName) +
    strlen(src.driveName)       +
    strlen(src.clientUserName)  +
303
304
305
306
307
308
309
    4; // 4 = the number of string termination characters

  // Calculate the total length of the message (header + body)
  // Message header = magic + reqtype + len = 3 * sizeof(uint32_t)
  const size_t totalLen = 3 * sizeof(uint32_t) + len;

  // Check that the message buffer is big enough
310
  if(totalLen > dstLen) {
311
312
    castor::exception::Exception ex(EMSGSIZE);

313
    ex.getMessage() << __PRETTY_FUNCTION__
314
315
316
      << ": Buffer too small for job submission request message"
         ": Required size: " << totalLen
      << ": Actual size: " << dstLen;
317
318
319
320
321
322

    throw ex;
  }

  // Marshall the whole message (header + body)
  char *p = dst;
323
324
325
326
327
328
329
330
331
332
333
  marshallUint32(RTCOPY_MAGIC_OLD0  , p);
  marshallUint32(VDQM_CLIENTINFO    , p);
  marshallUint32(len                , p);
  marshallUint32(src.tapeRequestID  , p);
  marshallUint32(src.clientPort     , p);
  marshallUint32(src.clientEuid     , p);
  marshallUint32(src.clientEgid     , p);
  marshallString(src.clientHost     , p);
  marshallString(src.deviceGroupName, p);
  marshallString(src.driveName      , p);
  marshallString(src.clientUserName , p);
334
335
336
337
338
339
340
341

  // Calculate the number of bytes actually marshalled
  const size_t nbBytesMarshalled = p - dst;

  // Check that the number of bytes marshalled was what was expected
  if(totalLen != nbBytesMarshalled) {
    castor::exception::Internal ie;

342
343
    ie.getMessage() << __PRETTY_FUNCTION__
      << ": Mismatch between the expected total length of the "
344
345
346
347
         "RCP job submission request message and the actual number of bytes "
         "marshalled"
         ": Expected: " << totalLen
      << ": Marshalled: " << nbBytesMarshalled;
348
349
350
351
352
353
354
355

    throw ie;
  }

  return totalLen;
}


356
//-----------------------------------------------------------------------------
357
// unmarshallRcpJobRequestMessage
358
//-----------------------------------------------------------------------------
359
360
void castor::tape::aggregator::Marshaller::unmarshallRcpJobRequestMessage(
  const char * &src, size_t &srcLen, RcpJobRequestMessage &dst)
361
362
363
364
365
366
  throw(castor::exception::Exception) {

  unmarshallUint32(src, srcLen, dst.tapeRequestID);
  unmarshallUint32(src, srcLen, dst.clientPort);
  unmarshallUint32(src, srcLen, dst.clientEuid);
  unmarshallUint32(src, srcLen, dst.clientEgid);
367
368
369
370
  unmarshallString(src, srcLen, dst.clientHost);
  unmarshallString(src, srcLen, dst.deviceGroupName);
  unmarshallString(src, srcLen, dst.driveName);
  unmarshallString(src, srcLen, dst.clientUserName);
371
372
373
}


374
//-----------------------------------------------------------------------------
375
// marshallRcpJobReplyMessage
376
//-----------------------------------------------------------------------------
377
378
size_t castor::tape::aggregator::Marshaller::marshallRcpJobReplyMessage(
  char *const dst, const size_t dstLen, const RcpJobReplyMessage &src)
379
380
  throw(castor::exception::Exception) {

381
382
383
  if(dst == NULL) {
    castor::exception::Exception ex(EINVAL);

384
385
    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Pointer to destination buffer is NULL";
386
387
388
389
    throw ex;
  }

  // Minimum buffer length = magic number + request type + length + status code
390
391
392
  // + terminating null character
  const size_t minimumLen = 4*sizeof(uint32_t) + 1;
  if(dstLen < minimumLen) {
393
394
    castor::exception::Exception ex(EINVAL);

395
    ex.getMessage() << __PRETTY_FUNCTION__
396
397
398
      << ": Destination buffer length is too small"
         ": Expected minimum: " << minimumLen
      << ": Actual: " << dstLen;
399
400
401
    throw ex;
  }

402
403
404
405
406
407
408
409
  // Calculate the length of the error message to be sent taking into account
  // the fact that the error message should be right trimmed if it is too large
  // to fit in the destination buffer.
  const size_t headerLen = 3 * sizeof(uint32_t); // magic + reqtype + len
  // free space = total - header - status - terminating null character
  const size_t freeSpace = dstLen - headerLen - sizeof(uint32_t) - 1;
  const size_t errLenToSend = strlen(src.errorMessage) < freeSpace ?
    strlen(src.errorMessage) : freeSpace;
410

411
412
413
  // Calculate the length of the message body
  // Message body = status + error message + terminating null character
  const uint32_t len = sizeof(src.status) + errLenToSend + 1;
414

415
416
  // Calculate the total length of the message (header + body)
  const size_t totalLen = headerLen + len;
417

418
419
420
421
  char *p = dst;
  marshallUint32(RTCOPY_MAGIC_OLD0, p); // Magic number
  marshallUint32(VDQM_CLIENTINFO  , p); // Request type
  marshallUint32(len              , p); // Length
422
  marshallUint32(src.status       , p); // status code
423

424
425
426
  strncpy(p, src.errorMessage, errLenToSend);
  *(p+errLenToSend) = '0';
  p = p + errLenToSend + 1;
427

428
429
430
431
432
433
434
  // Calculate the number of bytes actually marshalled
  const size_t nbBytesMarshalled = p - dst;

  // Check that the number of bytes marshalled was what was expected
  if(totalLen != nbBytesMarshalled) {
    castor::exception::Internal ie;

435
436
    ie.getMessage() << __PRETTY_FUNCTION__
      << ": Mismatch between the expected total length of the "
437
438
439
         "RCP job reply message and the actual number of bytes marshalled"
         ": Expected: " << totalLen
      << ": Marshalled: " << nbBytesMarshalled;
440
441
442
443
444

    throw ie;
  }

  return totalLen;
445
446
447
448
}


//-----------------------------------------------------------------------------
449
// unmarshallRcpJobReplyMessage
450
//-----------------------------------------------------------------------------
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
void castor::tape::aggregator::Marshaller::unmarshallRcpJobReplyMessage(
  const char * &src, size_t &srcLen, RcpJobReplyMessage &dst)
  throw(castor::exception::Exception) {

  // Unmarshall the status number
  Marshaller::unmarshallUint32(src, srcLen, dst.status);

  // The error message will be right trimmed if it is too large
  const size_t maxBytesToUnmarshall = srcLen < sizeof(dst.errorMessage) ?
    srcLen : sizeof(dst.errorMessage);

  // Unmarshall the error message
  if(maxBytesToUnmarshall > 0) {
    strncpy(dst.errorMessage, src, maxBytesToUnmarshall);
    dst.errorMessage[maxBytesToUnmarshall - 1] = '\0';
    src    = src + strlen(dst.errorMessage) + 1;
    srcLen = srcLen - strlen(dst.errorMessage) - 1;
  } else {
    dst.errorMessage[0] = '\0';
    // No need to update src or srcLen
  }
}


//-----------------------------------------------------------------------------
// marshallRtcpTapeRequestMessage
//-----------------------------------------------------------------------------
size_t castor::tape::aggregator::Marshaller::marshallRtcpTapeRequestMessage(
  char *dst, const size_t dstLen, const RtcpTapeRequestMessage &src)
480
481
482
  throw (castor::exception::Exception) {

  // Calculate the length of the message body
483
484
485
486
487
488
489
490
491
492
493
494
  const uint32_t len =
    14 * sizeof(uint32_t)     +
    strlen(src.vid)           +
    strlen(src.vsn)           +
    strlen(src.label)         +
    strlen(src.devtype)       +
    strlen(src.density)       +
    strlen(src.unit)          +
    sizeof(Cuuid_t)           +
    4 * sizeof(uint32_t)      + // 4 uint32_t's of err member (rtcpErrMsg_t)
    strlen(src.err.errmsgtxt) +
    7;                          // 7 = number of null terminator characters
495

496
  // Calculate the total length of the message (header + body)
497
498
499
500
  // Message header = magic + reqtype + len = 3 * sizeof(uint32_t)
  const size_t totalLen = 3 * sizeof(uint32_t) + len;

  // Check that the message buffer is big enough
501
  if(totalLen > dstLen) {
502
503
    castor::exception::Exception ex(EMSGSIZE);

504
505
    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Buffer too small for tape request message: "
506
507
508
509
510
      "Required size: " << totalLen << " Actual size: " << dstLen;

    throw ex;
  }

511
  // Marshall the whole message (header + body)
512
  char *p = dst;
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
  marshallUint32(RTCOPY_MAGIC                          , p);
  marshallUint32(RTCP_TAPEERR_REQ                      , p);
  marshallUint32(len                                   , p);
  marshallString(src.vid                               , p);
  marshallString(src.vsn                               , p);
  marshallString(src.label                             , p);
  marshallString(src.devtype                           , p);
  marshallString(src.density                           , p);
  marshallString(src.unit                              , p);
  marshallUint32(src.VolReqID                          , p);
  marshallUint32(src.jobID                             , p);
  marshallUint32(src.mode                              , p);
  marshallUint32(src.start_file                        , p);
  marshallUint32(src.end_file                          , p);
  marshallUint32(src.side                              , p);
  marshallUint32(src.tprc                              , p);
  marshallUint32(src.TStartRequest                     , p);
  marshallUint32(src.TEndRequest                       , p);
  marshallUint32(src.TStartRtcpd                       , p);
  marshallUint32(src.TStartMount                       , p);
  marshallUint32(src.TEndMount                         , p);
  marshallUint32(src.TStartUnmount                     , p);
  marshallUint32(src.TEndUnmount                       , p);
  marshallUint32(src.rtcpReqId.time_low                , p);
  marshallUint16(src.rtcpReqId.time_mid                , p);
  marshallUint16(src.rtcpReqId.time_hi_and_version     , p);
  marshallUint8(src.rtcpReqId.clock_seq_hi_and_reserved, p);
  marshallUint8(src.rtcpReqId.clock_seq_low            , p);
  marshallUint8(src.rtcpReqId.node[0]                  , p);
  marshallUint8(src.rtcpReqId.node[1]                  , p);
  marshallUint8(src.rtcpReqId.node[2]                  , p);
  marshallUint8(src.rtcpReqId.node[3]                  , p);
  marshallUint8(src.rtcpReqId.node[4]                  , p);
  marshallUint8(src.rtcpReqId.node[5]                  , p);
  marshallString(src.err.errmsgtxt                     , p);
  marshallUint32(src.err.severity                      , p);
  marshallUint32(src.err.errorcode                     , p);
  marshallUint32(src.err.max_tpretry                   , p);
  marshallUint32(src.err.max_cpretry                   , p);
552

553
554
555
556
557
558
559
  // Calculate the number of bytes actually marshalled
  const size_t nbBytesMarshalled = p - dst;

  // Check that the number of bytes marshalled was what was expected
  if(totalLen != nbBytesMarshalled) {
    castor::exception::Internal ie;

560
561
    ie.getMessage() << __PRETTY_FUNCTION__
      << ": Mismatch between the expected total length of the "
562
563
564
         "RTCP tape request message and the actual number of bytes marshalled"
         ": Expected: " << totalLen
      << ": Marshalled: " << nbBytesMarshalled;
565
566
567
568

    throw ie;
  }

569
570
  return totalLen;
}
571
572
573


//-----------------------------------------------------------------------------
574
// unmarshallRtcpTapeRequestMessage
575
//-----------------------------------------------------------------------------
576
577
void castor::tape::aggregator::Marshaller::unmarshallRtcpTapeRequestMessage(
  const char * &src, size_t &srcLen, RtcpTapeRequestMessage &dst)
578
579
  throw(castor::exception::Exception) {

580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
  unmarshallString(src, srcLen, dst.vid);
  unmarshallString(src, srcLen, dst.vsn);
  unmarshallString(src, srcLen, dst.label);
  unmarshallString(src, srcLen, dst.devtype);
  unmarshallString(src, srcLen, dst.density);
  unmarshallString(src, srcLen, dst.unit);
  unmarshallUint32(src, srcLen, dst.VolReqID);
  unmarshallUint32(src, srcLen, dst.jobID);
  unmarshallUint32(src, srcLen, dst.mode);
  unmarshallUint32(src, srcLen, dst.start_file);
  unmarshallUint32(src, srcLen, dst.end_file);
  unmarshallUint32(src, srcLen, dst.side);
  unmarshallUint32(src, srcLen, dst.tprc);
  unmarshallUint32(src, srcLen, dst.TStartRequest);
  unmarshallUint32(src, srcLen, dst.TEndRequest);
  unmarshallUint32(src, srcLen, dst.TStartRtcpd);
  unmarshallUint32(src, srcLen, dst.TStartMount);
  unmarshallUint32(src, srcLen, dst.TEndMount);
  unmarshallUint32(src, srcLen, dst.TStartUnmount);
  unmarshallUint32(src, srcLen, dst.TEndUnmount);
  unmarshallUint32(src, srcLen, dst.rtcpReqId.time_low);
  unmarshallUint16(src, srcLen, dst.rtcpReqId.time_mid);
  unmarshallUint16(src, srcLen, dst.rtcpReqId.time_hi_and_version);
  unmarshallUint8(src, srcLen, dst.rtcpReqId.clock_seq_hi_and_reserved);
  unmarshallUint8(src, srcLen, dst.rtcpReqId.clock_seq_low);
  unmarshallUint8(src, srcLen, dst.rtcpReqId.node[0]);
  unmarshallUint8(src, srcLen, dst.rtcpReqId.node[1]);
  unmarshallUint8(src, srcLen, dst.rtcpReqId.node[2]);
  unmarshallUint8(src, srcLen, dst.rtcpReqId.node[3]);
  unmarshallUint8(src, srcLen, dst.rtcpReqId.node[4]);
  unmarshallUint8(src, srcLen, dst.rtcpReqId.node[5]);
  unmarshallString(src, srcLen, dst.err.errmsgtxt);
  unmarshallUint32(src, srcLen, dst.err.severity);
  unmarshallUint32(src, srcLen, dst.err.errorcode);
  unmarshallUint32(src, srcLen, dst.err.max_tpretry);
  unmarshallUint32(src, srcLen, dst.err.max_cpretry);
616
}
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688


//-----------------------------------------------------------------------------
// marshallRtcpAcknowledgeMessage
//-----------------------------------------------------------------------------
size_t castor::tape::aggregator::Marshaller::marshallRtcpAcknowledgeMessage(
  char *const dst, const size_t dstLen, const RtcpAcknowledgeMessage &src)
  throw(castor::exception::Exception) {
  castor::exception::Internal ie;

  if(dst == NULL) {
    castor::exception::Exception ex(EINVAL);

    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Pointer to destination buffer is NULL";
    throw ex;
  }

  // Calculate the total length of the message (there is no separate header and
  // body)
  const uint32_t totalLen = 3 * sizeof(uint32_t); // magic + reqtype + status

  // Check that the message buffer is big enough
  if(totalLen > dstLen) {
    castor::exception::Exception ex(EMSGSIZE);

    ex.getMessage() << __PRETTY_FUNCTION__
      << ": Buffer too small for RTCP acknowledge message"
         ": Required size: " << totalLen
      << ": Actual size: " << dstLen;

    throw ex;
  }

  // Marshall the message
  char *p = dst;
  marshallUint32(src.magic  , p);
  marshallUint32(src.reqtype, p);
  marshallUint32(src.status , p);

  // Calculate the number of bytes actually marshalled
  const size_t nbBytesMarshalled = p - dst;

  // Check that the number of bytes marshalled was what was expected
  if(totalLen != nbBytesMarshalled) {
    castor::exception::Internal ie;

    ie.getMessage() << __PRETTY_FUNCTION__
      << ": Mismatch between the expected total length of the "
         "RTCP acknowledge message and the actual number of bytes "
         "marshalled"
         ": Expected: " << totalLen
      << ": Marshalled: " << nbBytesMarshalled;

    throw ie;
  }

  return totalLen;
}


//-----------------------------------------------------------------------------
// unmarshallRtcpAcknowledgeMessage
//-----------------------------------------------------------------------------
void castor::tape::aggregator::Marshaller::unmarshallRtcpAcknowledgeMessage(
  const char * &src, size_t &srcLen, RtcpAcknowledgeMessage &dst)
  throw(castor::exception::Exception) {

  unmarshallUint32(src, srcLen, dst.magic);
  unmarshallUint32(src, srcLen, dst.reqtype);
  unmarshallUint32(src, srcLen, dst.status);
}