/** Compare the two non-null messages, and return a detailed comparison report. */ DiffResult diffMessages(Message actual, Message expected) { checkNotNull(actual); checkNotNull(expected); checkArgument( actual.getDescriptorForType() == expected.getDescriptorForType(), "The actual [%s] and expected [%s] message descriptors do not match.", actual.getDescriptorForType(), expected.getDescriptorForType()); return diffMessages(actual, expected, rootConfig); }
/** * Set the "X-Protobuf-*" HTTP headers when responding with a message of * content type "application/x-protobuf" * <p><b>Note:</b> <code>outputMessage.getBody()</code> should not have been called * before because it writes HTTP headers (making them read only).</p> */ private void setProtoHeader(HttpOutputMessage response, Message message) { response.getHeaders().set(X_PROTOBUF_SCHEMA_HEADER, message.getDescriptorForType().getFile().getName()); response.getHeaders().set(X_PROTOBUF_MESSAGE_HEADER, message.getDescriptorForType().getFullName()); }
static MessageType of(Message message) { MessageType type = TYPES_BY_CLASS.get(message.getClass()); if (type == null) { type = new MessageType(message.getDescriptorForType()); TYPES_BY_CLASS.put(message.getClass(), type); } return type; } }
private static Iterable<String> getDescriptors(Iterable<? extends Message> messages) { List<String> descriptors = Lists.newArrayList(); for (Message message : messages) { descriptors.add(message == null ? "null" : message.getDescriptorForType().getFullName()); } return descriptors; }
public FieldDescriptor getDescriptor() { return scope.getDescriptorForType().getExtensions() .get(descriptorIndex); } },
private static boolean notMessagesWithSameDescriptor( @NullableDecl Message actual, @NullableDecl Object expected) { if (actual != null && expected instanceof Message) { return actual.getDescriptorForType() != ((Message) expected).getDescriptorForType(); } return true; }
@Override protected FieldDescriptor loadDescriptor() { return scope.getDescriptorForType().findFieldByName(name); } },
@Override public FieldDescriptor loadDescriptor() { return scope.getDescriptorForType().getExtensions().get(descriptorIndex); } },
RootPartialScopeLogic(Message message) { super(FieldNumberTree.fromMessage(message)); this.message = message; this.expectedDescriptor = message.getDescriptorForType(); }
@Override protected Schema getRecordSchema(Object record) { Descriptor descriptor = ((Message)record).getDescriptorForType(); Schema schema = schemaCache.get(descriptor); if (schema == null) { schema = getSchema(descriptor); schemaCache.put(descriptor, schema); } return schema; }
/** * Set the "X-Protobuf-*" HTTP headers when responding with a message of * content type "application/x-protobuf" * <p><b>Note:</b> <code>outputMessage.getBody()</code> should not have been called * before because it writes HTTP headers (making them read only).</p> */ private void setProtoHeader(HttpOutputMessage response, Message message) { response.getHeaders().set(X_PROTOBUF_SCHEMA_HEADER, message.getDescriptorForType().getFile().getName()); response.getHeaders().set(X_PROTOBUF_MESSAGE_HEADER, message.getDescriptorForType().getFullName()); }
/** * Construct a {@link Message.Builder} for a message of the same type as * {@code prototype}, and initialize it with {@code prototype}'s contents. */ public static Builder newBuilder(Message prototype) { return new Builder(prototype.getDescriptorForType()).mergeFrom(prototype); }
private static Map<Object, Object> toProtoMap(@NullableDecl Object container) { if (container == null) { return Collections.emptyMap(); } List<?> entryMessages = (List<?>) container; Map<Object, Object> retVal = Maps.newHashMap(); for (Object entry : entryMessages) { Message message = (Message) entry; Object key = message.getAllFields().get(message.getDescriptorForType().findFieldByNumber(1)); Object value = message.getAllFields().get(message.getDescriptorForType().findFieldByNumber(2)); retVal.put(key, value); } return retVal; }
/** * Construct a {@link Message.Builder} for a message of the same type as * {@code prototype}, and initialize it with {@code prototype}'s contents. */ public static Builder newBuilder(Message prototype) { return new Builder(prototype.getDescriptorForType()).mergeFrom(prototype); }
private ProtoTruthMessageDifferencer makeDifferencer(Message expected) { return config .withExpectedMessages(Arrays.asList(expected)) .toMessageDifferencer(actual().getDescriptorForType()); }
public <T extends com.google.protobuf.Message> boolean is( java.lang.Class<T> clazz) { T defaultInstance = com.google.protobuf.Internal.getDefaultInstance(clazz); return getTypeNameFromTypeUrl(getTypeUrl()).equals( defaultInstance.getDescriptorForType().getFullName()); }
@Override public final String formatDiff(@NullableDecl M actual, @NullableDecl M expected) { if (actual == null || expected == null) { return ""; } return FluentEqualityConfig.this .toMessageDifferencer(actual.getDescriptorForType()) .diffMessages(actual, expected) .printToString(FluentEqualityConfig.this.reportMismatchesOnly()); }
public static <T extends com.google.protobuf.Message> Any pack( T message) { return Any.newBuilder() .setTypeUrl(getTypeUrl("type.googleapis.com", message.getDescriptorForType())) .setValue(message.toByteString()) .build(); }
/** * Packs a message using the given type URL prefix. The type URL will * be constructed by concatenating the message type's full name to the * prefix with an optional "/" separator if the prefix doesn't end * with "/" already. */ public static <T extends com.google.protobuf.Message> Any pack( T message, java.lang.String typeUrlPrefix) { return Any.newBuilder() .setTypeUrl(getTypeUrl(typeUrlPrefix, message.getDescriptorForType())) .setValue(message.toByteString()) .build(); }
static Any toAny(Message message) { return Any.newBuilder() .setTypeUrl("type.googleapis.com/" + message.getDescriptorForType().getFullName()) .setValue(message.toByteString()) .build(); }