aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/util/json_util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/util/json_util.cc')
-rw-r--r--src/google/protobuf/util/json_util.cc28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc
index 129b6eaf..f81a7a30 100644
--- a/src/google/protobuf/util/json_util.cc
+++ b/src/google/protobuf/util/json_util.cc
@@ -50,7 +50,9 @@ namespace util {
namespace internal {
ZeroCopyStreamByteSink::~ZeroCopyStreamByteSink() {
- stream_->BackUp(buffer_size_);
+ if (buffer_size_ > 0) {
+ stream_->BackUp(buffer_size_);
+ }
}
void ZeroCopyStreamByteSink::Append(const char* bytes, size_t len) {
@@ -61,9 +63,11 @@ void ZeroCopyStreamByteSink::Append(const char* bytes, size_t len) {
buffer_size_ -= len;
return;
}
- memcpy(buffer_, bytes, buffer_size_);
- bytes += buffer_size_;
- len -= buffer_size_;
+ if (buffer_size_ > 0) {
+ memcpy(buffer_, bytes, buffer_size_);
+ bytes += buffer_size_;
+ len -= buffer_size_;
+ }
if (!stream_->Next(&buffer_, &buffer_size_)) {
// There isn't a way for ByteSink to report errors.
buffer_size_ = 0;
@@ -83,12 +87,18 @@ util::Status BinaryToJsonStream(TypeResolver* resolver,
RETURN_IF_ERROR(resolver->ResolveMessageType(type_url, &type));
converter::ProtoStreamObjectSource proto_source(&in_stream, resolver, type);
proto_source.set_use_ints_for_enums(options.always_print_enums_as_ints);
+ proto_source.set_preserve_proto_field_names(
+ options.preserve_proto_field_names);
io::CodedOutputStream out_stream(json_output);
converter::JsonObjectWriter json_writer(options.add_whitespace ? " " : "",
&out_stream);
if (options.always_print_primitive_fields) {
converter::DefaultValueObjectWriter default_value_writer(
resolver, type, &json_writer);
+ default_value_writer.set_preserve_proto_field_names(
+ options.preserve_proto_field_names);
+ default_value_writer.set_print_enums_as_ints(
+ options.always_print_enums_as_ints);
return proto_source.WriteTo(&default_value_writer);
} else {
return proto_source.WriteTo(&json_writer);
@@ -109,7 +119,7 @@ util::Status BinaryToJsonString(TypeResolver* resolver,
namespace {
class StatusErrorListener : public converter::ErrorListener {
public:
- StatusErrorListener() : status_(util::Status::OK) {}
+ StatusErrorListener() {}
virtual ~StatusErrorListener() {}
util::Status GetStatus() { return status_; }
@@ -117,22 +127,22 @@ class StatusErrorListener : public converter::ErrorListener {
virtual void InvalidName(const converter::LocationTrackerInterface& loc,
StringPiece unknown_name, StringPiece message) {
status_ = util::Status(util::error::INVALID_ARGUMENT,
- loc.ToString() + ": " + message.ToString());
+ loc.ToString() + ": " + string(message));
}
virtual void InvalidValue(const converter::LocationTrackerInterface& loc,
StringPiece type_name, StringPiece value) {
status_ =
util::Status(util::error::INVALID_ARGUMENT,
- loc.ToString() + ": invalid value " + value.ToString() +
- " for type " + type_name.ToString());
+ loc.ToString() + ": invalid value " + string(value) +
+ " for type " + string(type_name));
}
virtual void MissingField(const converter::LocationTrackerInterface& loc,
StringPiece missing_name) {
status_ = util::Status(
util::error::INVALID_ARGUMENT,
- loc.ToString() + ": missing field " + missing_name.ToString());
+ loc.ToString() + ": missing field " + string(missing_name));
}
private: