Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Unified Diff: tools/json_schema_compiler/util.cc

Issue 820673004: json_schema_compiler: Use std::vector<char> for binary values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplify_json_schema
Patch Set: Fix merge error. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/json_schema_compiler/util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/util.cc
diff --git a/tools/json_schema_compiler/util.cc b/tools/json_schema_compiler/util.cc
index 40dbe68c1f1274a0b09ca8e6141e876e69e6aea8..3e36cfc7a6957c7226fa0c5b2b10e78a7a6a104e 100644
--- a/tools/json_schema_compiler/util.cc
+++ b/tools/json_schema_compiler/util.cc
@@ -4,6 +4,7 @@
#include "tools/json_schema_compiler/util.h"
+#include "base/stl_util.h"
#include "base/values.h"
namespace json_schema_compiler {
@@ -25,6 +26,14 @@ bool PopulateItem(const base::Value& from, std::string* out) {
return from.GetAsString(out);
}
+bool PopulateItem(const base::Value& from, std::vector<char>* out) {
+ const base::BinaryValue* binary = nullptr;
+ if (!from.GetAsBinary(&binary))
+ return false;
+ out->assign(binary->GetBuffer(), binary->GetBuffer() + binary->GetSize());
+ return true;
+}
+
bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out) {
*out = make_linked_ptr(from.DeepCopy());
return true;
@@ -32,7 +41,7 @@ bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out) {
bool PopulateItem(const base::Value& from,
linked_ptr<base::DictionaryValue>* out) {
- const base::DictionaryValue* dict = NULL;
+ const base::DictionaryValue* dict = nullptr;
if (!from.GetAsDictionary(&dict))
return false;
*out = make_linked_ptr(dict->DeepCopy());
@@ -55,6 +64,11 @@ void AddItemToList(const std::string& from, base::ListValue* out) {
out->Append(new base::StringValue(from));
}
+void AddItemToList(const std::vector<char>& from, base::ListValue* out) {
+ out->Append(base::BinaryValue::CreateWithCopiedBuffer(vector_as_array(&from),
+ from.size()));
+}
+
void AddItemToList(const linked_ptr<base::Value>& from, base::ListValue* out) {
out->Append(from->DeepCopy());
}
@@ -87,5 +101,5 @@ std::string ValueTypeToString(base::Value::Type type) {
return "";
}
-} // namespace api_util
-} // namespace extensions
+} // namespace util
+} // namespace json_schema_compiler
« no previous file with comments | « tools/json_schema_compiler/util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698