xref: /aosp_15_r20/external/pigweed/pw_snapshot/public/pw_snapshot/uuid.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2021 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://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, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15 
16 #include <cstddef>
17 
18 #include "pw_bytes/span.h"
19 #include "pw_result/result.h"
20 #include "pw_span/span.h"
21 
22 namespace pw::snapshot {
23 
24 // Snapshot UUIDs are expected to be 128-bit.
25 //
26 // Note this is not strictly enforced anywhere, this is pure for convenience.
27 inline constexpr size_t kUuidSizeBytes = 16;
28 
29 using UuidSpan = span<std::byte, kUuidSizeBytes>;
30 using ConstUuidSpan = span<const std::byte, kUuidSizeBytes>;
31 
32 // Reads the snapshot UUID from an in memory snapshot, if present, and returns
33 // the subspan of `output` that contains the read snapshot.
34 //
35 // Returns:
36 //   OK - UUID found, status with size indicates number of bytes written to
37 //     `output`.
38 //   RESOURCE_EXHUASTED - UUID found, but `output` was too small to fit it.
39 //   NOT_FOUND - No snapshot UUID found in the provided snapshot.
40 Result<ConstByteSpan> ReadUuidFromSnapshot(ConstByteSpan snapshot,
41                                            UuidSpan output);
42 
43 }  // namespace pw::snapshot
44