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;
}
}
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();
}
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);
}
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");
}
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");
}
Aggregations