当前位置: 首页>>代码示例>>Java>>正文


Java MessageLiteOrBuilder类代码示例

本文整理汇总了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();
}
 
开发者ID:gukt,项目名称:umbrella,代码行数:20,代码来源:PacketWrapper.java

示例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;
}
 
开发者ID:gukt,项目名称:umbrella,代码行数:20,代码来源:PacketWrapper.java

示例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()));
        }
    }
 
开发者ID:gukt,项目名称:umbrella,代码行数:17,代码来源:ProtobufEncoder.java

示例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;
}
 
开发者ID:google,项目名称:openrtb-doubleclick,代码行数:27,代码来源:ProtoUtils.java

示例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()));
    }
}
 
开发者ID:ninelook,项目名称:wecard-server,代码行数:12,代码来源:ProtobufEncoder.java

示例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;
}
 
开发者ID:gukt,项目名称:umbrella,代码行数:12,代码来源:PacketWrapper.java

示例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());
}
 
开发者ID:gukt,项目名称:umbrella,代码行数:13,代码来源:PacketWrapper.java

示例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());
}
 
开发者ID:gukt,项目名称:umbrella,代码行数:11,代码来源:Errors.java

示例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;
}
 
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:10,代码来源:ProtobufByteBufCodec.java

示例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;
}
 
开发者ID:google,项目名称:openrtb,代码行数:10,代码来源:ProtoUtils.java

示例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;
}
 
开发者ID:google,项目名称:openrtb,代码行数:11,代码来源:ProtoUtils.java

示例12: write

import com.google.protobuf.MessageLiteOrBuilder; //导入依赖的package包/类
public void write(MessageLiteOrBuilder message) {
    if (!connected) {
        this.connect(); // 发送数据时自动连接
    }
    channel.writeAndFlush(message);
}
 
开发者ID:gukt,项目名称:umbrella,代码行数:7,代码来源:SimpleSocketClient.java


注:本文中的com.google.protobuf.MessageLiteOrBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。