blob: 3efbfcd05573086fea5da7dfb3eb6e5468d94fde [file] [log] [blame]
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include <fuchsia/ledger/cloud/cpp/fidl.h>
#include <google/firestore/v1beta1/document.pb.h>
#include <lib/fidl/cpp/vector.h>
#include <lib/fxl/strings/string_view.h>
#include "peridot/bin/cloud_provider_firestore/include/types.h"
#include "peridot/lib/commit_pack/commit_pack.h"
namespace cloud_provider_firestore {
// Encodes the data so that it can be used as a Firestore key.
// The resulting encoding is base64url with a single '+' character appended at
// the end. This is because Firestore disallows keys matching the regular
// expression `__.*__` which would otherwise be possible to produce.
// See
std::string EncodeKey(fxl::StringView input);
// Decodes a Firestore key encoded using |EncodeKey|.
bool DecodeKey(fxl::StringView input, std::string* output);
// Encodes a batch of commits in the cloud provider FIDL format as a Firestore
// document.
bool EncodeCommitBatch(const cloud_provider::CommitPack& commits,
google::firestore::v1beta1::Document* document);
// Decodes a Firestore document representing a commit batch.
bool DecodeCommitBatch(
const google::firestore::v1beta1::Document& document,
std::vector<cloud_provider::CommitPackEntry>* commit_entries,
std::string* timestamp);
} // namespace cloud_provider_firestore