Thanks to visit codestin.com
Credit goes to chromium.googlesource.com

blob: d5dfdceae64364524936f451b903afed40facea6 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2019 The Chromium Authors
Albert J. Wongf60c8d22021-07-27 07:25:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_JSON_VALUES_UTIL_H_
6#define BASE_JSON_VALUES_UTIL_H_
7
Arthur Sonzognie5fff99c2024-02-21 15:58:248#include <optional>
9
Albert J. Wongf60c8d22021-07-27 07:25:2610#include "base/base_export.h"
11#include "base/values.h"
Albert J. Wongf60c8d22021-07-27 07:25:2612
13namespace base {
14class FilePath;
15class Time;
16class TimeDelta;
17class UnguessableToken;
18
19// Simple helper functions for converting between Value and other types.
20// The Value representation is stable, suitable for persistent storage
21// e.g. as JSON on disk.
22//
23// It is valid to pass nullptr to the ValueToEtc functions. They will just
Arthur Sonzognie5fff99c2024-02-21 15:58:2424// return std::nullopt.
Albert J. Wongf60c8d22021-07-27 07:25:2625
26// Converts between an int64_t and a string-flavored Value (a human
27// readable string of that number).
28BASE_EXPORT Value Int64ToValue(int64_t integer);
Arthur Sonzognie5fff99c2024-02-21 15:58:2429BASE_EXPORT std::optional<int64_t> ValueToInt64(const Value* value);
30BASE_EXPORT std::optional<int64_t> ValueToInt64(const Value& value);
Albert J. Wongf60c8d22021-07-27 07:25:2631
32// Converts between a TimeDelta (an int64_t number of microseconds) and a
33// string-flavored Value (a human readable string of that number).
34BASE_EXPORT Value TimeDeltaToValue(TimeDelta time_delta);
Arthur Sonzognie5fff99c2024-02-21 15:58:2435BASE_EXPORT std::optional<TimeDelta> ValueToTimeDelta(const Value* value);
36BASE_EXPORT std::optional<TimeDelta> ValueToTimeDelta(const Value& value);
Albert J. Wongf60c8d22021-07-27 07:25:2637
38// Converts between a Time (an int64_t number of microseconds since the
39// Windows epoch) and a string-flavored Value (a human readable string of
40// that number).
41BASE_EXPORT Value TimeToValue(Time time);
Arthur Sonzognie5fff99c2024-02-21 15:58:2442BASE_EXPORT std::optional<Time> ValueToTime(const Value* value);
43BASE_EXPORT std::optional<Time> ValueToTime(const Value& value);
Albert J. Wongf60c8d22021-07-27 07:25:2644
45// Converts between a FilePath (a std::string or std::u16string) and a
46// string-flavored Value (the UTF-8 representation).
Tom Sepez335ca782024-10-31 21:29:5247BASE_EXPORT Value FilePathToValue(const FilePath& file_path);
Arthur Sonzognie5fff99c2024-02-21 15:58:2448BASE_EXPORT std::optional<FilePath> ValueToFilePath(const Value* value);
49BASE_EXPORT std::optional<FilePath> ValueToFilePath(const Value& value);
Albert J. Wongf60c8d22021-07-27 07:25:2650
51// Converts between a UnguessableToken (128 bits) and a string-flavored
52// Value (32 hexadecimal digits).
53BASE_EXPORT Value UnguessableTokenToValue(UnguessableToken token);
Arthur Sonzognie5fff99c2024-02-21 15:58:2454BASE_EXPORT std::optional<UnguessableToken> ValueToUnguessableToken(
Albert J. Wongf60c8d22021-07-27 07:25:2655 const Value* value);
Arthur Sonzognie5fff99c2024-02-21 15:58:2456BASE_EXPORT std::optional<UnguessableToken> ValueToUnguessableToken(
Albert J. Wongf60c8d22021-07-27 07:25:2657 const Value& value);
58
59} // namespace base
60
61#endif // BASE_JSON_VALUES_UTIL_H_