Search in sources :

Example 1 with UnknownFieldSetLite

use of com.google.protobuf.UnknownFieldSetLite in project Signal-Android by WhisperSystems.

the class ProtoUtil method hasUnknownFields.

/**
 * True if there are unknown fields anywhere inside the proto or its nested protos.
 */
@SuppressWarnings("rawtypes")
public static boolean hasUnknownFields(GeneratedMessageLite rootProto) {
    try {
        List<GeneratedMessageLite> allProtos = getInnerProtos(rootProto);
        allProtos.add(rootProto);
        for (GeneratedMessageLite proto : allProtos) {
            Field field = GeneratedMessageLite.class.getDeclaredField("unknownFields");
            field.setAccessible(true);
            UnknownFieldSetLite unknownFields = (UnknownFieldSetLite) field.get(proto);
            if (unknownFields != null && unknownFields.getSerializedSize() > 0) {
                return true;
            }
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        Log.w(TAG, "Failed to read proto private fields! Assuming no unknown fields.");
    }
    return false;
}
Also used : GeneratedMessageLite(com.google.protobuf.GeneratedMessageLite) Field(java.lang.reflect.Field) UnknownFieldSetLite(com.google.protobuf.UnknownFieldSetLite)

Example 2 with UnknownFieldSetLite

use of com.google.protobuf.UnknownFieldSetLite in project Signal-Android by signalapp.

the class ProtoUtil method hasUnknownFields.

/**
 * True if there are unknown fields anywhere inside the proto or its nested protos.
 */
@SuppressWarnings("rawtypes")
public static boolean hasUnknownFields(GeneratedMessageLite rootProto) {
    try {
        List<GeneratedMessageLite> allProtos = getInnerProtos(rootProto);
        allProtos.add(rootProto);
        for (GeneratedMessageLite proto : allProtos) {
            Field field = GeneratedMessageLite.class.getDeclaredField("unknownFields");
            field.setAccessible(true);
            UnknownFieldSetLite unknownFields = (UnknownFieldSetLite) field.get(proto);
            if (unknownFields != null && unknownFields.getSerializedSize() > 0) {
                return true;
            }
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        Log.w(TAG, "Failed to read proto private fields! Assuming no unknown fields.");
    }
    return false;
}
Also used : GeneratedMessageLite(com.google.protobuf.GeneratedMessageLite) Field(java.lang.reflect.Field) UnknownFieldSetLite(com.google.protobuf.UnknownFieldSetLite)

Aggregations

GeneratedMessageLite (com.google.protobuf.GeneratedMessageLite)2 UnknownFieldSetLite (com.google.protobuf.UnknownFieldSetLite)2 Field (java.lang.reflect.Field)2