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

Unified Diff: tools/json_schema_compiler/cc_generator.py

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
Index: tools/json_schema_compiler/cc_generator.py
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py
index 22bb3715b9c4037a83d5fc36d676a7817f654089..db832bef9eac39426f0247d82130804b6bcdbacf 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -43,6 +43,7 @@ class _Generator(object):
.Append()
.Append(self._util_cc_helper.GetIncludePath())
.Append('#include "base/logging.h"')
+ .Append('#include "base/stl_util.h"')
.Append('#include "base/strings/string_number_conversions.h"')
.Append('#include "base/strings/utf_string_conversions.h"')
.Append('#include "%s/%s.h"' %
@@ -160,7 +161,7 @@ class _Generator(object):
items.append('%s(false)' % prop.unix_name)
elif (t.property_type == PropertyType.ANY or
t.property_type == PropertyType.ARRAY or
- t.property_type == PropertyType.BINARY or # mapped to std::string
+ t.property_type == PropertyType.BINARY or
t.property_type == PropertyType.CHOICES or
t.property_type == PropertyType.OBJECT or
t.property_type == PropertyType.FUNCTION or
@@ -541,10 +542,12 @@ class _Generator(object):
elif underlying_type.property_type == PropertyType.BINARY:
if is_ptr:
vardot = var + '->'
+ ref = var + '.get()'
else:
vardot = var + '.'
- return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' %
- (vardot, vardot))
+ ref = '&' + var
+ return ('base::BinaryValue::CreateWithCopiedBuffer(vector_as_array(%s),'
+ ' %ssize())' % (ref, vardot))
elif underlying_type.property_type == PropertyType.ARRAY:
return '%s.release()' % self._util_cc_helper.CreateValueFromArray(
var,
@@ -807,13 +810,14 @@ class _Generator(object):
.Append(' static_cast<const base::BinaryValue*>(%(src_var)s);')
)
if is_ptr:
- (c.Append('%(dst_var)s.reset(')
- .Append(' new std::string(binary_value->GetBuffer(),')
- .Append(' binary_value->GetSize()));')
+ (c.Append('%(dst_var)s.reset(new std::vector<char>(')
+ .Append(' binary_value->GetBuffer(),')
+ .Append(' binary_value->GetBuffer() + binary_value->GetSize()));')
)
else:
- (c.Append('%(dst_var)s.assign(binary_value->GetBuffer(),')
- .Append(' binary_value->GetSize());')
+ (c.Append('%(dst_var)s.assign(')
+ .Append(' binary_value->GetBuffer(),')
+ .Append(' binary_value->GetBuffer() + binary_value->GetSize());')
)
c.Eblock('}')
else:
« no previous file with comments | « extensions/browser/api/vpn_provider/vpn_service.cc ('k') | tools/json_schema_compiler/cpp_type_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698