Longfellow ZK 0290cb32
Loading...
Searching...
No Matches
serialization.h
1// Copyright 2025 Google LLC.
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.
14
15#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_SERIALIZATION_H_
16#define PRIVACY_PROOFS_ZK_LIB_UTIL_SERIALIZATION_H_
17
18#include <cstdint>
19
20namespace proofs {
21
22static inline void u64_to_le(uint8_t a[/*8*/], uint64_t x) {
23 a[0] = x & 0xffu;
24 a[1] = (x >> 8) & 0xffu;
25 a[2] = (x >> 16) & 0xffu;
26 a[3] = (x >> 24) & 0xffu;
27 a[4] = (x >> 32) & 0xffu;
28 a[5] = (x >> 40) & 0xffu;
29 a[6] = (x >> 48) & 0xffu;
30 a[7] = (x >> 56) & 0xffu;
31}
32
33static inline uint64_t u64_of_le(const uint8_t a[/*8*/]) {
34 return ((uint64_t)a[7] << 56) | ((uint64_t)a[6] << 48) |
35 ((uint64_t)a[5] << 40) | ((uint64_t)a[4] << 32) |
36 ((uint64_t)a[3] << 24) | ((uint64_t)a[2] << 16) |
37 ((uint64_t)a[1] << 8) | (uint64_t)a[0];
38}
39
40static inline void u32_to_le(uint8_t a[/*4*/], uint32_t x) {
41 a[0] = x & 0xffu;
42 a[1] = (x >> 8) & 0xffu;
43 a[2] = (x >> 16) & 0xffu;
44 a[3] = (x >> 24) & 0xffu;
45}
46
47static inline uint32_t u32_of_le(const uint8_t a[/*4*/]) {
48 return ((uint32_t)a[3] << 24) | ((uint32_t)a[2] << 16) |
49 ((uint32_t)a[1] << 8) | (uint32_t)a[0];
50}
51
52} // namespace proofs
53
54#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_SERIALIZATION_H_