Search in sources :

Example 6 with ProtocolStringList

use of com.google.protobuf.ProtocolStringList in project core-java by SpineEventEngine.

the class FieldMasks method doApply.

private static <M extends Message, B extends Message.Builder> M doApply(FieldMask mask, M message, TypeUrl type) {
    checkNotNull(mask);
    checkNotNull(message);
    checkNotNull(type);
    final ProtocolStringList filter = mask.getPathsList();
    final Class<B> builderClass = getBuilderForType(type);
    if (builderClass == null) {
        return message;
    }
    try {
        final Constructor<B> builderConstructor = builderClass.getDeclaredConstructor();
        builderConstructor.setAccessible(true);
        final M result = messageForFilter(filter, builderConstructor, message);
        return result;
    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
        log().warn(format(CONSTRUCTOR_INVOCATION_ERROR_LOGGING_PATTERN, builderClass.getCanonicalName()), e);
        return message;
    }
}
Also used : ProtocolStringList(com.google.protobuf.ProtocolStringList) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with ProtocolStringList

use of com.google.protobuf.ProtocolStringList in project XRTB by benmfaul.

the class MyReader method doInternal.

/**
	 * Take the internal protobuf and convert to JSON.
	 * @throws Exception on JSON or protobuf errors.
	 */
void doInternal() throws Exception {
    impressions = new ArrayList<Impression>();
    root = BidRequest.factory.objectNode();
    // Add this to the log
    byte[] bytes = internal.toByteArray();
    String str = new String(Base64.encodeBase64(bytes));
    root.put("protobuf", str);
    root.put("at", internal.getAt().getNumber());
    ProtocolStringList list = internal.getBadvList();
    root.put("badv", getAsStringList(BidRequest.factory.arrayNode(), list));
    if (internal.hasTmax())
        root.put("tmax", internal.getTmax());
    root.put("id", internal.getId());
    makeSiteOrApp();
    makeDevice();
    makeImpressions();
    makeUser();
    rootNode = (JsonNode) root;
    setup();
}
Also used : Impression(com.xrtb.pojo.Impression) ProtocolStringList(com.google.protobuf.ProtocolStringList)

Example 8 with ProtocolStringList

use of com.google.protobuf.ProtocolStringList in project core-java by SpineEventEngine.

the class FieldMasks method applyMask.

/**
 * Applies the given {@code FieldMask} to given collection of {@link Message}s.
 * Does not change the {@link Collection} itself.
 *
 * <p>In case the {@code FieldMask} instance contains invalid field declarations, they are
 * ignored and do not affect the execution result.
 *
 * @param mask     {@code FieldMask} to apply to each item of the input {@link Collection}.
 * @param messages {@link Message}s to filter.
 * @param type     type of the {@link Message}s.
 * @return messages with the {@code FieldMask} applied
 */
@Nonnull
public static <M extends Message, B extends Message.Builder> Collection<M> applyMask(FieldMask mask, Collection<M> messages, TypeUrl type) {
    checkNotNull(mask);
    checkNotNull(messages);
    checkNotNull(type);
    final List<M> filtered = new LinkedList<>();
    final ProtocolStringList filter = mask.getPathsList();
    final Class<B> builderClass = getBuilderForType(type);
    if (filter.isEmpty() || builderClass == null) {
        return Collections.unmodifiableCollection(messages);
    }
    try {
        final Constructor<B> builderConstructor = builderClass.getDeclaredConstructor();
        builderConstructor.setAccessible(true);
        for (Message wholeMessage : messages) {
            final M message = messageForFilter(filter, builderConstructor, wholeMessage);
            filtered.add(message);
        }
    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
        // If any reflection failure happens, return all the data without any mask applied.
        log().warn(format(CONSTRUCTOR_INVOCATION_ERROR_LOGGING_PATTERN, builderClass.getCanonicalName()), e);
        return Collections.unmodifiableCollection(messages);
    }
    return Collections.unmodifiableList(filtered);
}
Also used : Message(com.google.protobuf.Message) LinkedList(java.util.LinkedList) ProtocolStringList(com.google.protobuf.ProtocolStringList) InvocationTargetException(java.lang.reflect.InvocationTargetException) Nonnull(javax.annotation.Nonnull)

Example 9 with ProtocolStringList

use of com.google.protobuf.ProtocolStringList in project bazel by bazelbuild.

the class AndroidStudioInfoAspectTest method testTransitiveCCLibraryWithIncludes.

@Test
public void testTransitiveCCLibraryWithIncludes() throws Exception {
    scratch.file("com/google/example/BUILD", "cc_library(", "    name = 'lib2',", "    srcs = ['lib2/lib2.cc'],", "    hdrs = ['lib2/lib2.h'],", "    includes = ['baz/lib'],", ")", "cc_library(", "    name = 'lib1',", "    srcs = ['lib1/lib1.cc'],", "    hdrs = ['lib1/lib1.h'],", "    includes = ['foo/bar'],", "    deps = [':lib2'],", ")");
    Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib1");
    assertThat(targetIdeInfos).hasSize(3);
    TargetIdeInfo lib1 = getTargetIdeInfoAndVerifyLabel("//com/google/example:lib1", targetIdeInfos);
    assertThat(lib1.hasCIdeInfo()).isTrue();
    CIdeInfo cTargetIdeInfo = lib1.getCIdeInfo();
    assertThat(cTargetIdeInfo.getTargetIncludeList()).containsExactly("foo/bar");
    // Make sure our understanding of where this attributes show up in other providers is correct.
    Entry<String, TargetIdeInfo> toolchainEntry = getCcToolchainRuleAndVerifyThereIsOnlyOne(targetIdeInfos);
    TargetIdeInfo toolchainInfo = toolchainEntry.getValue();
    assertThat(toolchainInfo.hasCToolchainIdeInfo()).isTrue();
    CToolchainIdeInfo cToolchainIdeInfo = toolchainInfo.getCToolchainIdeInfo();
    ProtocolStringList builtInIncludeDirectoryList = cToolchainIdeInfo.getBuiltInIncludeDirectoryList();
    assertThat(builtInIncludeDirectoryList).doesNotContain("foo/bar");
    assertThat(builtInIncludeDirectoryList).doesNotContain("baz/lib");
    assertThat(builtInIncludeDirectoryList).doesNotContain("com/google/example/foo/bar");
    assertThat(builtInIncludeDirectoryList).doesNotContain("com/google/example/baz/lib");
    ProtocolStringList transIncludeDirList = cTargetIdeInfo.getTransitiveIncludeDirectoryList();
    assertThat(transIncludeDirList).doesNotContain("foo/bar");
    assertThat(transIncludeDirList).doesNotContain("baz/lib");
    assertThat(transIncludeDirList).doesNotContain("com/google/example/foo/bar");
    assertThat(transIncludeDirList).doesNotContain("com/google/example/baz/lib");
    ProtocolStringList transQuoteIncludeDirList = cTargetIdeInfo.getTransitiveQuoteIncludeDirectoryList();
    assertThat(transQuoteIncludeDirList).doesNotContain("foo/bar");
    assertThat(transQuoteIncludeDirList).doesNotContain("baz/lib");
    assertThat(transQuoteIncludeDirList).doesNotContain("com/google/example/foo/bar");
    assertThat(transQuoteIncludeDirList).doesNotContain("com/google/example/baz/lib");
    ProtocolStringList transSysIncludeDirList = cTargetIdeInfo.getTransitiveSystemIncludeDirectoryList();
    assertThat(transSysIncludeDirList).doesNotContain("foo/bar");
    assertThat(transSysIncludeDirList).doesNotContain("baz/lib");
    assertThat(transSysIncludeDirList).contains("com/google/example/foo/bar");
    assertThat(transSysIncludeDirList).contains("com/google/example/baz/lib");
}
Also used : TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) CToolchainIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo) CIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo) ByteString(com.google.protobuf.ByteString) ProtocolStringList(com.google.protobuf.ProtocolStringList) Test(org.junit.Test)

Example 10 with ProtocolStringList

use of com.google.protobuf.ProtocolStringList in project bazel by bazelbuild.

the class AndroidStudioInfoAspectTest method testTransitiveCCLibraryWithDefines.

@Test
public void testTransitiveCCLibraryWithDefines() throws Exception {
    scratch.file("com/google/example/BUILD", "cc_library(", "    name = 'lib2',", "    srcs = ['lib2/lib2.cc'],", "    hdrs = ['lib2/lib2.h'],", "    defines = ['COMPLEX_IMPL'],", ")", "cc_library(", "    name = 'lib1',", "    srcs = ['lib1/lib1.cc'],", "    hdrs = ['lib1/lib1.h'],", "    defines = ['VERSION2'],", "    deps = [':lib2'],", ")");
    Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib1");
    assertThat(targetIdeInfos).hasSize(3);
    TargetIdeInfo lib1 = getTargetIdeInfoAndVerifyLabel("//com/google/example:lib1", targetIdeInfos);
    assertThat(lib1.hasCIdeInfo()).isTrue();
    CIdeInfo cIdeInfo = lib1.getCIdeInfo();
    assertThat(cIdeInfo.getTargetDefineList()).containsExactly("VERSION2");
    // Make sure our understanding of where this attributes show up in other providers is correct.
    ProtocolStringList transDefineList = cIdeInfo.getTransitiveDefineList();
    assertThat(transDefineList).contains("VERSION2");
    assertThat(transDefineList).contains("COMPLEX_IMPL");
}
Also used : TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) CIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo) ByteString(com.google.protobuf.ByteString) ProtocolStringList(com.google.protobuf.ProtocolStringList) Test(org.junit.Test)

Aggregations

ProtocolStringList (com.google.protobuf.ProtocolStringList)14 ByteString (com.google.protobuf.ByteString)8 CIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo)7 TargetIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo)7 Test (org.junit.Test)7 CToolchainIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArtifactLocation (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.ArtifactLocation)1 FieldMask (com.google.protobuf.FieldMask)1 Message (com.google.protobuf.Message)1 Impression (com.xrtb.pojo.Impression)1 HeaderValue (io.projectriff.grpc.function.FunctionProtos.Message.HeaderValue)1 FieldPath (io.spine.base.FieldPath)1 LinkedList (java.util.LinkedList)1 Nonnull (javax.annotation.Nonnull)1