#include <fstream>
#include <vector>
#ifdef _WIN32
-#include <io.h> //for _mktemp
+#include <io.h> // for _mktemp
#endif
#include "include/json/json.h"
#include "tensorflow/core/lib/core/errors.h"
Status ParseJson(StringPiece json, Json::Value* result) {
Json::Reader reader;
- if (!reader.parse(json.ToString(), *result)) {
+ if (!reader.parse(json.data(), json.data() + json.size(), *result)) {
return errors::Internal("Couldn't parse JSON response from GCS.");
}
return Status::OK();
}
+Status ParseJson(const std::vector<char>& json, Json::Value* result) {
+ return ParseJson(StringPiece{json.data(), json.size()}, result);
+}
+
/// Reads a JSON value with the given name from a parent JSON value.
-Status GetValue(const Json::Value& parent, const string& name,
+Status GetValue(const Json::Value& parent, const char* name,
Json::Value* result) {
*result = parent.get(name, Json::Value::null);
- if (*result == Json::Value::null) {
+ if (result->isNull()) {
return errors::Internal("The field '", name,
"' was expected in the JSON response.");
}
}
/// Reads a string JSON value with the given name from a parent JSON value.
-Status GetStringValue(const Json::Value& parent, const string& name,
+Status GetStringValue(const Json::Value& parent, const char* name,
string* result) {
Json::Value result_value;
TF_RETURN_IF_ERROR(GetValue(parent, name, &result_value));
}
/// Reads a long JSON value with the given name from a parent JSON value.
-Status GetInt64Value(const Json::Value& parent, const string& name,
+Status GetInt64Value(const Json::Value& parent, const char* name,
int64* result) {
Json::Value result_value;
TF_RETURN_IF_ERROR(GetValue(parent, name, &result_value));
return Status::OK();
}
if (result_value.isString() &&
- strings::safe_strto64(result_value.asString().c_str(), result)) {
+ strings::safe_strto64(result_value.asCString(), result)) {
return Status::OK();
}
return errors::Internal(
}
/// Reads a boolean JSON value with the given name from a parent JSON value.
-Status GetBoolValue(const Json::Value& parent, const string& name,
- bool* result) {
+Status GetBoolValue(const Json::Value& parent, const char* name, bool* result) {
Json::Value result_value;
TF_RETURN_IF_ERROR(GetValue(parent, name, &result_value));
if (!result_value.isBool()) {
" when reading metadata of gs://",
bucket, "/", object);
- StringPiece response_piece =
- StringPiece(output_buffer.data(), output_buffer.size());
Json::Value root;
- TF_RETURN_IF_ERROR(ParseJson(response_piece, &root));
+ TF_RETURN_IF_ERROR(ParseJson(output_buffer, &root));
// Parse file size.
- TF_RETURN_IF_ERROR(GetInt64Value(root, "size", &(stat->length)));
+ TF_RETURN_IF_ERROR(GetInt64Value(root, "size", &stat->length));
// Parse file modification time.
string updated;
TF_RETURN_WITH_CONTEXT_IF_ERROR(request->Send(), " when reading ", dirname);
Json::Value root;
- StringPiece response_piece =
- StringPiece(output_buffer.data(), output_buffer.size());
- TF_RETURN_IF_ERROR(ParseJson(response_piece, &root));
+ TF_RETURN_IF_ERROR(ParseJson(output_buffer, &root));
const auto items = root.get("items", Json::Value::null);
- if (items != Json::Value::null) {
+ if (!items.isNull()) {
if (!items.isArray()) {
return errors::Internal(
"Expected an array 'items' in the GCS response.");
}
}
const auto prefixes = root.get("prefixes", Json::Value::null);
- if (prefixes != Json::Value::null) {
+ if (!prefixes.isNull()) {
// Subfolders are returned for the non-recursive mode.
if (!prefixes.isArray()) {
return errors::Internal(
}
for (size_t i = 0; i < prefixes.size(); i++) {
const auto prefix = prefixes.get(i, Json::Value::null);
- if (prefix == Json::Value::null || !prefix.isString()) {
+ if (prefix.isNull() || !prefix.isString()) {
return errors::Internal(
"'prefixes' was expected to be an array of strings in the GCS "
"response.");
}
}
const auto token = root.get("nextPageToken", Json::Value::null);
- if (token == Json::Value::null) {
+ if (token.isNull()) {
return Status::OK();
}
if (!token.isString()) {
// DeleteFile call below.
file_block_cache_->RemoveFile(target);
Json::Value root;
- StringPiece response_piece =
- StringPiece(output_buffer.data(), output_buffer.size());
- TF_RETURN_IF_ERROR(ParseJson(response_piece, &root));
+ TF_RETURN_IF_ERROR(ParseJson(output_buffer, &root));
bool done;
TF_RETURN_IF_ERROR(GetBoolValue(root, "done", &done));
if (!done) {