chromium/third_party/openscreen/src/util/json/json_helpers.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UTIL_JSON_JSON_HELPERS_H_
#define UTIL_JSON_JSON_HELPERS_H_

#include <chrono>
#include <cmath>
#include <functional>
#include <string>
#include <utility>
#include <vector>

#include "json/value.h"
#include "platform/base/error.h"
#include "util/chrono_helpers.h"
#include "util/json/json_serialization.h"
#include "util/simple_fraction.h"

// This file contains helper methods for parsing JSON, in an attempt to
// reduce boilerplate code when working with JsonCpp.
namespace openscreen::json {

inline bool TryParseBool(const Json::Value& value, bool* out) {}

// A general note about parsing primitives. "Validation" in this context
// generally means ensuring that the values are non-negative, excepting doubles
// which may be negative in some cases.
inline bool TryParseDouble(const Json::Value& value,
                           double* out,
                           bool allow_negative = false) {}

inline bool TryParseInt(const Json::Value& value, int* out) {}

inline bool TryParseUint(const Json::Value& value, uint32_t* out) {}

inline bool TryParseString(const Json::Value& value, std::string* out) {}

// We want to be more robust when we parse fractions then just
// allowing strings, this will parse numeral values such as
// value: 50 as well as value: "50" and value: "100/2".
inline bool TryParseSimpleFraction(const Json::Value& value,
                                   SimpleFraction* out) {}

inline bool TryParseMilliseconds(const Json::Value& value, milliseconds* out) {}

Parser;

// NOTE: array parsing methods reset the output vector to an empty vector in
// any error case. This is especially useful for optional arrays.
template <typename T>
bool TryParseArray(const Json::Value& value,
                   Parser<T> parser,
                   std::vector<T>* out) {}

inline bool TryParseIntArray(const Json::Value& value, std::vector<int>* out) {}

inline bool TryParseUintArray(const Json::Value& value,
                              std::vector<uint32_t>* out) {}

inline bool TryParseStringArray(const Json::Value& value,
                                std::vector<std::string>* out) {}

template <typename T>
Json::Value PrimitiveVectorToJson(const std::vector<T>& vec) {}

}  // namespace openscreen::json

#endif  // UTIL_JSON_JSON_HELPERS_H_