Debian Codegraph @

libs/woff2/src/store_bytes.h

raw
1 /* Copyright 2013 Google Inc. All Rights Reserved.
2
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6
7 /* Helper functions for storing integer values into byte streams.
8 No bounds checking is performed, that is the responsibility of the caller. */
9
10 #ifndef WOFF2_STORE_BYTES_H_
11 #define WOFF2_STORE_BYTES_H_
12
13 #include <inttypes.h>
14 #include <stddef.h>
15 #include <string.h>
16
17 #include "./port.h"
18
19 namespace woff2 {
20
21 inline size_t StoreU32(uint8_t* dst, size_t offset, uint32_t x) {
22 dst[offset] = x >> 24;
23 dst[offset + 1] = x >> 16;
24 dst[offset + 2] = x >> 8;
25 dst[offset + 3] = x;
26 return offset + 4;
27 }
28
29 inline size_t Store16(uint8_t* dst, size_t offset, int x) {
30 dst[offset] = x >> 8;
31 dst[offset + 1] = x;
32 return offset + 2;
33 }
34
35 inline void StoreU32(uint32_t val, size_t* offset, uint8_t* dst) {
36 dst[(*offset)++] = val >> 24;
37 dst[(*offset)++] = val >> 16;
38 dst[(*offset)++] = val >> 8;
39 dst[(*offset)++] = val;
40 }
41
42 inline void Store16(int val, size_t* offset, uint8_t* dst) {
43 dst[(*offset)++] = val >> 8;
44 dst[(*offset)++] = val;
45 }
46
47 inline void StoreBytes(const uint8_t* data, size_t len,
48 size_t* offset, uint8_t* dst) {
49 memcpy(&dst[*offset], data, len);
50 *offset += len;
51 }
52
53 } // namespace woff2
54
55 #endif // WOFF2_STORE_BYTES_H_