/src/samba/third_party/ngtcp2/lib/ngtcp2_vec.h
Line | Count | Source |
1 | | /* |
2 | | * ngtcp2 |
3 | | * |
4 | | * Copyright (c) 2018 ngtcp2 contributors |
5 | | * |
6 | | * Permission is hereby granted, free of charge, to any person obtaining |
7 | | * a copy of this software and associated documentation files (the |
8 | | * "Software"), to deal in the Software without restriction, including |
9 | | * without limitation the rights to use, copy, modify, merge, publish, |
10 | | * distribute, sublicense, and/or sell copies of the Software, and to |
11 | | * permit persons to whom the Software is furnished to do so, subject to |
12 | | * the following conditions: |
13 | | * |
14 | | * The above copyright notice and this permission notice shall be |
15 | | * included in all copies or substantial portions of the Software. |
16 | | * |
17 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
18 | | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
19 | | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
20 | | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
21 | | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
22 | | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
23 | | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
24 | | */ |
25 | | #ifndef NGTCP2_VEC_H |
26 | | #define NGTCP2_VEC_H |
27 | | |
28 | | #ifdef HAVE_CONFIG_H |
29 | | # include <config.h> |
30 | | #endif /* defined(HAVE_CONFIG_H) */ |
31 | | |
32 | | #include <ngtcp2/ngtcp2.h> |
33 | | |
34 | | #include "ngtcp2_mem.h" |
35 | | |
36 | | /* |
37 | | * ngtcp2_vec_init initializes |vec| with the given parameters. It |
38 | | * returns |vec|. |
39 | | */ |
40 | | ngtcp2_vec *ngtcp2_vec_init(ngtcp2_vec *vec, const uint8_t *base, size_t len); |
41 | | |
42 | | /* |
43 | | * ngtcp2_vec_len returns the sum of length in |vec| of |n| elements. |
44 | | */ |
45 | | uint64_t ngtcp2_vec_len(const ngtcp2_vec *vec, size_t n); |
46 | | |
47 | | /* |
48 | | * ngtcp2_vec_len_varint is similar to ngtcp2_vec_len, but it returns |
49 | | * -1 if the sum of the length exceeds NGTCP2_MAX_VARINT. |
50 | | */ |
51 | | int64_t ngtcp2_vec_len_varint(const ngtcp2_vec *vec, size_t n); |
52 | | |
53 | | /* |
54 | | * ngtcp2_vec_split splits |src| at the data position where |
55 | | * ngtcp2_vec_len(|src|) does not exceed |left| bytes. The removed |
56 | | * vectors are moved to |dst|. The existing elements in |dst| are |
57 | | * moved forward to make up a space. The |maxcnt| is the maximum |
58 | | * number of elements which |dst| array can contain. The caller must |
59 | | * set |*psrccnt| to the number of elements of |src|. Similarly, the |
60 | | * caller must set |*pdstcnt| to the number of elements of |dst|. The |
61 | | * split does not necessarily occur at the boundary of ngtcp2_vec |
62 | | * object. After split has done, this function updates |*psrccnt| and |
63 | | * |*pdstcnt|. This function returns the number of bytes moved from |
64 | | * |src| to |dst|. If split cannot be made because doing so exceeds |
65 | | * |maxcnt|, this function returns -1. |
66 | | */ |
67 | | ngtcp2_ssize ngtcp2_vec_split(ngtcp2_vec *dst, size_t *pdstcnt, ngtcp2_vec *src, |
68 | | size_t *psrccnt, size_t left, size_t maxcnt); |
69 | | |
70 | | /* |
71 | | * ngtcp2_vec_merge merges |src| into |dst| by moving at most |left| |
72 | | * bytes from |src|. The |maxcnt| is the maximum number of elements |
73 | | * which |dst| array can contain. The caller must set |*pdstcnt| to |
74 | | * the number of elements of |dst|. Similarly, the caller must set |
75 | | * |*psrccnt| to the number of elements of |src|. After merge has |
76 | | * done, this function updates |*psrccnt| and |*pdstcnt|. This |
77 | | * function returns the number of bytes moved from |src| to |dst|. |
78 | | */ |
79 | | size_t ngtcp2_vec_merge(ngtcp2_vec *dst, size_t *pdstcnt, ngtcp2_vec *src, |
80 | | size_t *psrccnt, size_t left, size_t maxcnt); |
81 | | |
82 | | /* |
83 | | * ngtcp2_vec_copy_at_most copies |src| of length |srccnt| to |dst| of |
84 | | * length |dstcnt|. The total number of bytes which the copied |
85 | | * ngtcp2_vec refers to is at most |left|. The empty elements in |
86 | | * |src| are ignored. This function returns the number of elements |
87 | | * copied. |
88 | | */ |
89 | | size_t ngtcp2_vec_copy_at_most(ngtcp2_vec *dst, size_t dstcnt, |
90 | | const ngtcp2_vec *src, size_t srccnt, |
91 | | size_t left); |
92 | | |
93 | | /* |
94 | | * ngtcp2_vec_copy copies |src| of length |cnt| to |dst|. |dst| must |
95 | | * have sufficient capacity. |
96 | | */ |
97 | | void ngtcp2_vec_copy(ngtcp2_vec *dst, const ngtcp2_vec *src, size_t cnt); |
98 | | |
99 | | /* |
100 | | * ngtcp2_vec_split_at splits |src| at the |offset|. Caller must |
101 | | * ensure that offset < src->len. This function assigns the right |
102 | | * part of vector into |dst|. |
103 | | */ |
104 | | void ngtcp2_vec_split_at(ngtcp2_vec *dst, ngtcp2_vec *src, size_t offset); |
105 | | |
106 | | /* |
107 | | * ngtcp2_vec_end returns the one beyond the last offset of |v|. |
108 | | */ |
109 | 0 | static inline uint8_t *ngtcp2_vec_end(const ngtcp2_vec *v) { |
110 | 0 | return v->base + v->len; |
111 | 0 | } Unexecuted instantiation: ngtcp2_conn.c:ngtcp2_vec_end Unexecuted instantiation: ngtcp2_log.c:ngtcp2_vec_end Unexecuted instantiation: ngtcp2_pkt.c:ngtcp2_vec_end Unexecuted instantiation: ngtcp2_qlog.c:ngtcp2_vec_end Unexecuted instantiation: ngtcp2_rtb.c:ngtcp2_vec_end Unexecuted instantiation: ngtcp2_strm.c:ngtcp2_vec_end Unexecuted instantiation: ngtcp2_vec.c:ngtcp2_vec_end |
112 | | |
113 | | /* |
114 | | * ngtcp2_vec_drop removes the first |n| bytes from |v| by adjusting |
115 | | * its base and len fields. This function assumes |v|->len > 0 && |
116 | | * |v|->len >= n. |
117 | | */ |
118 | 0 | static inline void ngtcp2_vec_drop(ngtcp2_vec *v, size_t n) { |
119 | 0 | v->base += n; |
120 | 0 | v->len -= n; |
121 | 0 | } Unexecuted instantiation: ngtcp2_conn.c:ngtcp2_vec_drop Unexecuted instantiation: ngtcp2_log.c:ngtcp2_vec_drop Unexecuted instantiation: ngtcp2_pkt.c:ngtcp2_vec_drop Unexecuted instantiation: ngtcp2_qlog.c:ngtcp2_vec_drop Unexecuted instantiation: ngtcp2_rtb.c:ngtcp2_vec_drop Unexecuted instantiation: ngtcp2_strm.c:ngtcp2_vec_drop Unexecuted instantiation: ngtcp2_vec.c:ngtcp2_vec_drop |
122 | | |
123 | | #endif /* !defined(NGTCP2_VEC_H) */ |