com.google.protobuf.MessageLiteOrBuilder Java Examples

The following examples show how to use com.google.protobuf.MessageLiteOrBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProtoUtils.java    From openrtb-doubleclick with Apache License 2.0 6 votes vote down vote up
private static <M extends MessageLiteOrBuilder> List<M> filterFrom(
    List<M> objs, Predicate<M> filter, int firstDiscarded) {
  List<M> filtered;

  if (firstDiscarded == 0) {
    filtered = null;
  } else {
    filtered = new ArrayList<>(objs.size() - 1);
    for (int i = 0; i < firstDiscarded; ++i) {
      filtered.add(objs.get(i));
    }
  }

  for (int i = firstDiscarded + 1; i < objs.size(); ++i) {
    M obj = objs.get(i);

    if (filter.test(obj)) {
      if (filtered == null) {
        filtered = new ArrayList<>(objs.size() - i);
      }
      filtered.add(obj);
    }
  }

  return filtered == null ? ImmutableList.<M>of() : filtered;
}
 
Example #2
Source File: ProtoUtils.java    From openrtb with Apache License 2.0 6 votes vote down vote up
private static <M extends MessageLiteOrBuilder> List<M> filterFrom(
    List<M> objs, Predicate<M> filter, int firstDiscarded) {
  List<M> filtered;

  if (firstDiscarded == 0) {
    filtered = null;
  } else {
    filtered = new ArrayList<>(objs.size() - 1);
    for (int i = 0; i < firstDiscarded; ++i) {
      filtered.add(objs.get(i));
    }
  }

  for (int i = firstDiscarded + 1; i < objs.size(); ++i) {
    M obj = objs.get(i);

    if (filter.test(obj)) {
      if (filtered == null) {
        filtered = new ArrayList<>(objs.size() - i);
      }
      filtered.add(obj);
    }
  }

  return filtered == null ? ImmutableList.<M>of() : filtered;
}
 
Example #3
Source File: ProtobufEncoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected void encode(ChannelHandlerContext ctx, MessageLiteOrBuilder msg, List<Object> out)
        throws Exception {
    if (msg instanceof MessageLite) {
        out.add(wrappedBuffer(((MessageLite) msg).toByteArray()));
        return;
    }
    if (msg instanceof MessageLite.Builder) {
        out.add(wrappedBuffer(((MessageLite.Builder) msg).build().toByteArray()));
    }
}
 
Example #4
Source File: ProtobufEncoder.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
protected void encode(
        ChannelHandlerContext ctx, MessageLiteOrBuilder msg, List<Object> out) throws Exception {
    if (msg instanceof MessageLite) {
        out.add(wrappedBuffer(((MessageLite) msg).toByteArray()));
        return;
    }
    if (msg instanceof MessageLite.Builder) {
        out.add(wrappedBuffer(((MessageLite.Builder) msg).build().toByteArray()));
    }
}
 
Example #5
Source File: ProtoUtils.java    From openrtb with Apache License 2.0 5 votes vote down vote up
/**
 * Given a message-or-builder, returns a message, invoking the builder if necessary.
 */
@SuppressWarnings("unchecked")
public static <I extends MessageLiteOrBuilder, O extends MessageLite> O built(@Nullable I msg) {
  return msg instanceof MessageLite.Builder
      ? (O) ((MessageLite.Builder) msg).build()
      : (O) msg;
}
 
Example #6
Source File: ProtoUtils.java    From openrtb with Apache License 2.0 5 votes vote down vote up
/**
 * Given a message-or-builder, return a builder, invoking toBuilder() if necessary.
 */
@SuppressWarnings("unchecked")
public static <I extends MessageLiteOrBuilder, O extends MessageLite.Builder> O builder(
    @Nullable I msg) {
  return msg instanceof MessageLite
      ? (O) ((MessageLite) msg).toBuilder()
      : (O) msg;
}