public long extractTimestampMillis(String topic, final byte[] bytes) throws IOException { if (timestampFieldPath != null) { com.google.protobuf.Message decodedMessage = protobufUtil.decodeMessage(topic, bytes); int i = 0; for (; i < timestampFieldPath.length - 1; ++i) { decodedMessage = (com.google.protobuf.Message) decodedMessage.getField( decodedMessage.getDescriptorForType().findFieldByName(timestampFieldPath[i])); } Object timestampObject = decodedMessage.getField( decodedMessage.getDescriptorForType().findFieldByName(timestampFieldPath[i])); if (timestampObject instanceof com.google.protobuf.Timestamp) { return Timestamps.toMillis((com.google.protobuf.Timestamp) timestampObject); } else { return toMillis((Long) timestampObject); } } else { // Assume that the timestamp field is the first field, is required, // and is a uint64. CodedInputStream input = CodedInputStream.newInstance(bytes); // Don't really care about the tag, but need to read it to get, to // the payload. input.readTag(); return toMillis(input.readUInt64()); } }
@Override public String getValue(Message msg) { return (String) msg.getField( ProtoBufFieldProcessor.getFieldDescriptor( AppClass.getDefaultInstance(), AppClass.ID_FIELD_NUMBER)); }
public static Object getFieldByName(Message message, String name) { return message.getField(message.getDescriptorForType().findFieldByName(name)); }