Java 类com.google.protobuf.MessageLiteOrBuilder 实例源码

项目:umbrella    文件:PacketWrapper.java   
public static Packet wrap(MessageLiteOrBuilder message) {
    if (message instanceof Packet) {
        return ((Packet) message);
    }

    if (message instanceof Packet.Builder) {
        return ((Packet.Builder) message).build();
    }

    ByteString bytes = toByteString(message);

    Packet.Builder builder = Packet.newBuilder();
    builder.setSequence(SEQUENCE.incrementAndGet());
    MessageType messageType = getMessageType(message);
    builder.setType(messageType);
    builder.setData(bytes);

    return builder.build();
}
项目:umbrella    文件:PacketWrapper.java   
public static Packet.Builder wrapBuilder(MessageLiteOrBuilder message) {
    if (message instanceof Packet) {
        return ((Packet) message).toBuilder();
    }

    if (message instanceof Packet.Builder) {
        return (Packet.Builder) message;
    }

    ByteString bytes = toByteString(message);

    Packet.Builder builder = Packet.newBuilder();
    builder.setSequence(SEQUENCE.incrementAndGet());
    MessageType messageType = getMessageType(message);
    builder.setType(messageType);
    builder.setData(bytes);

    return builder;
}
项目:umbrella    文件:ProtobufEncoder.java   
@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()));
//        }

        Packet packet = PacketWrapper.wrap(msg);
        if (packet != null) {
            out.add(wrappedBuffer(packet.toByteArray()));
        }
    }
项目:openrtb-doubleclick    文件:ProtoUtils.java   
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;
}
项目:openrtb    文件:ProtoUtils.java   
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;
}
项目:wecard-server    文件:ProtobufEncoder.java   
@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()));
    }
}
项目:netty4.0.27Learn    文件:ProtobufEncoder.java   
@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()));
    }
}
项目:umbrella    文件:PacketWrapper.java   
private static ByteString toByteString(MessageLiteOrBuilder message) {
    ByteString bytes = null;

    if (message instanceof MessageLite) {
        bytes = ((MessageLite) message).toByteString();
    } else if (message instanceof MessageLite.Builder) {
        bytes = ((MessageLite.Builder) message).build().toByteString();
    }

    return bytes;
}
项目:umbrella    文件:PacketWrapper.java   
private static MessageType getMessageType(MessageLiteOrBuilder message) {
    String key = null;
    if (message instanceof MessageLite) {
        key = message.getClass().getSimpleName();
    }

    if (message instanceof MessageLite.Builder) {
        key = ((MessageLite.Builder) message).build().getClass().getSimpleName();
    }

    return messageTypesByName.get(key.toUpperCase());
}
项目:umbrella    文件:Errors.java   
public static void sendError(HandlerContext ctx, Packet packet, MessageLiteOrBuilder error){
    Packet.Builder builder = packet.toBuilder();
    if(error instanceof MessageLite.Builder){
        builder.setData(((MessageLite.Builder) error).build().toByteString());
    }else {
        builder.setData(((MessageLite) error).toByteString());
    }

    ctx.write(builder.build());
}
项目:netty4study    文件:ProtobufEncoder.java   
@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()));
    }
}
项目:peercentrum-core    文件:ProtobufByteBufCodec.java   
public static ByteBuf encodeNoLengthPrefix(MessageLiteOrBuilder msg) {
    if (msg instanceof MessageLite) {
        return Unpooled.wrappedBuffer(((MessageLite) msg).toByteArray());
    }
    if (msg instanceof MessageLite.Builder) {
        return Unpooled.wrappedBuffer(((MessageLite.Builder) msg).build().toByteArray());
    }
    return null;
}
项目:netty-netty-5.0.0.Alpha1    文件:ProtobufEncoder.java   
@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()));
    }
}
项目:openrtb    文件:ProtoUtils.java   
/**
 * 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;
}
项目:openrtb    文件:ProtoUtils.java   
/**
 * 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;
}
项目:umbrella    文件:SimpleSocketClient.java   
public void write(MessageLiteOrBuilder message) {
    if (!connected) {
        this.connect(); // 发送数据时自动连接
    }
    channel.writeAndFlush(message);
}