Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f
[chromium-blink-merge.git] / third_party / woff2 / src / store_bytes.h
bloba9a3401677516ce5e050c936e87d49b4d8885d79
1 // Copyright 2013 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // Helper functions for storing integer values into byte streams.
16 // No bounds checking is performed, that is the responsibility of the caller.
18 #ifndef WOFF2_STORE_BYTES_H_
19 #define WOFF2_STORE_BYTES_H_
21 #include <inttypes.h>
22 #include <stddef.h>
23 #include <string.h>
25 namespace woff2 {
27 inline size_t StoreU32(uint8_t* dst, size_t offset, uint32_t x) {
28 dst[offset] = x >> 24;
29 dst[offset + 1] = x >> 16;
30 dst[offset + 2] = x >> 8;
31 dst[offset + 3] = x;
32 return offset + 4;
35 inline size_t Store16(uint8_t* dst, size_t offset, int x) {
36 dst[offset] = x >> 8;
37 dst[offset + 1] = x;
38 return offset + 2;
41 inline void StoreU32(uint32_t val, size_t* offset, uint8_t* dst) {
42 dst[(*offset)++] = val >> 24;
43 dst[(*offset)++] = val >> 16;
44 dst[(*offset)++] = val >> 8;
45 dst[(*offset)++] = val;
48 inline void Store16(int val, size_t* offset, uint8_t* dst) {
49 dst[(*offset)++] = val >> 8;
50 dst[(*offset)++] = val;
53 inline void StoreBytes(const uint8_t* data, size_t len,
54 size_t* offset, uint8_t* dst) {
55 memcpy(&dst[*offset], data, len);
56 *offset += len;
59 } // namespace woff2
61 #endif // WOFF2_STORE_BYTES_H_