File: usual.h

package info (click to toggle)
ruby-oj 3.16.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,208 kB
  • sloc: ansic: 20,028; ruby: 11,642; sh: 70; makefile: 17
file content (69 lines) | stat: -rw-r--r-- 1,608 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2022, Peter Ohler, All rights reserved.

#include <ruby.h>
#include <stdbool.h>
#include <stdint.h>

struct _cache;
struct _ojParser;

// Used to mark the start of each Hash, Array, or Object. The members point at
// positions of the start in the value stack and if not an Array into the key
// stack.
typedef struct _col {
    long vi;  // value stack index
    long ki;  // key stack index if an hash else -1 for an array
} *Col;

typedef union _key {
    struct {
        int16_t len;
        char    buf[30];
    };
    struct {
        int16_t xlen;  // should be the same as len
        char   *key;
    };
} *Key;

#define MISS_AUTO 'A'
#define MISS_RAISE 'R'
#define MISS_IGNORE 'I'

typedef struct _usual {
    VALUE *vhead;
    VALUE *vtail;
    VALUE *vend;

    Col chead;
    Col ctail;
    Col cend;

    Key khead;
    Key ktail;
    Key kend;

    VALUE (*get_key)(struct _ojParser *p, Key kp);
    struct _cache *key_cache;  // same as str_cache or sym_cache
    struct _cache *str_cache;
    struct _cache *sym_cache;
    struct _cache *class_cache;
    struct _cache *attr_cache;

    VALUE array_class;
    VALUE hash_class;

    char   *create_id;
    uint8_t create_id_len;
    uint8_t cache_str;
    uint8_t cache_xrate;
    uint8_t miss_class;
    bool    cache_keys;
    bool    ignore_json_create;
    bool    raise_on_empty;
} *Usual;

// Initialize the parser with the usual delegate. If the usual delegate is
// wrapped then this function is called first and then the parser functions
// can be replaced.
extern void oj_init_usual(struct _ojParser *p, Usual d);