-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathfrb.pxd
48 lines (35 loc) · 1.18 KB
/
frb.pxd
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
# Copyright (C) 2016-present the asyncpg authors and contributors
# <see AUTHORS file>
#
# This module is part of asyncpg and is released under
# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
cdef:
struct FRBuffer:
const char* buf
ssize_t len
inline ssize_t frb_get_len(FRBuffer *frb):
return frb.len
inline void frb_set_len(FRBuffer *frb, ssize_t new_len):
frb.len = new_len
inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):
frb.buf = buf
frb.len = len
inline const char* frb_read(FRBuffer *frb, ssize_t n) except NULL:
cdef const char *result
frb_check(frb, n)
result = frb.buf
frb.buf += n
frb.len -= n
return result
inline const char* frb_read_all(FRBuffer *frb):
cdef const char *result
result = frb.buf
frb.buf += frb.len
frb.len = 0
return result
inline FRBuffer *frb_slice_from(FRBuffer *frb,
FRBuffer* source, ssize_t len):
frb.buf = frb_read(source, len)
frb.len = len
return frb
object frb_check(FRBuffer *frb, ssize_t n)