iceberg-cpp
Loading...
Searching...
No Matches
uuid.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <array>
23#include <cstdint>
24#include <span>
25#include <string_view>
26
27#include "iceberg/iceberg_export.h"
28#include "iceberg/result.h"
30
33
34namespace iceberg {
35
36class ICEBERG_EXPORT Uuid : public util::Formattable {
37 public:
38 Uuid() = delete;
39 constexpr static size_t kLength = 16;
40
41 explicit Uuid(std::array<uint8_t, kLength> data);
42
44 static Uuid GenerateV4();
45
47 static Uuid GenerateV7();
48
57 static Uuid GenerateV7(uint64_t unix_ts_ms);
58
60 static Result<Uuid> FromString(std::string_view str);
61
63 static Result<Uuid> FromBytes(std::span<const uint8_t> bytes);
64
66 std::span<const uint8_t> bytes() const { return data_; }
67
72 uint8_t operator[](size_t index) const;
73
75 std::string ToString() const override;
76
77 friend bool operator==(const Uuid& lhs, const Uuid& rhs) {
78 return lhs.data_ == rhs.data_;
79 }
80
81 int64_t high_bits() const;
82 int64_t low_bits() const;
83
84 private:
85 std::array<uint8_t, kLength> data_;
86};
87
88} // namespace iceberg
Definition uuid.h:36
std::span< const uint8_t > bytes() const
Get the raw bytes of the UUID.
Definition uuid.h:66
Interface for objects that can be formatted via std::format.
Definition formattable.h:36