Initial commit
[io-compress-brotli.git] / dec / streams.h
1 /* Copyright 2013 Google Inc. All Rights Reserved.
2
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6
7 /* Functions for streaming input and output. */
8
9 #ifndef BROTLI_DEC_STREAMS_H_
10 #define BROTLI_DEC_STREAMS_H_
11
12 #include <stdio.h>
13 #include "./port.h"
14 #include "./types.h"
15
16 #if defined(__cplusplus) || defined(c_plusplus)
17 extern "C" {
18 #endif
19
20 /* Function pointer type used to read len bytes into buf. Returns the */
21 /* number of bytes read or -1 on error. */
22 typedef int (*BrotliInputFunction)(void* data, uint8_t* buf, size_t len);
23
24 /* Input callback function with associated data. */
25 typedef struct {
26 BrotliInputFunction cb_;
27 void* data_;
28 } BrotliInput;
29
30 /* Reads len bytes into buf, using the in callback. */
31 static BROTLI_INLINE int BrotliRead(BrotliInput in, uint8_t* buf, size_t len) {
32 return in.cb_(in.data_, buf, len);
33 }
34
35 /* Function pointer type used to write len bytes into buf. Returns the */
36 /* number of bytes written or -1 on error. */
37 typedef int (*BrotliOutputFunction)(void* data, const uint8_t* buf, size_t len);
38
39 /* Output callback function with associated data. */
40 typedef struct {
41 BrotliOutputFunction cb_;
42 void* data_;
43 } BrotliOutput;
44
45 /* Writes len bytes into buf, using the out callback. */
46 static BROTLI_INLINE int BrotliWrite(BrotliOutput out,
47 const uint8_t* buf, size_t len) {
48 return out.cb_(out.data_, buf, len);
49 }
50
51 /* Memory region with position. */
52 typedef struct {
53 const uint8_t* buffer;
54 size_t length;
55 size_t pos;
56 } BrotliMemInput;
57
58 /* Input callback where *data is a BrotliMemInput struct. */
59 int BrotliMemInputFunction(void* data, uint8_t* buf, size_t count);
60
61 /* Returns an input callback that wraps the given memory region. */
62 BrotliInput BrotliInitMemInput(const uint8_t* buffer, size_t length,
63 BrotliMemInput* mem_input);
64
65 /* Output buffer with position. */
66 typedef struct {
67 uint8_t* buffer;
68 size_t length;
69 size_t pos;
70 } BrotliMemOutput;
71
72 /* Output callback where *data is a BrotliMemOutput struct. */
73 int BrotliMemOutputFunction(void* data, const uint8_t* buf, size_t count);
74
75 /* Returns an output callback that wraps the given memory region. */
76 BrotliOutput BrotliInitMemOutput(uint8_t* buffer, size_t length,
77 BrotliMemOutput* mem_output);
78
79 /* Input callback that reads from a file. */
80 int BrotliFileInputFunction(void* data, uint8_t* buf, size_t count);
81 BrotliInput BrotliFileInput(FILE* f);
82
83 /* Output callback that writes to a file. */
84 int BrotliFileOutputFunction(void* data, const uint8_t* buf, size_t count);
85 BrotliOutput BrotliFileOutput(FILE* f);
86
87 /* Output callback that does nothing, always consumes the whole input. */
88 int BrotliNullOutputFunction(void* data, const uint8_t* buf, size_t count);
89 BrotliOutput BrotliNullOutput(void);
90
91 #if defined(__cplusplus) || defined(c_plusplus)
92 } /* extern "C" */
93 #endif
94
95 #endif /* BROTLI_DEC_STREAMS_H_ */
This page took 0.022965 seconds and 4 git commands to generate.