Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a437d577 authored by Kweku Adams's avatar Kweku Adams Committed by Android (Google) Code Review
Browse files

Merge "incidentd: Fix printing of repeated scalar fields."

parents ed33dcb7 ee649598
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ using namespace std;
/**
 * Class to represent a protobuf Message, where we don't actually
 * know what any of the fields are, just their type codes. In other
 * words, this loslessly stores a parsed protobuf object without
 * words, this losslessly stores a parsed protobuf object without
 * having the .proto file that generated it.
 */
class GenericMessage
+19 −23
Original line number Diff line number Diff line
@@ -138,7 +138,6 @@ read_message(CodedInputStream* in, Descriptor const* descriptor, GenericMessage*
static void
print_value(Out* out, FieldDescriptor const* field, GenericMessage::Node const& node)
{
    uint32_t val32;
    FieldDescriptor::Type type = field->type();

    switch (node.type) {
@@ -160,23 +159,25 @@ print_value(Out* out, FieldDescriptor const* field, GenericMessage::Node const&
            break;
        case GenericMessage::TYPE_VALUE64:
            switch (type) {
                case FieldDescriptor::TYPE_FIXED64:
                case FieldDescriptor::TYPE_SFIXED64:
                case FieldDescriptor::TYPE_DOUBLE:
                    out->printf("%f", *(double*)&node.value64);
                    break;
                // Int32s here were added with addInt64 from a WIRETYPE_VARINT,
                // even if the definition is for a 32 bit int.
                case FieldDescriptor::TYPE_SINT32:
                case FieldDescriptor::TYPE_INT32:
                    val32 = (uint32_t)node.value32;
                    out->printf("%d", val32);
                    out->printf("%d", node.value64);
                    break;
                case FieldDescriptor::TYPE_INT64:
                case FieldDescriptor::TYPE_UINT32:
                    val32 = (uint32_t)node.value32;
                    out->printf("%u", val32);
                case FieldDescriptor::TYPE_SINT64:
                case FieldDescriptor::TYPE_SFIXED64:
                    out->printf("%lld", node.value64);
                    break;
                case FieldDescriptor::TYPE_UINT32:
                case FieldDescriptor::TYPE_UINT64:
                case FieldDescriptor::TYPE_SINT64:
                case FieldDescriptor::TYPE_FIXED64:
                    out->printf("%u", node.value64);
                    break;
                case FieldDescriptor::TYPE_BOOL:
                    if (node.value64) {
                        out->printf("true");
@@ -185,11 +186,15 @@ print_value(Out* out, FieldDescriptor const* field, GenericMessage::Node const&
                    }
                    break;
                case FieldDescriptor::TYPE_ENUM:
                    if (field->enum_type()->FindValueByNumber((int)node.value64) == NULL) {
                        out->printf("%lld", (int) node.value64);
                    } else {
                        out->printf("%s", field->enum_type()->FindValueByNumber((int)node.value64)
                            ->name().c_str());
                    }
                    break;
                default:
                    out->printf("(unexpected value64 %ld (0x%x))", node.value64, node.value64);
                    out->printf("(unexpected value64 %lld (0x%x))", node.value64, node.value64);
                    break;
            }
            break;
@@ -224,23 +229,14 @@ print_message(Out* out, Descriptor const* descriptor, GenericMessage const* mess
        out->printf("%s=", field->name().c_str());
        if (repeated) {
            if (it.first != it.second) {
                out->printf("[");
                if (type == FieldDescriptor::TYPE_MESSAGE
                        || type == FieldDescriptor::TYPE_STRING
                        || type == FieldDescriptor::TYPE_BYTES) {
                    out->printf("\n");
                }
                out->printf("[\n");
                out->indent();

                for (GenericMessage::const_iterator_pair it = message->find(fieldId);
                        it.first != it.second; it.first++) {
                    print_value(out, field, it.first->second);
                    if (type == FieldDescriptor::TYPE_MESSAGE
                            || type == FieldDescriptor::TYPE_STRING
                            || type == FieldDescriptor::TYPE_BYTES) {
                    out->printf("\n");
                }
                }

                out->dedent();
                out->printf("]");