File: decoder.h

package info (click to toggle)
cbor2 5.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 784 kB
  • sloc: ansic: 5,728; python: 4,109; makefile: 14; sh: 8
file content (44 lines) | stat: -rw-r--r-- 1,507 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <stdbool.h>
#include <stdint.h>

// Default readahead buffer size for streaming reads.
// Set to 1 for backwards compatibility (no buffering).
#define CBOR2_DEFAULT_READ_SIZE 1
#define CBOR2_DEFAULT_MAX_DEPTH 400

// Forward declaration for function pointer typedef
struct CBORDecoderObject_;

// Function pointer type for read dispatch (eliminates runtime check)
typedef int (*fp_read_fn)(struct CBORDecoderObject_ *, char *, Py_ssize_t);

typedef struct CBORDecoderObject_ {
    PyObject_HEAD
    PyObject *read;    // cached read() method of fp
    PyObject *tag_hook;
    PyObject *object_hook;
    PyObject *shareables;
    PyObject *stringref_namespace;
    const char *str_errors;  // NULL for strict, "replace" for replace mode
    Py_ssize_t max_depth;
    bool immutable;
    Py_ssize_t shared_index;
    Py_ssize_t decode_depth;

    // Readahead buffer for streaming
    char *readahead;            // allocated buffer
    Py_ssize_t readahead_size;  // size of allocated buffer
    Py_ssize_t read_pos;        // current position in buffer
    Py_ssize_t read_len;        // valid bytes in buffer

    // Read dispatch - points to unbuffered or buffered implementation
    fp_read_fn fp_read;
} CBORDecoderObject;

extern PyTypeObject CBORDecoderType;

PyObject * CBORDecoder_new(PyTypeObject *, PyObject *, PyObject *);
int CBORDecoder_init(CBORDecoderObject *, PyObject *, PyObject *);
PyObject * CBORDecoder_decode(CBORDecoderObject *);