Hash :
67e4aff5
Author :
Date :
2021-04-02T13:17:00
Fix rapidjson build error in Skia. Instead of using defines in the header, use the same approach as we do with frame capture by defining a stub "mock" cpp file. Bug: angleproject:5805 Change-Id: Ief1cb6497ddafc9656bb0e7d6a921eff3610a7fb Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2801695 Reviewed-by: Cody Northrop <cnorthrop@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// JsonSerializer.h: Implementation of a JSON based serializer
//
#ifndef LIBANGLE_JSONSERIALIZER_H_
#define LIBANGLE_JSONSERIALIZER_H_
#include "common/angleutils.h"
#if !defined(ANGLE_HAS_RAPIDJSON)
# error RapidJSON must be available to build this file.
#endif // !defined(ANGLE_HAVE_RAPIDJSON)
#include <rapidjson/document.h>
#include <memory>
#include <sstream>
#include <stack>
#include <type_traits>
namespace angle
{
// Rapidjson has problems picking the right AddMember template for long
// integer types, so let's just make these values use 64 bit variants
template <typename T>
struct StoreAs
{
using Type = T;
};
template <>
struct StoreAs<unsigned long>
{
using Type = uint64_t;
};
template <>
struct StoreAs<signed long>
{
using Type = int64_t;
};
class JsonSerializer : public angle::NonCopyable
{
public:
JsonSerializer();
~JsonSerializer();
void startDocument(const std::string &name);
void endDocument();
void addCString(const std::string &name, const char *value);
void addString(const std::string &name, const std::string &value);
void addBlob(const std::string &name, const uint8_t *value, size_t length);
void startGroup(const std::string &name);
void endGroup();
const char *data() const;
std::vector<uint8_t> getData() const;
size_t length() const;
template <typename T>
void addScalar(const std::string &name, T value)
{
rapidjson::Value tag(name.c_str(), mAllocator);
typename StoreAs<T>::Type v = value;
mGroupValueStack.top()->AddMember(tag, v, mAllocator);
}
template <typename T>
void addVector(const std::string &name, const std::vector<T> &value)
{
rapidjson::Value tag(name.c_str(), mAllocator);
rapidjson::Value array(rapidjson::kArrayType);
array.SetArray();
for (typename StoreAs<T>::Type v : value)
array.PushBack(v, mAllocator);
mGroupValueStack.top()->AddMember(tag, array, mAllocator);
}
private:
using ValuePointer = std::unique_ptr<rapidjson::Value>;
rapidjson::Document mDoc;
rapidjson::Document::AllocatorType &mAllocator;
std::stack<std::string> mGroupNameStack;
std::stack<ValuePointer> mGroupValueStack;
std::string mResult;
};
} // namespace angle
#endif // JSONSERIALIZER_H