本文整理汇总了Java中com.google.protobuf.MessageLiteOrBuilder类的典型用法代码示例。如果您正苦于以下问题:Java MessageLiteOrBuilder类的具体用法?Java MessageLiteOrBuilder怎么用?Java MessageLiteOrBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageLiteOrBuilder类属于com.google.protobuf包,在下文中一共展示了MessageLiteOrBuilder类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrap
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
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();
}
示例2: wrapBuilder
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
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;
}
示例3: encode
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
@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()));
}
}
示例4: filterFrom
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
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;
}
示例5: encode
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
@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()));
}
}
示例6: toByteString
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
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;
}
示例7: getMessageType
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
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());
}
示例8: sendError
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
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());
}
示例9: encodeNoLengthPrefix
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
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;
}
示例10: built
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
/**
* 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;
}
示例11: builder
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
/**
* 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;
}
示例12: write
import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
public void write(MessageLiteOrBuilder message) {
if (!connected) {
this.connect(); // 发送数据时自动连接
}
channel.writeAndFlush(message);
}