root/branches/libfreebob-1.0/src/libfreebobavc/serialize.cpp

Revision 241, 2.9 kB (checked in by pieterpalmers, 18 years ago)

* configure.ac: Version bump to 1.0.0

* Changed all FreeBob? to FreeBoB
* Removed all .cvsignore
* Added Pieter to AUTHORS
* Updated NEWS and README (release canditate date added)

by Daniel Wagner

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* serialize.cpp
2  * Copyright (C) 2005 by Daniel Wagner
3  *
4  * This file is part of FreeBoB.
5  *
6  * FreeBoB is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * FreeBoB 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with FreeBoB; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA.
19  */
20
21 #include "serialize.h"
22
23 #include <iostream>
24 #include <iomanip>
25
26 #include <netinet/in.h>
27
28 bool
29 CoutSerializer::write( byte_t d, const char* name )
30 {
31     printf( "  %3d:\t0x%02x\t%s\n", m_cnt, d, name );
32     m_cnt += sizeof( byte_t );
33
34     return true;
35 }
36
37 bool
38 CoutSerializer::write( quadlet_t d, const char* name )
39 {
40     printf( "  %3d:\t0x%08x\t%s\n", m_cnt, d, name );
41     m_cnt += sizeof( quadlet_t );
42     return true;
43 }
44
45 //////////////////////////////////////////////////
46
47 bool
48 BufferSerialize::write( byte_t value, const char* name )
49 {
50     bool result = false;
51     if ( isCurPosValid() ) {
52         *m_curPos = value;
53         m_curPos += sizeof( byte_t );
54         result = true;
55     }
56     return result;
57 }
58
59 bool
60 BufferSerialize::write( quadlet_t value,  const char* name )
61 {
62     bool result = false;
63     if ( isCurPosValid() ) {
64         * ( quadlet_t* )m_curPos = value;
65         m_curPos += sizeof( quadlet_t );
66         result = true;
67     }
68     return result;
69 }
70
71 bool
72 BufferSerialize::isCurPosValid() const
73 {
74     if ( static_cast<size_t>( ( m_curPos - m_buffer ) ) >= m_length ) {
75         return false;
76     }
77     return true;
78 }
79
80 //////////////////////////////////////////////////
81
82 bool
83 BufferDeserialize::read( byte_t* value )
84 {
85     bool result = false;
86     if ( isCurPosValid() ) {
87         *value = *m_curPos;
88         m_curPos += sizeof( byte_t );
89         result = true;
90     }
91     return result;
92 }
93
94 bool
95 BufferDeserialize::read( quadlet_t* value )
96 {
97     bool result = false;
98     if ( isCurPosValid() ) {
99         *value = *m_curPos;
100         m_curPos += sizeof( quadlet_t );
101         result = true;
102     }
103     return result;
104 }
105
106 bool
107 BufferDeserialize::read( char** value, size_t length )
108 {
109     bool result = false;
110     if ( isCurPosValid() ) {
111         *value = ( char* )m_curPos;
112         m_curPos += length;
113         result = true;
114     }
115     return result;
116 }
117
118 bool
119 BufferDeserialize::peek( byte_t* value )
120 {
121     bool result = false;
122     if ( isCurPosValid() ) {
123         *value = *m_curPos;
124         result = true;
125     }
126     return result;
127 }
128
129 bool
130 BufferDeserialize::isCurPosValid() const
131 {
132     if ( static_cast<size_t>( ( m_curPos - m_buffer ) ) >= m_length ) {
133         return false;
134     }
135     return true;
136 }
137
Note: See TracBrowser for help on using the browser.