CPN
Computational Process Networks
Main Page
Namespaces
Classes
Files
File List
File Members
lib
PacketDecoder.cc
Go to the documentation of this file.
1
//=============================================================================
2
// Computational Process Networks class library
3
// Copyright (C) 1997-2006 Gregory E. Allen and The University of Texas
4
//
5
// This library is free software; you can redistribute it and/or modify it
6
// under the terms of the GNU Library General Public License as published
7
// by the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
9
//
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// Library General Public License for more details.
14
//
15
// The GNU Public License is available in the file LICENSE, or you
16
// can write to the Free Software Foundation, Inc., 59 Temple Place -
17
// Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
18
// World Wide Web at http://www.fsf.org.
19
//=============================================================================
23
#include "common_priv.h"
24
#include "
PacketDecoder.h
"
25
#include <
cpn/utils/ThrowingAssert.h
>
26
#include <string.h>
27
28
namespace
CPN {
29
30
PacketDecoder::PacketDecoder
()
31
: numbytes(0)
32
{
33
}
34
35
PacketDecoder::~PacketDecoder
() {}
36
37
void
*
PacketDecoder::GetDecoderBytes
(
unsigned
&amount) {
38
char
*ptr =
reinterpret_cast<
char
*
>
(&
header
.
header
);
39
amount =
sizeof
(
header
.
header
) -
numbytes
;
40
ASSERT
(amount != 0,
"Zero decoder bytes"
);
41
return
ptr +
numbytes
;
42
}
43
44
void
PacketDecoder::ReleaseDecoderBytes
(
unsigned
amount) {
45
ASSERT
(
numbytes
+ amount <=
sizeof
(
header
.
header
));
46
numbytes
+= amount;
47
if
(
numbytes
==
sizeof
(
header
.
header
)) {
48
if
(
header
.
Valid
()) {
49
FirePacket
(
header
);
50
numbytes
= 0;
51
}
else
{
52
// If it is not valid, what do we do??
53
// Well, we can search for the header word
54
// wont always work...
55
char
*ptr =
reinterpret_cast<
char
*
>
(&
header
.
header
);
56
numbytes
-= 1;
57
memmove(ptr, ptr + 1,
numbytes
);
58
}
59
}
60
}
61
62
void
PacketDecoder::Reset
() {
63
numbytes
= 0;
64
}
65
}
66
CPN::Packet::header
PacketHeader header
Definition:
PacketHeader.h:148
CPN::PacketDecoder::PacketDecoder
PacketDecoder()
Definition:
PacketDecoder.cc:30
ThrowingAssert.h
CPN::PacketDecoder::Reset
void Reset()
Definition:
PacketDecoder.cc:62
CPN::PacketDecoder::header
Packet header
Definition:
PacketDecoder.h:52
CPN::PacketDecoder::ReleaseDecoderBytes
void ReleaseDecoderBytes(unsigned amount)
Definition:
PacketDecoder.cc:44
CPN::PacketDecoder::numbytes
unsigned numbytes
Definition:
PacketDecoder.h:53
PacketDecoder.h
CPN::PacketDecoder::~PacketDecoder
virtual ~PacketDecoder()
Definition:
PacketDecoder.cc:35
CPN::Packet::Valid
bool Valid() const
Definition:
PacketHeader.h:134
CPN::PacketHandler::FirePacket
void FirePacket(const Packet &packet)
Definition:
PacketHeader.cc:31
ASSERT
#define ASSERT(exp,...)
Definition:
ThrowingAssert.h:62
CPN::PacketDecoder::GetDecoderBytes
void * GetDecoderBytes(unsigned &amount)
Definition:
PacketDecoder.cc:37
Generated by
1.8.5