changeset 8191:7bd7c4e24951 quic

Macro for calculating size of varint.
author Vladimir Homutov <vl@nginx.com>
date Wed, 04 Mar 2020 23:24:51 +0300
parents 2bc1f97c1c2d
children fb0879c65650
files src/event/ngx_event_quic.c
diffstat 1 files changed, 3 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/event/ngx_event_quic.c
+++ b/src/event/ngx_event_quic.c
@@ -49,6 +49,8 @@
 #define ngx_quic_write_uint32_aligned(p, s)                                   \
     (*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t))
 
+#define ngx_quic_varint_len(value)                                            \
+    ((value) <= 63 ? 1 : (value) <= 16383 ? 2 : (value) <= 1073741823 ?  4 : 8)
 
 
 #if (NGX_DEBUG)
@@ -349,12 +351,7 @@ ngx_quic_create_crypto(u_char *p, ngx_qu
     u_char  *start;
 
     if (p == NULL) {
-        if (crypto->len >= 64) {
-            return crypto->len + 4;
-
-        } else {
-            return crypto->len + 3;
-        } // TODO: proper calculation of varint
+        return 3 + ngx_quic_varint_len(crypto->len) + crypto->len;
     }
 
     start = p;