redrust 0.1.1

redrust is a port of the popular Redis database system written in Rust programming language. This port aims to provide all the features of Redis while taking advantage of the Rust language's safety, speed, and modern language features.
Documentation
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
extern crate c2rust_bitfields;
extern crate libc;
extern crate core;
extern "C" {
    fn memcpy(
        _: *mut libc::c_void,
        _: *const libc::c_void,
        _: libc::c_ulong,
    ) -> *mut libc::c_void;
    fn strtod(_: *const libc::c_char, _: *mut *mut libc::c_char) -> libc::c_double;
    fn string2ll(
        s: *const libc::c_char,
        slen: size_t,
        value: *mut libc::c_longlong,
    ) -> libc::c_int;
    fn strchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char;
}
pub type size_t = libc::c_ulong;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct ReplyParser {
    pub curr_location: *const libc::c_char,
    pub callbacks: ReplyParserCallbacks,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct ReplyParserCallbacks {
    pub null_array_callback: Option::<
        unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char, size_t) -> (),
    >,
    pub null_bulk_string_callback: Option::<
        unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char, size_t) -> (),
    >,
    pub bulk_string_callback: Option::<
        unsafe extern "C" fn(
            *mut libc::c_void,
            *const libc::c_char,
            size_t,
            *const libc::c_char,
            size_t,
        ) -> (),
    >,
    pub error_callback: Option::<
        unsafe extern "C" fn(
            *mut libc::c_void,
            *const libc::c_char,
            size_t,
            *const libc::c_char,
            size_t,
        ) -> (),
    >,
    pub simple_str_callback: Option::<
        unsafe extern "C" fn(
            *mut libc::c_void,
            *const libc::c_char,
            size_t,
            *const libc::c_char,
            size_t,
        ) -> (),
    >,
    pub long_callback: Option::<
        unsafe extern "C" fn(
            *mut libc::c_void,
            libc::c_longlong,
            *const libc::c_char,
            size_t,
        ) -> (),
    >,
    pub array_callback: Option::<
        unsafe extern "C" fn(
            *mut ReplyParser,
            *mut libc::c_void,
            size_t,
            *const libc::c_char,
        ) -> (),
    >,
    pub set_callback: Option::<
        unsafe extern "C" fn(
            *mut ReplyParser,
            *mut libc::c_void,
            size_t,
            *const libc::c_char,
        ) -> (),
    >,
    pub map_callback: Option::<
        unsafe extern "C" fn(
            *mut ReplyParser,
            *mut libc::c_void,
            size_t,
            *const libc::c_char,
        ) -> (),
    >,
    pub bool_callback: Option::<
        unsafe extern "C" fn(
            *mut libc::c_void,
            libc::c_int,
            *const libc::c_char,
            size_t,
        ) -> (),
    >,
    pub double_callback: Option::<
        unsafe extern "C" fn(
            *mut libc::c_void,
            libc::c_double,
            *const libc::c_char,
            size_t,
        ) -> (),
    >,
    pub big_number_callback: Option::<
        unsafe extern "C" fn(
            *mut libc::c_void,
            *const libc::c_char,
            size_t,
            *const libc::c_char,
            size_t,
        ) -> (),
    >,
    pub verbatim_string_callback: Option::<
        unsafe extern "C" fn(
            *mut libc::c_void,
            *const libc::c_char,
            *const libc::c_char,
            size_t,
            *const libc::c_char,
            size_t,
        ) -> (),
    >,
    pub attribute_callback: Option::<
        unsafe extern "C" fn(
            *mut ReplyParser,
            *mut libc::c_void,
            size_t,
            *const libc::c_char,
        ) -> (),
    >,
    pub null_callback: Option::<
        unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char, size_t) -> (),
    >,
    pub error: Option::<unsafe extern "C" fn(*mut libc::c_void) -> ()>,
}
unsafe extern "C" fn parseBulk(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    let mut bulklen: libc::c_longlong = 0;
    (*parser).curr_location = p.offset(2 as libc::c_int as isize);
    string2ll(
        proto.offset(1 as libc::c_int as isize),
        (p.offset_from(proto) as libc::c_long - 1 as libc::c_int as libc::c_long)
            as size_t,
        &mut bulklen,
    );
    if bulklen == -(1 as libc::c_int) as libc::c_longlong {
        ((*parser).callbacks.null_bulk_string_callback)
            .expect(
                "non-null function pointer",
            )(
            p_ctx,
            proto,
            ((*parser).curr_location).offset_from(proto) as libc::c_long as size_t,
        );
    } else {
        let mut str: *const libc::c_char = (*parser).curr_location;
        (*parser).curr_location = ((*parser).curr_location).offset(bulklen as isize);
        (*parser)
            .curr_location = ((*parser).curr_location).offset(2 as libc::c_int as isize);
        ((*parser).callbacks.bulk_string_callback)
            .expect(
                "non-null function pointer",
            )(
            p_ctx,
            str,
            bulklen as size_t,
            proto,
            ((*parser).curr_location).offset_from(proto) as libc::c_long as size_t,
        );
    }
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseSimpleString(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    (*parser).curr_location = p.offset(2 as libc::c_int as isize);
    ((*parser).callbacks.simple_str_callback)
        .expect(
            "non-null function pointer",
        )(
        p_ctx,
        proto.offset(1 as libc::c_int as isize),
        (p.offset_from(proto) as libc::c_long - 1 as libc::c_int as libc::c_long)
            as size_t,
        proto,
        ((*parser).curr_location).offset_from(proto) as libc::c_long as size_t,
    );
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseError(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    (*parser).curr_location = p.offset(2 as libc::c_int as isize);
    ((*parser).callbacks.error_callback)
        .expect(
            "non-null function pointer",
        )(
        p_ctx,
        proto.offset(1 as libc::c_int as isize),
        (p.offset_from(proto) as libc::c_long - 1 as libc::c_int as libc::c_long)
            as size_t,
        proto,
        ((*parser).curr_location).offset_from(proto) as libc::c_long as size_t,
    );
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseLong(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    (*parser).curr_location = p.offset(2 as libc::c_int as isize);
    let mut val: libc::c_longlong = 0;
    string2ll(
        proto.offset(1 as libc::c_int as isize),
        (p.offset_from(proto) as libc::c_long - 1 as libc::c_int as libc::c_long)
            as size_t,
        &mut val,
    );
    ((*parser).callbacks.long_callback)
        .expect(
            "non-null function pointer",
        )(
        p_ctx,
        val,
        proto,
        ((*parser).curr_location).offset_from(proto) as libc::c_long as size_t,
    );
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseAttributes(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    let mut len: libc::c_longlong = 0;
    string2ll(
        proto.offset(1 as libc::c_int as isize),
        (p.offset_from(proto) as libc::c_long - 1 as libc::c_int as libc::c_long)
            as size_t,
        &mut len,
    );
    p = p.offset(2 as libc::c_int as isize);
    (*parser).curr_location = p;
    ((*parser).callbacks.attribute_callback)
        .expect("non-null function pointer")(parser, p_ctx, len as size_t, proto);
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseVerbatimString(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    let mut bulklen: libc::c_longlong = 0;
    (*parser).curr_location = p.offset(2 as libc::c_int as isize);
    string2ll(
        proto.offset(1 as libc::c_int as isize),
        (p.offset_from(proto) as libc::c_long - 1 as libc::c_int as libc::c_long)
            as size_t,
        &mut bulklen,
    );
    let mut format: *const libc::c_char = (*parser).curr_location;
    (*parser).curr_location = ((*parser).curr_location).offset(bulklen as isize);
    (*parser)
        .curr_location = ((*parser).curr_location).offset(2 as libc::c_int as isize);
    ((*parser).callbacks.verbatim_string_callback)
        .expect(
            "non-null function pointer",
        )(
        p_ctx,
        format,
        format.offset(4 as libc::c_int as isize),
        (bulklen - 4 as libc::c_int as libc::c_longlong) as size_t,
        proto,
        ((*parser).curr_location).offset_from(proto) as libc::c_long as size_t,
    );
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseBigNumber(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    (*parser).curr_location = p.offset(2 as libc::c_int as isize);
    ((*parser).callbacks.big_number_callback)
        .expect(
            "non-null function pointer",
        )(
        p_ctx,
        proto.offset(1 as libc::c_int as isize),
        (p.offset_from(proto) as libc::c_long - 1 as libc::c_int as libc::c_long)
            as size_t,
        proto,
        ((*parser).curr_location).offset_from(proto) as libc::c_long as size_t,
    );
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseNull(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    (*parser).curr_location = p.offset(2 as libc::c_int as isize);
    ((*parser).callbacks.null_callback)
        .expect(
            "non-null function pointer",
        )(
        p_ctx,
        proto,
        ((*parser).curr_location).offset_from(proto) as libc::c_long as size_t,
    );
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseDouble(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    (*parser).curr_location = p.offset(2 as libc::c_int as isize);
    let mut buf: [libc::c_char; 5121] = [0; 5121];
    let mut len: size_t = (p.offset_from(proto) as libc::c_long
        - 1 as libc::c_int as libc::c_long) as size_t;
    let mut d: libc::c_double = 0.;
    if len <= (5 as libc::c_int * 1024 as libc::c_int) as libc::c_ulong {
        memcpy(
            buf.as_mut_ptr() as *mut libc::c_void,
            proto.offset(1 as libc::c_int as isize) as *const libc::c_void,
            len,
        );
        buf[len as usize] = '\0' as i32 as libc::c_char;
        d = strtod(buf.as_mut_ptr(), 0 as *mut *mut libc::c_char);
    } else {
        d = 0 as libc::c_int as libc::c_double;
    }
    ((*parser).callbacks.double_callback)
        .expect(
            "non-null function pointer",
        )(
        p_ctx,
        d,
        proto,
        ((*parser).curr_location).offset_from(proto) as libc::c_long as size_t,
    );
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseBool(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    (*parser).curr_location = p.offset(2 as libc::c_int as isize);
    ((*parser).callbacks.bool_callback)
        .expect(
            "non-null function pointer",
        )(
        p_ctx,
        (*proto.offset(1 as libc::c_int as isize) as libc::c_int == 't' as i32)
            as libc::c_int,
        proto,
        ((*parser).curr_location).offset_from(proto) as libc::c_long as size_t,
    );
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseArray(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    let mut len: libc::c_longlong = 0;
    string2ll(
        proto.offset(1 as libc::c_int as isize),
        (p.offset_from(proto) as libc::c_long - 1 as libc::c_int as libc::c_long)
            as size_t,
        &mut len,
    );
    p = p.offset(2 as libc::c_int as isize);
    (*parser).curr_location = p;
    if len == -(1 as libc::c_int) as libc::c_longlong {
        ((*parser).callbacks.null_array_callback)
            .expect(
                "non-null function pointer",
            )(
            p_ctx,
            proto,
            ((*parser).curr_location).offset_from(proto) as libc::c_long as size_t,
        );
    } else {
        ((*parser).callbacks.array_callback)
            .expect("non-null function pointer")(parser, p_ctx, len as size_t, proto);
    }
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseSet(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    let mut len: libc::c_longlong = 0;
    string2ll(
        proto.offset(1 as libc::c_int as isize),
        (p.offset_from(proto) as libc::c_long - 1 as libc::c_int as libc::c_long)
            as size_t,
        &mut len,
    );
    p = p.offset(2 as libc::c_int as isize);
    (*parser).curr_location = p;
    ((*parser).callbacks.set_callback)
        .expect("non-null function pointer")(parser, p_ctx, len as size_t, proto);
    return 0 as libc::c_int;
}
unsafe extern "C" fn parseMap(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    let mut proto: *const libc::c_char = (*parser).curr_location;
    let mut p: *mut libc::c_char = strchr(
        proto.offset(1 as libc::c_int as isize),
        '\r' as i32,
    );
    let mut len: libc::c_longlong = 0;
    string2ll(
        proto.offset(1 as libc::c_int as isize),
        (p.offset_from(proto) as libc::c_long - 1 as libc::c_int as libc::c_long)
            as size_t,
        &mut len,
    );
    p = p.offset(2 as libc::c_int as isize);
    (*parser).curr_location = p;
    ((*parser).callbacks.map_callback)
        .expect("non-null function pointer")(parser, p_ctx, len as size_t, proto);
    return 0 as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn parseReply(
    mut parser: *mut ReplyParser,
    mut p_ctx: *mut libc::c_void,
) -> libc::c_int {
    match *((*parser).curr_location).offset(0 as libc::c_int as isize) as libc::c_int {
        36 => return parseBulk(parser, p_ctx),
        43 => return parseSimpleString(parser, p_ctx),
        45 => return parseError(parser, p_ctx),
        58 => return parseLong(parser, p_ctx),
        42 => return parseArray(parser, p_ctx),
        126 => return parseSet(parser, p_ctx),
        37 => return parseMap(parser, p_ctx),
        35 => return parseBool(parser, p_ctx),
        44 => return parseDouble(parser, p_ctx),
        95 => return parseNull(parser, p_ctx),
        40 => return parseBigNumber(parser, p_ctx),
        61 => return parseVerbatimString(parser, p_ctx),
        124 => return parseAttributes(parser, p_ctx),
        _ => {
            if ((*parser).callbacks.error).is_some() {
                ((*parser).callbacks.error).expect("non-null function pointer")(p_ctx);
            }
        }
    }
    return -(1 as libc::c_int);
}