2 Generic object-oriented reading/writing.
4 Part of the swftools package.
6 Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program 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
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 #include "../config.h"
30 #ifndef __rfxswf_bitio_h__
31 #define __rfxswf_bitio_h__
33 #define READER_TYPE_FILE 1
34 #define READER_TYPE_MEM 2
35 #define READER_TYPE_ZLIB_U 3
36 #define READER_TYPE_ZLIB_C 4
37 #define READER_TYPE_ZLIB READER_TYPE_ZLIB_U
38 #define READER_TYPE_NULL 5
39 #define READER_TYPE_FILE2 6
40 #define READER_TYPE_ZZIP 7
42 #define WRITER_TYPE_FILE 1
43 #define WRITER_TYPE_MEM 2
44 #define WRITER_TYPE_ZLIB_C 3
45 #define WRITER_TYPE_ZLIB_U 4
46 #define WRITER_TYPE_NULL 5
47 #define WRITER_TYPE_GROWING_MEM 6
48 #define WRITER_TYPE_ZLIB WRITER_TYPE_ZLIB_C
50 typedef struct _reader
52 int (*read
)(struct _reader
*, void*data
, int len
);
53 int (*seek
)(struct _reader
*, int pos
);
54 void (*dealloc
)(struct _reader
*);
63 typedef struct _writer
65 int (*write
)(struct _writer
*, void*data
, int len
);
66 void (*flush
)(struct _writer
*);
67 void (*finish
)(struct _writer
*);
76 void reader_resetbits(reader_t
*r
);
77 unsigned int reader_readbit(reader_t
*r
);
78 unsigned int reader_readbits(reader_t
*r
, int num
);
80 U8
reader_readU8(reader_t
*r
);
81 U16
reader_readU16(reader_t
*r
);
82 U32
reader_readU32(reader_t
*r
);
83 float reader_readFloat(reader_t
*r
);
84 double reader_readDouble(reader_t
*r
);
85 char*reader_readString(reader_t
*r
);
87 void writer_resetbits(writer_t
*w
);
88 void writer_writebit(writer_t
*w
, int bit
);
89 void writer_writebits(writer_t
*w
, unsigned int data
, int bits
);
91 void writer_writeU8(writer_t
*w
, unsigned char b
);
92 void writer_writeU16(writer_t
*w
, unsigned short v
);
93 void writer_writeU32(writer_t
*w
, unsigned long v
);
94 void writer_writeFloat(writer_t
*w
, float f
);
95 void writer_writeDouble(writer_t
*w
, double f
);
96 void writer_writeString(writer_t
*w
, const char*s
);
98 /* standard readers / writers */
100 void reader_init_filereader(reader_t
*r
, int handle
);
101 void reader_init_filereader2(reader_t
*r
, const char*filename
);
102 void reader_init_zlibinflate(reader_t
*r
, reader_t
*input
);
103 void reader_init_memreader(reader_t
*r
, void*data
, int length
);
104 void reader_init_nullreader(reader_t
*r
);
106 void reader_init_zzipreader(reader_t
*r
,ZZIP_FILE
*z
);
109 void writer_init_filewriter(writer_t
*w
, int handle
);
110 void writer_init_filewriter2(writer_t
*w
, char*filename
);
111 void writer_init_zlibdeflate(writer_t
*w
, writer_t
*output
);
112 void writer_init_memwriter(writer_t
*r
, void*data
, int length
);
113 void writer_init_nullwriter(writer_t
*w
);
115 void writer_init_growingmemwriter(writer_t
*r
, U32 grow
);
116 void* writer_growmemwrite_memptr(writer_t
*w
, int*len
);
117 void* writer_growmemwrite_getmem(writer_t
*w
);
118 void writer_growmemwrite_reset(writer_t
*w
);
120 #endif //__rfxswf_bitio_h__