3 implementation of bitio.h.
5 Copyright (C) 2003 Matthias Kramm <kramm@quiss.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
31 #define __USE_LARGEFILE64
35 #include "../config.h"
39 #define ZLIB_BUFFER_SIZE 16384
43 /* ---------------------------- null reader ------------------------------- */
45 static int reader_nullread(reader_t
*r
, void* data
, int len
)
50 static void reader_nullread_dealloc(reader_t
*r
)
52 memset(r
, 0, sizeof(reader_t
));
54 static int reader_nullseek(reader_t
*r
, int pos
)
58 void reader_init_nullreader(reader_t
*r
)
60 r
->read
= reader_nullread
;
61 r
->seek
= reader_nullseek
;
62 r
->dealloc
= reader_nullread_dealloc
;
64 r
->type
= READER_TYPE_NULL
;
69 /* ---------------------------- file reader ------------------------------- */
71 static int reader_fileread(reader_t
*reader
, void* data
, int len
)
73 int ret
= read((int)reader
->internal
, data
, len
);
78 static void reader_fileread_dealloc(reader_t
*r
)
80 if(r
->type
== READER_TYPE_FILE2
) {
81 close((ptroff_t
)r
->internal
);
83 memset(r
, 0, sizeof(reader_t
));
85 static int reader_fileread_seek(reader_t
*r
, int pos
)
87 return lseek((ptroff_t
)r
->internal
, pos
, SEEK_SET
);
89 void reader_init_filereader(reader_t
*r
, int handle
)
91 r
->read
= reader_fileread
;
92 r
->seek
= reader_fileread_seek
;
93 r
->dealloc
= reader_fileread_dealloc
;
94 r
->internal
= (void*)handle
;
95 r
->type
= READER_TYPE_FILE
;
100 int reader_init_filereader2(reader_t
*r
, const char*filename
)
112 reader_init_filereader(r
, fi
);
113 r
->type
= READER_TYPE_FILE2
;
117 /* ---------------------------- mem reader ------------------------------- */
119 typedef struct _memread
125 static int reader_memread(reader_t
*reader
, void* data
, int len
)
127 memread_t
*mr
= (memread_t
*)reader
->internal
;
129 if(mr
->length
- reader
->pos
< len
) {
130 len
= mr
->length
- reader
->pos
;
133 memcpy(data
, &mr
->data
[reader
->pos
], len
);
137 static int reader_memseek(reader_t
*reader
, int pos
)
139 memread_t
*mr
= (memread_t
*)reader
->internal
;
140 if(pos
>=0 && pos
<=mr
->length
) {
147 static void reader_memread_dealloc(reader_t
*reader
)
150 free(reader
->internal
);
151 memset(reader
, 0, sizeof(reader_t
));
153 void reader_init_memreader(reader_t
*r
, void*newdata
, int newlength
)
155 memread_t
*mr
= (memread_t
*)malloc(sizeof(memread_t
));
156 mr
->data
= (unsigned char*)newdata
;
157 mr
->length
= newlength
;
158 r
->read
= reader_memread
;
159 r
->seek
= reader_memseek
;
160 r
->dealloc
= reader_memread_dealloc
;
161 r
->internal
= (void*)mr
;
162 r
->type
= READER_TYPE_MEM
;
168 /* ---------------------------- zzip reader ------------------------------ */
170 static int reader_zzip_read(reader_t
*reader
, void* data
, int len
)
172 return zzip_file_read((ZZIP_FILE
*)reader
->internal
, data
, len
);
174 static void reader_zzip_dealloc(reader_t
*reader
)
176 memset(reader
, 0, sizeof(reader_t
));
178 static int reader_zzip_seek(reader_t
*reader
, int pos
)
180 return zzip_seek((ZZIP_FILE
*)reader
->internal
, pos
, SEEK_SET
);
182 void reader_init_zzipreader(reader_t
*r
,ZZIP_FILE
*z
)
184 r
->read
= reader_zzip_read
;
185 r
->seek
= reader_zzip_seek
;
186 r
->dealloc
= reader_zzip_dealloc
;
188 r
->type
= READER_TYPE_ZZIP
;
195 /* ---------------------------- mem writer ------------------------------- */
197 typedef struct _memwrite
203 static int writer_memwrite_write(writer_t
*w
, void* data
, int len
)
205 memwrite_t
*mw
= (memwrite_t
*)w
->internal
;
206 if(mw
->length
- w
->pos
> len
) {
207 memcpy(&mw
->data
[w
->pos
], data
, len
);
211 memcpy(&mw
->data
[w
->pos
], data
, mw
->length
- w
->pos
);
213 return mw
->length
- w
->pos
;
216 static void writer_memwrite_finish(writer_t
*w
)
222 static void dummy_flush(writer_t
*w
)
225 void writer_init_memwriter(writer_t
*w
, void*data
, int len
)
228 mr
= (memwrite_t
*)malloc(sizeof(memwrite_t
));
229 mr
->data
= (unsigned char *)data
;
231 memset(w
, 0, sizeof(writer_t
));
232 w
->write
= writer_memwrite_write
;
233 w
->flush
= dummy_flush
;
234 w
->finish
= writer_memwrite_finish
;
235 w
->internal
= (void*)mr
;
236 w
->type
= WRITER_TYPE_MEM
;
242 /* ------------------------- growing mem writer ------------------------------- */
244 typedef struct _growmemwrite
250 static int writer_growmemwrite_write(writer_t
*w
, void* data
, int len
)
252 growmemwrite_t
*mw
= (growmemwrite_t
*)w
->internal
;
254 fprintf(stderr
, "Illegal write operation: data already given away");
257 if(mw
->length
- w
->pos
< len
) {
258 int newlength
= mw
->length
;
259 while(newlength
- w
->pos
< len
) {
260 newlength
+= mw
->grow
;
263 unsigned char*newmem
= (unsigned char*)malloc(newlength
);
264 memcpy(newmem
, mw
->data
, mw
->length
);
268 mw
->data
= (unsigned char*)realloc(mw
->data
, newlength
);
270 mw
->length
= newlength
;
272 memcpy(&mw
->data
[w
->pos
], data
, len
);
276 static void writer_growmemwrite_finish(writer_t
*w
)
278 growmemwrite_t
*mw
= (growmemwrite_t
*)w
->internal
;
280 free(mw
->data
);mw
->data
= 0;
283 free(w
->internal
);mw
=0;
284 memset(w
, 0, sizeof(writer_t
));
286 void* writer_growmemwrite_memptr(writer_t
*w
, int*len
)
288 growmemwrite_t
*mw
= (growmemwrite_t
*)w
->internal
;
294 void* writer_growmemwrite_getmem(writer_t
*w
)
296 growmemwrite_t
*mw
= (growmemwrite_t
*)w
->internal
;
298 /* remove own reference so that neither write() nor finish() can free it.
299 It's property of the caller now.
304 void writer_growmemwrite_reset(writer_t
*w
)
306 growmemwrite_t
*mw
= (growmemwrite_t
*)w
->internal
;
311 void writer_init_growingmemwriter(writer_t
*w
, U32 grow
)
313 growmemwrite_t
*mw
= (growmemwrite_t
*)malloc(sizeof(growmemwrite_t
));
315 mw
->data
= (unsigned char *)malloc(mw
->length
);
317 memset(w
, 0, sizeof(writer_t
));
318 w
->write
= writer_growmemwrite_write
;
319 w
->flush
= dummy_flush
;
320 w
->finish
= writer_growmemwrite_finish
;
321 w
->internal
= (void*)mw
;
322 w
->type
= WRITER_TYPE_GROWING_MEM
;
328 /* ---------------------------- file writer ------------------------------- */
330 typedef struct _filewrite
336 static int writer_filewrite_write(writer_t
*w
, void* data
, int len
)
338 filewrite_t
* fw
= (filewrite_t
*)w
->internal
;
340 int l
= write(fw
->handle
, data
, len
);
342 fprintf(stderr
, "Error writing to file: %d/%d", l
, len
);
345 static void writer_filewrite_finish(writer_t
*w
)
347 filewrite_t
*mr
= (filewrite_t
*)w
->internal
;
351 memset(w
, 0, sizeof(writer_t
));
353 void writer_init_filewriter(writer_t
*w
, int handle
)
355 filewrite_t
*mr
= (filewrite_t
*)malloc(sizeof(filewrite_t
));
358 memset(w
, 0, sizeof(writer_t
));
359 w
->write
= writer_filewrite_write
;
360 w
->finish
= writer_filewrite_finish
;
362 w
->type
= WRITER_TYPE_FILE
;
367 void writer_init_filewriter2(writer_t
*w
, char*filename
)
378 O_WRONLY
|O_CREAT
|O_TRUNC
, 0644);
379 writer_init_filewriter(w
, fi
);
380 ((filewrite_t
*)w
->internal
)->free_handle
= 1;
383 /* ---------------------------- null writer ------------------------------- */
385 static int writer_nullwrite_write(writer_t
*w
, void* data
, int len
)
390 static void writer_nullwrite_finish(writer_t
*w
)
392 memset(w
, 0, sizeof(writer_t
));
394 void writer_init_nullwriter(writer_t
*w
)
396 memset(w
, 0, sizeof(writer_t
));
397 w
->write
= writer_nullwrite_write
;
398 w
->flush
= dummy_flush
;
399 w
->finish
= writer_nullwrite_finish
;
401 w
->type
= WRITER_TYPE_NULL
;
406 /* ---------------------------- zlibinflate reader -------------------------- */
408 typedef struct _zlibinflate
413 unsigned char readbuffer
[ZLIB_BUFFER_SIZE
];
418 static void zlib_error(int ret
, char* msg
, z_stream
*zs
)
420 fprintf(stderr
, "%s: zlib error (%d): last zlib error: %s\n",
423 zs
->msg
?zs
->msg
:"unknown");
424 if(errno
) perror("errno:");
429 static int reader_zlibinflate(reader_t
*reader
, void* data
, int len
)
432 zlibinflate_t
*z
= (zlibinflate_t
*)reader
->internal
;
440 z
->zs
.next_out
= (Bytef
*)data
;
441 z
->zs
.avail_out
= len
;
444 if(!z
->zs
.avail_in
) {
445 z
->zs
.avail_in
= z
->input
->read(z
->input
, z
->readbuffer
, ZLIB_BUFFER_SIZE
);
446 z
->zs
.next_in
= z
->readbuffer
;
449 ret
= inflate(&z
->zs
, Z_NO_FLUSH
);
451 ret
= inflate(&z
->zs
, Z_FINISH
);
454 ret
!= Z_STREAM_END
) zlib_error(ret
, "bitio:inflate_inflate", &z
->zs
);
456 if (ret
== Z_STREAM_END
) {
457 int pos
= z
->zs
.next_out
- (Bytef
*)data
;
458 ret
= inflateEnd(&z
->zs
);
459 if (ret
!= Z_OK
) zlib_error(ret
, "bitio:inflate_end", &z
->zs
);
460 free(reader
->internal
);
461 reader
->internal
= 0;
465 if(!z
->zs
.avail_out
) {
472 fprintf(stderr
, "Error: swftools was compiled without zlib support");
476 static int reader_zlibseek(reader_t
*reader
, int pos
)
478 fprintf(stderr
, "Erro: seeking not supported for zlib streams");
481 static void reader_zlibinflate_dealloc(reader_t
*reader
)
484 zlibinflate_t
*z
= (zlibinflate_t
*)reader
->internal
;
485 /* test whether read() already did basic deallocation */
486 if(reader
->internal
) {
488 free(reader
->internal
);
490 memset(reader
, 0, sizeof(reader_t
));
493 void reader_init_zlibinflate(reader_t
*r
, reader_t
*input
)
496 zlibinflate_t
*z
= (zlibinflate_t
*)malloc(sizeof(zlibinflate_t
));
497 memset(z
, 0, sizeof(zlibinflate_t
));
499 memset(r
, 0, sizeof(reader_t
));
501 r
->read
= reader_zlibinflate
;
502 r
->seek
= reader_zlibseek
;
503 r
->dealloc
= reader_zlibinflate_dealloc
;
504 r
->type
= READER_TYPE_ZLIB
;
507 memset(&z
->zs
,0,sizeof(z_stream
));
508 z
->zs
.zalloc
= Z_NULL
;
509 z
->zs
.zfree
= Z_NULL
;
510 z
->zs
.opaque
= Z_NULL
;
511 ret
= inflateInit(&z
->zs
);
512 if (ret
!= Z_OK
) zlib_error(ret
, "bitio:inflate_init", &z
->zs
);
515 fprintf(stderr
, "Error: swftools was compiled without zlib support");
520 /* ---------------------------- zlibdeflate writer -------------------------- */
522 typedef struct _zlibdeflate
527 unsigned char writebuffer
[ZLIB_BUFFER_SIZE
];
531 static int writer_zlibdeflate_write(writer_t
*writer
, void* data
, int len
)
534 zlibdeflate_t
*z
= (zlibdeflate_t
*)writer
->internal
;
536 if(writer
->type
!= WRITER_TYPE_ZLIB
) {
537 fprintf(stderr
, "Wrong writer ID (writer not initialized?)\n");
541 fprintf(stderr
, "zlib not initialized!\n");
547 z
->zs
.next_in
= (Bytef
*)data
;
548 z
->zs
.avail_in
= len
;
551 ret
= deflate(&z
->zs
, Z_NO_FLUSH
);
553 if (ret
!= Z_OK
) zlib_error(ret
, "bitio:deflate_deflate", &z
->zs
);
555 if(z
->zs
.next_out
!= z
->writebuffer
) {
556 writer
->pos
+= z
->zs
.next_out
- (Bytef
*)z
->writebuffer
;
557 z
->output
->write(z
->output
, z
->writebuffer
, z
->zs
.next_out
- (Bytef
*)z
->writebuffer
);
558 z
->zs
.next_out
= z
->writebuffer
;
559 z
->zs
.avail_out
= ZLIB_BUFFER_SIZE
;
562 if(!z
->zs
.avail_in
) {
568 fprintf(stderr
, "Error: swftools was compiled without zlib support");
573 void writer_zlibdeflate_flush(writer_t
*writer
)
576 zlibdeflate_t
*z
= (zlibdeflate_t
*)writer
->internal
;
578 if(writer
->type
!= WRITER_TYPE_ZLIB
) {
579 fprintf(stderr
, "Wrong writer ID (writer not initialized?)\n");
583 fprintf(stderr
, "zlib not initialized!\n");
590 ret
= deflate(&z
->zs
, Z_SYNC_FLUSH
);
591 if (ret
!= Z_OK
) zlib_error(ret
, "bitio:deflate_flush", &z
->zs
);
592 if(z
->zs
.next_out
!= z
->writebuffer
) {
593 writer
->pos
+= z
->zs
.next_out
- (Bytef
*)z
->writebuffer
;
594 z
->output
->write(z
->output
, z
->writebuffer
, z
->zs
.next_out
- (Bytef
*)z
->writebuffer
);
595 z
->zs
.next_out
= z
->writebuffer
;
596 z
->zs
.avail_out
= ZLIB_BUFFER_SIZE
;
598 /* TODO: how will zlib let us know it needs more buffer space? */
603 fprintf(stderr
, "Error: swftools was compiled without zlib support");
608 static void writer_zlibdeflate_finish(writer_t
*writer
)
611 zlibdeflate_t
*z
= (zlibdeflate_t
*)writer
->internal
;
614 if(writer
->type
!= WRITER_TYPE_ZLIB
) {
615 fprintf(stderr
, "Wrong writer ID (writer not initialized?)\n");
622 ret
= deflate(&z
->zs
, Z_FINISH
);
624 ret
!= Z_STREAM_END
) zlib_error(ret
, "bitio:deflate_finish", &z
->zs
);
626 if(z
->zs
.next_out
!= z
->writebuffer
) {
627 writer
->pos
+= z
->zs
.next_out
- (Bytef
*)z
->writebuffer
;
628 z
->output
->write(z
->output
, z
->writebuffer
, z
->zs
.next_out
- (Bytef
*)z
->writebuffer
);
629 z
->zs
.next_out
= z
->writebuffer
;
630 z
->zs
.avail_out
= ZLIB_BUFFER_SIZE
;
633 if (ret
== Z_STREAM_END
) {
638 ret
= deflateEnd(&z
->zs
);
639 if (ret
!= Z_OK
) zlib_error(ret
, "bitio:deflate_end", &z
->zs
);
640 free(writer
->internal
);
641 memset(writer
, 0, sizeof(writer_t
));
642 //output->finish(output);
644 fprintf(stderr
, "Error: swftools was compiled without zlib support");
648 void writer_init_zlibdeflate(writer_t
*w
, writer_t
*output
)
653 memset(w
, 0, sizeof(writer_t
));
654 z
= (zlibdeflate_t
*)malloc(sizeof(zlibdeflate_t
));
655 memset(z
, 0, sizeof(zlibdeflate_t
));
657 w
->write
= writer_zlibdeflate_write
;
658 w
->flush
= writer_zlibdeflate_flush
;
659 w
->finish
= writer_zlibdeflate_finish
;
660 w
->type
= WRITER_TYPE_ZLIB
;
663 memset(&z
->zs
,0,sizeof(z_stream
));
664 z
->zs
.zalloc
= Z_NULL
;
665 z
->zs
.zfree
= Z_NULL
;
666 z
->zs
.opaque
= Z_NULL
;
667 ret
= deflateInit(&z
->zs
, 9);
668 if (ret
!= Z_OK
) zlib_error(ret
, "bitio:deflate_init", &z
->zs
);
671 z
->zs
.next_out
= z
->writebuffer
;
672 z
->zs
.avail_out
= ZLIB_BUFFER_SIZE
;
674 fprintf(stderr
, "Error: swftools was compiled without zlib support");
679 /* ----------------------- bit handling routines -------------------------- */
681 void writer_writebit(writer_t
*w
, int bit
)
685 w
->write(w
, &w
->mybyte
, 1);
690 w
->mybyte
|= 1 << (7 - w
->bitpos
);
693 void writer_writebits(writer_t
*w
, unsigned int data
, int bits
)
698 writer_writebit(w
, (data
>> (bits
-t
-1))&1);
701 void writer_resetbits(writer_t
*w
)
704 w
->write(w
, &w
->mybyte
, 1);
709 unsigned int reader_readbit(reader_t
*r
)
714 r
->read(r
, &r
->mybyte
, 1);
716 return (r
->mybyte
>>(7-r
->bitpos
++))&1;
718 unsigned int reader_readbits(reader_t
*r
, int num
)
725 val
|=reader_readbit(r
);
729 void reader_resetbits(reader_t
*r
)
736 U8
reader_readU8(reader_t
*r
)
739 if(r
->read(r
, &b
, 1)<1) {
740 fprintf(stderr
, "bitio.c:reader_readU8: Read over end of memory region\n");
744 S8
reader_readS8(reader_t
*r
)
747 if(r
->read(r
, &b
, 1)<1) {
748 fprintf(stderr
, "bitio.c:reader_readU8: Read over end of memory region\n");
752 U16
reader_readU16(reader_t
*r
)
755 if(r
->read(r
, &b1
, 1)<1) {
756 fprintf(stderr
, "bitio.c:reader_readU16: Read over end of memory region\n");
758 if(r
->read(r
, &b2
, 1)<1) {
759 fprintf(stderr
, "bitio.c:reader_readU16: Read over end of memory region\n");
763 U32
reader_readU32(reader_t
*r
)
765 U8 b1
=0,b2
=0,b3
=0,b4
=0;
766 if(r
->read(r
, &b1
, 1)<1)
767 fprintf(stderr
, "bitio.c:reader_readU32: Read over end of memory region\n");
768 if(r
->read(r
, &b2
, 1)<1)
769 fprintf(stderr
, "bitio.c:reader_readU32: Read over end of memory region\n");
770 if(r
->read(r
, &b3
, 1)<1)
771 fprintf(stderr
, "bitio.c:reader_readU32: Read over end of memory region\n");
772 if(r
->read(r
, &b4
, 1)<1)
773 fprintf(stderr
, "bitio.c:reader_readU32: Read over end of memory region\n");
774 return b1
|b2
<<8|b3
<<16|b4
<<24;
777 float reader_readFloat(reader_t
*r
)
783 U8 b1
=0,b2
=0,b3
=0,b4
=0;
788 U32 w
= (b1
|b2
<<8|b3
<<16|b4
<<24);
791 double reader_readDouble(reader_t
*r
)
799 U64 w
= ((U64
)b
[0]|(U64
)b
[1]<<8|(U64
)b
[2]<<16|(U64
)b
[3]<<24|(U64
)b
[4]<<32|(U64
)b
[5]<<40|(U64
)b
[6]<<48|(U64
)b
[7]<<56);
802 char*reader_readString(reader_t
*r
)
805 writer_init_growingmemwriter(&g
, 16);
807 U8 b
= reader_readU8(r
);
808 writer_writeU8(&g
, b
);
812 char*string
= (char*)writer_growmemwrite_getmem(&g
);
816 unsigned int read_compressed_uint(reader_t
*r
)
821 b
= reader_readU8(r
);
826 int read_compressed_int(reader_t
*r
)
831 b
= reader_readS8(r
);
835 i
|=0xffffff80; //sign extension
841 b
= reader_readS8(r
);
849 void writer_writeString(writer_t
*w
, const char*s
)
853 w
->write(w
, (void*)s
, l
);
854 w
->write(w
, &zero
, 1);
856 void writer_writeU8(writer_t
*w
, unsigned char b
)
860 void writer_writeU16(writer_t
*w
, unsigned short v
)
862 unsigned char b1
= v
;
863 unsigned char b2
= v
>>8;
867 void writer_writeU32(writer_t
*w
, unsigned long v
)
869 unsigned char b1
= v
;
870 unsigned char b2
= v
>>8;
871 unsigned char b3
= v
>>16;
872 unsigned char b4
= v
>>24;
878 void writer_writeFloat(writer_t
*w
, float f
)
883 unsigned v
= *(unsigned*)&f
;
884 unsigned char b1
= v
;
885 unsigned char b2
= v
>>8;
886 unsigned char b3
= v
>>16;
887 unsigned char b4
= v
>>24;
893 void writer_writeDouble(writer_t
*w
, double f
)
898 unsigned long long v
= *(unsigned long long*)&f
;
899 unsigned char b1
= v
;
900 unsigned char b2
= v
>>8;
901 unsigned char b3
= v
>>16;
902 unsigned char b4
= v
>>24;
903 unsigned char b5
= v
>>32;
904 unsigned char b6
= v
>>40;
905 unsigned char b7
= v
>>48;
906 unsigned char b8
= v
>>56;
916 void write_compressed_uint(writer_t
*w
, unsigned int u
)
919 writer_writeU8(w
, u
);
920 } else if(u
<0x4000) {
921 writer_writeU8(w
, u
>>7|0x80);
922 writer_writeU8(w
, u
&0x7f);
923 } else if(u
<0x200000) {
924 writer_writeU8(w
, u
>>14|0x80);
925 writer_writeU8(w
, u
>>7|0x80);
926 writer_writeU8(w
, u
&0x7f);
927 } else if(u
<0x10000000) {
928 writer_writeU8(w
, u
>>21|0x80);
929 writer_writeU8(w
, u
>>14|0x80);
930 writer_writeU8(w
, u
>>7|0x80);
931 writer_writeU8(w
, u
&0x7f);
933 writer_writeU8(w
, u
>>28|0x80);
934 writer_writeU8(w
, u
>>21|0x80);
935 writer_writeU8(w
, u
>>14|0x80);
936 writer_writeU8(w
, u
>>7|0x80);
937 writer_writeU8(w
, u
&0x7f);
940 void write_compressed_int(writer_t
*w
, int i
)
942 if(i
>=-0x40 && i
<0x40) {
943 writer_writeU8(w
, i
&0x7f);
944 } else if(i
>=-0x2000 && i
<0x2000) {
945 writer_writeU8(w
, (i
>>7)&0x7f|0x80);
946 writer_writeU8(w
, i
&0x7f);
947 } else if(i
>=-0x100000 && i
<0x100000) {
948 writer_writeU8(w
, (i
>>14)&0x7f|0x80);
949 writer_writeU8(w
, (i
>>7)&0x7f|0x80);
950 writer_writeU8(w
, (i
)&0x7f);
951 } else if(i
>=-0x8000000 && i
<0x8000000) {
952 writer_writeU8(w
, (i
>>21)&0x7f|0x80);
953 writer_writeU8(w
, (i
>>14)&0x7f|0x80);
954 writer_writeU8(w
, (i
>>7)&0x7f|0x80);
955 writer_writeU8(w
, (i
)&0x7f);
957 writer_writeU8(w
, (i
>>28)&0x7f|0x80);
958 writer_writeU8(w
, (i
>>21)&0x7f|0x80);
959 writer_writeU8(w
, (i
>>14)&0x7f|0x80);
960 writer_writeU8(w
, (i
>>7)&0x7f|0x80);
961 writer_writeU8(w
, (i
)&0x7f);