root/trunk/libffado/src/libavc/util/avc_serialize.h

Revision 503, 4.7 kB (checked in by ppalmers, 17 years ago)

- put all libavc stuff into it's own name namespace (AVC)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #ifndef SERIALIZE_H
25 #define SERIALIZE_H
26
27 #include "debugmodule/debugmodule.h"
28
29 #include <libraw1394/raw1394.h> // byte_t and quadlet_t declaration
30 #include <string>
31
32 namespace AVC {
33
34 // Interfaces
35
36 class IOSSerialize {
37 public:
38     IOSSerialize() {}
39     virtual ~IOSSerialize() {}
40
41     virtual bool write( byte_t value, const char* name = "" ) = 0;
42     virtual bool write( uint16_t value, const char* name = "" ) = 0;
43     virtual bool write( quadlet_t value, const char* name = "" ) = 0;
44     virtual bool write( const char *values, size_t len, const char* name = "" ) = 0;
45 };
46
47 class IISDeserialize {
48 public:
49     IISDeserialize() {}
50     virtual ~IISDeserialize() {}
51
52     virtual bool read( byte_t* value ) = 0;
53     virtual bool read( uint16_t* value ) = 0;
54     virtual bool read( quadlet_t* value ) = 0;
55     virtual bool read( char** value, size_t length ) = 0;
56     virtual bool peek( byte_t* value ) = 0;
57     virtual bool peek( uint16_t* value, size_t offset )=0;
58     virtual bool skip( size_t length ) = 0;
59     virtual int getNrOfConsumedBytes()  const = 0;
60 };
61
62 // Specialized implementations of previously defined interfaces
63
64 class CoutSerializer: public IOSSerialize {
65 public:
66     CoutSerializer()
67         : IOSSerialize()
68         , m_cnt( 0 )
69         {}
70     virtual ~CoutSerializer() {}
71
72     virtual bool write( byte_t value, const char* name = "" );
73     virtual bool write( uint16_t value, const char* name = "" );
74     virtual bool write( quadlet_t value,  const char* name = "" );
75     virtual bool write( const char *values, size_t len, const char* name = "" );
76
77 private:
78     unsigned int m_cnt;
79     DECLARE_DEBUG_MODULE;
80
81 };
82
83 class StringSerializer: public IOSSerialize {
84 public:
85     StringSerializer()
86         : IOSSerialize()
87         , m_cnt( 0 )
88         {}
89     virtual ~StringSerializer() {}
90
91     virtual bool write( byte_t value, const char* name = "" );
92     virtual bool write( uint16_t value, const char* name = "" );
93     virtual bool write( quadlet_t value,  const char* name = "" );
94     virtual bool write( const char *values, size_t len, const char* name = "" );
95     virtual std::string getString( ) { return m_string;};
96
97 private:
98     unsigned int m_cnt;
99     std::string m_string;
100     DECLARE_DEBUG_MODULE;
101 };
102
103 class BufferSerialize: public IOSSerialize {
104 public:
105     BufferSerialize( unsigned char* buffer, size_t length )
106         : IOSSerialize()
107         , m_buffer( buffer )
108         , m_curPos( m_buffer )
109         , m_length( length )
110         {}
111     virtual ~BufferSerialize() {}
112
113     virtual bool write( byte_t value, const char* name = "" );
114     virtual bool write( uint16_t value, const char* name = "" );
115     virtual bool write( quadlet_t value,  const char* name = "" );
116     virtual bool write( const char *values, size_t len, const char* name = "" );
117
118     int getNrOfProducesBytes() const
119     { return m_curPos - m_buffer; }
120
121 protected:
122     inline bool isCurPosValid() const;
123
124 private:
125     unsigned char* m_buffer;
126     unsigned char* m_curPos;
127     size_t m_length;
128     DECLARE_DEBUG_MODULE;
129 };
130
131 class BufferDeserialize: public IISDeserialize {
132 public:
133     BufferDeserialize( const unsigned char* buffer, size_t length )
134         : IISDeserialize()
135         , m_buffer( const_cast<unsigned char*>( buffer ) )
136         , m_curPos( m_buffer )
137         , m_length( length )
138         {}
139     virtual ~BufferDeserialize() {}
140
141     virtual bool read( byte_t* value );
142     virtual bool read( uint16_t* value );
143     virtual bool read( quadlet_t* value );
144     virtual bool read( char** value, size_t length );
145     virtual bool peek( byte_t* value );
146     virtual bool peek( uint16_t* value, size_t offset );
147     virtual bool skip( size_t length );
148
149     int getNrOfConsumedBytes()  const
150         { return m_curPos - m_buffer; }
151
152 protected:
153     inline bool isCurPosValid() const;
154
155 private:
156     unsigned char* m_buffer; // start of the buffer
157     unsigned char* m_curPos; // current read pos
158     size_t m_length;         // size of buffer
159     DECLARE_DEBUG_MODULE;
160 };
161
162 }
163 #endif // SERIALIZE_H
164
Note: See TracBrowser for help on using the browser.