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

Revision 439, 3.6 kB (checked in by pieterpalmers, 16 years ago)

- some work on the AVC mixer & control stuff

  • 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 IMPL_DEBUG_MODULE( CoutSerializer, CoutSerializer, DEBUG_LEVEL_NORMAL );
29
30 bool
31 CoutSerializer::write( byte_t d, const char* name )
32 {
33     debugOutput( DEBUG_LEVEL_NORMAL, "  %3d:\t0x%02x\t%s\n", m_cnt, d, name );
34     m_cnt += sizeof( byte_t );
35
36     return true;
37 }
38
39 bool
40 CoutSerializer::write( quadlet_t d, const char* name )
41 {
42     debugOutput( DEBUG_LEVEL_NORMAL, "  %3d:\t0x%08x\t%s\n", m_cnt, d, name );
43     m_cnt += sizeof( quadlet_t );
44     return true;
45 }
46
47 //////////////////////////////////////////////////
48
49 bool
50 StringSerializer::write( byte_t d, const char* name )
51 {
52     char* result;
53     asprintf( &result, "  %3d:\t0x%02x\t%s\n", m_cnt, d, name );
54
55     m_string += result;
56     free( result );
57
58     m_cnt += sizeof( byte_t );
59
60     return true;
61 }
62
63 bool
64 StringSerializer::write( quadlet_t d, const char* name )
65 {
66     char* result;
67     asprintf( &result, "  %3d:\t0x%08x\t%s\n", m_cnt, d, name );
68
69     m_string += result;
70     free( result );
71
72     m_cnt += sizeof( quadlet_t );
73     return true;
74 }
75
76 //////////////////////////////////////////////////
77
78 bool
79 BufferSerialize::write( byte_t value, const char* name )
80 {
81     bool result = false;
82     if ( isCurPosValid() ) {
83         *m_curPos = value;
84         m_curPos += sizeof( byte_t );
85         result = true;
86     }
87     return result;
88 }
89
90 bool
91 BufferSerialize::write( quadlet_t value,  const char* name )
92 {
93     bool result = false;
94     if ( isCurPosValid() ) {
95         * ( quadlet_t* )m_curPos = value;
96         m_curPos += sizeof( quadlet_t );
97         result = true;
98     }
99     return result;
100 }
101
102 bool
103 BufferSerialize::isCurPosValid() const
104 {
105     if ( static_cast<size_t>( ( m_curPos - m_buffer ) ) >= m_length ) {
106         return false;
107     }
108     return true;
109 }
110
111 //////////////////////////////////////////////////
112
113 bool
114 BufferDeserialize::read( byte_t* value )
115 {
116     bool result = false;
117     if ( isCurPosValid() ) {
118         *value = *m_curPos;
119         m_curPos += sizeof( byte_t );
120         result = true;
121     }
122     return result;
123 }
124
125 bool
126 BufferDeserialize::read( quadlet_t* value )
127 {
128     bool result = false;
129     if ( isCurPosValid() ) {
130         *value = *( ( quadlet_t* )m_curPos );
131         m_curPos += sizeof( quadlet_t );
132         result = true;
133     }
134     return result;
135 }
136
137 bool
138 BufferDeserialize::read( char** value, size_t length )
139 {
140     bool result = false;
141     if ( isCurPosValid() ) {
142         *value = ( char* )m_curPos;
143         m_curPos += length;
144         result = true;
145     }
146     return result;
147 }
148
149 bool
150 BufferDeserialize::peek( byte_t* value )
151 {
152     bool result = false;
153     if ( isCurPosValid() ) {
154         *value = *m_curPos;
155         result = true;
156     }
157     return result;
158 }
159
160 bool
161 BufferDeserialize::isCurPosValid() const
162 {
163     if ( static_cast<size_t>( ( m_curPos - m_buffer ) ) >= m_length ) {
164         return false;
165     }
166     return true;
167 }
168
Note: See TracBrowser for help on using the browser.