root/branches/streaming-rework/src/libavc/avc_serialize.cpp

Revision 365, 3.5 kB (checked in by wagi, 17 years ago)

src/libfreebobavc/serialize* moved to src/libfreebob/avc_serialize*, all includes adapted
src/bebob/bebob_serialize* moved to src/libutil/serialize*
src/libutil/serialize: use Glib::ustring instead of std::string.
src/configrom: serialize and deserialize added (not finished)
src/devicemanager: load and save cached functionality added (not finished)

various small whitespace updates (emacs lässt grüssen :))

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* avc_serialize.cpp
2  * Copyright (C) 2005,07 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 "avc_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 StringSerializer::write( byte_t d, const char* name )
49 {
50     char* result;
51     asprintf( &result, "  %3d:\t0x%02x\t%s\n", m_cnt, d, name );
52
53     m_string += result;
54     free( result );
55
56     m_cnt += sizeof( byte_t );
57
58     return true;
59 }
60
61 bool
62 StringSerializer::write( quadlet_t d, const char* name )
63 {
64     char* result;
65     asprintf( &result, "  %3d:\t0x%08x\t%s\n", m_cnt, d, name );
66
67     m_string += result;
68     free( result );
69
70     m_cnt += sizeof( quadlet_t );
71     return true;
72 }
73
74 //////////////////////////////////////////////////
75
76 bool
77 BufferSerialize::write( byte_t value, const char* name )
78 {
79     bool result = false;
80     if ( isCurPosValid() ) {
81         *m_curPos = value;
82         m_curPos += sizeof( byte_t );
83         result = true;
84     }
85     return result;
86 }
87
88 bool
89 BufferSerialize::write( quadlet_t value,  const char* name )
90 {
91     bool result = false;
92     if ( isCurPosValid() ) {
93         * ( quadlet_t* )m_curPos = value;
94         m_curPos += sizeof( quadlet_t );
95         result = true;
96     }
97     return result;
98 }
99
100 bool
101 BufferSerialize::isCurPosValid() const
102 {
103     if ( static_cast<size_t>( ( m_curPos - m_buffer ) ) >= m_length ) {
104         return false;
105     }
106     return true;
107 }
108
109 //////////////////////////////////////////////////
110
111 bool
112 BufferDeserialize::read( byte_t* value )
113 {
114     bool result = false;
115     if ( isCurPosValid() ) {
116         *value = *m_curPos;
117         m_curPos += sizeof( byte_t );
118         result = true;
119     }
120     return result;
121 }
122
123 bool
124 BufferDeserialize::read( quadlet_t* value )
125 {
126     bool result = false;
127     if ( isCurPosValid() ) {
128         *value = *( ( quadlet_t* )m_curPos );
129         m_curPos += sizeof( quadlet_t );
130         result = true;
131     }
132     return result;
133 }
134
135 bool
136 BufferDeserialize::read( char** value, size_t length )
137 {
138     bool result = false;
139     if ( isCurPosValid() ) {
140         *value = ( char* )m_curPos;
141         m_curPos += length;
142         result = true;
143     }
144     return result;
145 }
146
147 bool
148 BufferDeserialize::peek( byte_t* value )
149 {
150     bool result = false;
151     if ( isCurPosValid() ) {
152         *value = *m_curPos;
153         result = true;
154     }
155     return result;
156 }
157
158 bool
159 BufferDeserialize::isCurPosValid() const
160 {
161     if ( static_cast<size_t>( ( m_curPos - m_buffer ) ) >= m_length ) {
162         return false;
163     }
164     return true;
165 }
166
Note: See TracBrowser for help on using the browser.