/src/mosquitto/libcommon/mqtt_common.c
Line | Count | Source |
1 | | /* |
2 | | Copyright (c) 2009-2021 Roger Light <roger@atchoo.org> |
3 | | |
4 | | All rights reserved. This program and the accompanying materials |
5 | | are made available under the terms of the Eclipse Public License 2.0 |
6 | | and Eclipse Distribution License v1.0 which accompany this distribution. |
7 | | |
8 | | The Eclipse Public License is available at |
9 | | https://www.eclipse.org/legal/epl-2.0/ |
10 | | and the Eclipse Distribution License is available at |
11 | | http://www.eclipse.org/org/documents/edl-v10.php. |
12 | | |
13 | | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause |
14 | | |
15 | | Contributors: |
16 | | Roger Light - initial implementation and documentation. |
17 | | */ |
18 | | |
19 | | #include "config.h" |
20 | | |
21 | | #include <stdint.h> |
22 | | |
23 | | #include "mosquitto.h" |
24 | | |
25 | | |
26 | | unsigned int mosquitto_varint_bytes(uint32_t word) |
27 | 19.9M | { |
28 | 19.9M | if(word < 128){ |
29 | 19.9M | return 1; |
30 | 19.9M | }else if(word < 16384){ |
31 | 218 | return 2; |
32 | 526 | }else if(word < 2097152){ |
33 | 184 | return 3; |
34 | 342 | }else if(word < 268435456){ |
35 | 342 | return 4; |
36 | 342 | }else{ |
37 | 0 | return 5; |
38 | 0 | } |
39 | 19.9M | } |