• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Builder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.protobuf.AbstractMessage.Builder的典型用法代码示例。如果您正苦于以下问题:Java Builder类的具体用法?Java Builder怎么用?Java Builder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Builder类属于com.google.protobuf.AbstractMessage包,在下文中一共展示了Builder类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: decodeJson

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
public static WsPacket decodeJson(String stringResult) {
	try {

		JSONObject jsObj = JSONObject.fromObject(stringResult);
		String wsOpCode = jsObj.getString(WSOPCODE);
		if (wsOpCode == null) {
			if (WSManager.log != null) {
				WSManager.log.warn("数据为:" + stringResult + ",无wsOpCode");
			}
			return null;
		}
		if (!WSManager.wsOpCodeMap.containsKey(wsOpCode)) {
			if (WSManager.log != null) {
				WSManager.log.warn("wsOpCode为:" + wsOpCode + "无对应解析,请及时解决");
			}
			return null;
		}
		Class<?> className = WSManager.wsOpCodeMap.get(wsOpCode);

		Method buildM = className.getDeclaredMethod("newBuilder");
		AbstractMessage.Builder<?> builder = (Builder<?>) buildM.invoke(null);
		Message data = PacketUtils.jsonToProtoBuf(stringResult, builder);
		WsPacket wsPacket = new WsPacket(wsOpCode, data);
		return wsPacket;
	} catch (Exception e) {
		if (WSManager.log != null) {
			WSManager.log.error("json转换成protobuf异常", e);
		}
		return null;
	}
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:32,代码来源:WSCodeUtil.java


示例2: getBuilder

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
private static Builder getBuilder(Class<?> cl) throws Exception {
    if (cl==null) {
        return null;
    }
    
    Method meth = cl.getMethod("newBuilder");
    if (!Modifier.isStatic(meth.getModifiers())
            || !Modifier.isPublic(meth.getModifiers())) {
        throw new Exception("Not a PB!");
    }
    Object o = meth.invoke(cl);
    if (!(o instanceof Builder)) {
        throw new Exception("Not a PB Descriptor!");
    }
    return (Builder) o;
}
 
开发者ID:rhlabs,项目名称:louie,代码行数:17,代码来源:ReflectCommand.java


示例3: decodeJson

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
/**
 * 将字符串转换成HttpPacket
 * 
 * @param stringResult
 *            字符串
 * @param isServer
 *            是不是服务器一般传true
 * @param httpPacket
 *            消息包
 * @return
 */
public static boolean decodeJson(String stringResult, boolean isServer, HttpPacket httpPacket) {
	try {
		// 转换成json获取hOpCode,如果没有看看头消息有没有
		JSONObject jsObj = JSONObject.fromObject(stringResult);
		String hOpCode;
		if (jsObj.containsKey(AllowParam.HOPCODE)) {
			hOpCode = jsObj.getString(AllowParam.HOPCODE);
		} else if (httpPacket.hSession.headParam.hOpCode != null && !httpPacket.hSession.headParam.hOpCode.equals("")) {
			hOpCode = httpPacket.hSession.headParam.hOpCode;
		} else {
			return false;
		}
		// 是否设定相应解析
		if (!HttpManager.hOpCodeMap.containsKey(hOpCode)) {
			if (HttpConfig.log != null) {
				HttpConfig.log.warn("hOpCode为:" + hOpCode + "无对应解析,请及时解决");
			}
			return false;
		}
		// 解析
		Class<?>[] classNames = HttpManager.hOpCodeMap.get(hOpCode);
		Class<?> className;
		if (isServer) {
			className = classNames[0];
		} else {
			className = classNames[1];
		}
		Method buildM = className.getDeclaredMethod("newBuilder");
		AbstractMessage.Builder<?> builder = (Builder<?>) buildM.invoke(null);
		Message data = PacketUtils.jsonToProtoBuf(stringResult, builder);
		if (data == null) {
			return false;
		}
		// 设置hOpCode和消息体
		httpPacket.sethOpCode(hOpCode);
		httpPacket.setData(data);
		return true;
	} catch (Exception e) {
		if (HttpConfig.log != null) {
			HttpConfig.log.error("json转换成protobuf异常", e);
		}
		return false;
	}
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:56,代码来源:CodeUtils.java


示例4: getParser

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
private static BuilderParser getParser(Class<?> cl) throws Exception {
    if (cl == null) {
        return null;
    }
    Method meth = cl.getMethod("newBuilder");
    if (!Modifier.isStatic(meth.getModifiers())
            || !Modifier.isPublic(meth.getModifiers())) {
        throw new Exception("Not a PB!");
    }
    Object o = meth.invoke(cl);
    if (!(o instanceof Builder)) {
        throw new Exception("Not a PB Descriptor!");
    }
    return new BuilderParser<>((Builder) o);
}
 
开发者ID:rhlabs,项目名称:louie,代码行数:16,代码来源:AnnotatedMessageHandler.java


示例5: sendAll

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
/**
 * 发送到所有网关连接
 */
public void sendAll(short code, Builder<?> messageBuilder)
{
	PBMessage packet = new PBMessage(code);
	if (messageBuilder != null)
	{
		// packet.setMessage(messageBuilder.build());
	}
	gateWay.send(packet);
}
 
开发者ID:LaoZhongGu,项目名称:RushServer,代码行数:13,代码来源:GatewayLinkMgr.java


示例6: sendTotalBlackUser

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
/**
 * 发送黑名单列表给玩家
 */
public void sendTotalBlackUser()
{
	BlackInfoListMsg.Builder netMsg = BlackInfoListMsg.newBuilder();
	List<String> blackUser = playerInfo.getBlackUserList();
	for (String userName : blackUser)
	{
		netMsg.addBlackInfoList(userName);
	}

	sendPacket(Protocol.S_C_TOTAL_BLACK_USER, netMsg);
}
 
开发者ID:LaoZhongGu,项目名称:RushServer,代码行数:15,代码来源:GamePlayer.java


示例7: sendPacket

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
/**
 * 发送消息包
 */
public void sendPacket(short msgId, Builder<?> msgBuilder)
{
	PBMessage packet = new PBMessage(msgId);
	if (msgBuilder != null)
	{
		// packet.setMessage(msgBuilder.build());
	}

	sendPacket(packet);
}
 
开发者ID:LaoZhongGu,项目名称:RushServer,代码行数:14,代码来源:GamePlayer.java


示例8: sendTips

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
/**
 * 发送各类提示信息给客户端
 */
public void sendTips(int tipId, Object... args)
{
	TipInfoMsg.Builder netMsg = TipInfoMsg.newBuilder();
	netMsg.setTipId(tipId);
	for (int index = 0; index < args.length; index++)
	{
		netMsg.addContent(String.valueOf(args[index]));
	}

	sendPacket(Protocol.S_C_TIP_INFO, netMsg);
}
 
开发者ID:LaoZhongGu,项目名称:RushServer,代码行数:15,代码来源:GamePlayer.java


示例9: syncPlayerProperty

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
private void syncPlayerProperty(boolean isAllSynch)
{
	if (changeCount.get() <= 0)
	{
		PlayerMsg.Builder playerInfoMsg = PlayerMsg.newBuilder();
		initPlayerMsg(playerInfoMsg, isAllSynch);
		sendPacket(Protocol.S_C_PLAYER_INFO, playerInfoMsg);
	}
}
 
开发者ID:LaoZhongGu,项目名称:RushServer,代码行数:10,代码来源:GamePlayer.java


示例10: pvpRandomItem

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
public void pvpRandomItem()
{
	PVPRandomDiceMsg.Builder netMsg = PVPRandomDiceMsg.newBuilder();
	int itemIndex = 0;
	for (int i = 0; i < 7; i++)
	{
		int color = ThreadLocalRandom.current().nextInt(1, 5);
		DiceInfoMsg.Builder diceInfoMsg = DiceInfoMsg.newBuilder();
		diceInfoMsg.setQuality(color);
		int[] aryColor = aryWhite;
		switch (color)
		{
		case 2:
			aryColor = aryBlack;
			break;

		case 3:
			aryColor = aryGold;
			break;

		case 4:
			aryColor = aryGreen;
			break;

		default:
			break;
		}

		int index = ThreadLocalRandom.current().nextInt(0, 6);
		itemIndex += aryColor[index];
		diceInfoMsg.setPointNum(index);
		netMsg.addDiceInfoList(diceInfoMsg);
	}
	int itemId = randomItemIdList.get(itemIndex).type;
	propMgr.addOnePropToPackage(itemId, 1, ItemChangeType.PVP_RANDOM_DICE_REWARD);
	netMsg.setItemIndex(itemIndex + 1);
	sendPacket(Protocol.S_C_PVP_RANDOM_ITEM, netMsg);
}
 
开发者ID:LaoZhongGu,项目名称:RushServer,代码行数:39,代码来源:GamePlayer.java


示例11: toProtobuf

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
/**
 * @see com.quancheng.saluki.serializer.IProtobufSerializer#toProtobuf(java.lang.Object)
 */
@Override
@SuppressWarnings({"unchecked", "rawtypes", "unused"})
public Message toProtobuf(Object pojo) throws ProtobufException {
  try {
    final Class<?> fromClazz = (Class<?>) pojo.getClass();
    final Class<? extends GeneratedMessageV3> protoClazz =
        ProtobufSerializerUtils.getProtobufClassFromPojoAnno(fromClazz);
    if (protoClazz == null) {
      throw new ProtobufAnnotationException(
          "Doesn't seem like " + fromClazz + " is ProtobufEntity");
    }
    final Map<Field, ProtobufAttribute> protoBufFields =
        ProtobufSerializerUtils.getAllProtbufFields(fromClazz);
    if (protoBufFields.isEmpty()) {
      return null;
    }
    final Method newBuilderMethod = protoClazz.getMethod("newBuilder");
    final Builder protoObjBuilder = (Builder) newBuilderMethod.invoke(null);
    for (Entry<Field, ProtobufAttribute> entry : protoBufFields.entrySet()) {
      final Field field = entry.getKey();
      final ProtobufAttribute gpbAnnotation = entry.getValue();
      final String fieldName = field.getName();
      // 1. Determine validity of value
      Object value = Pojo2ProtobufHelp.getPojoFieldValue(pojo, gpbAnnotation, field);
      // If value is null and it is not required, skip, as the default for Protobuf values is null
      if (value == null) {
        continue;
      }
      // 2. Call recursively if this is a ProtobufEntity
      value = Pojo2ProtobufHelp.serializeToProtobufEntity(value);
      // 3. Special recursively if this is a ProtobufEntity
      if (value instanceof Collection) {
        value = Pojo2ProtobufHelp.convertCollectionToProtobufs((Collection<Object>) value);
        if (((Collection) value).isEmpty()) {
          continue;
        }
      }
      if (value instanceof Map) {
        value = Pojo2ProtobufHelp.convertMapToProtobufs((Map) value);
        if (((Map) value).isEmpty()) {
          continue;
        }
      }
      String setter = ProtobufSerializerUtils.getProtobufSetter(gpbAnnotation, field, value);
      if (value instanceof Enum) {
        value = JReflectionUtils.runMethod(value, "getNumber");
        setter = setter + "Value";
      }
      Pojo2ProtobufHelp.setProtobufFieldValue(gpbAnnotation, protoObjBuilder, setter, value);
    }
    return protoObjBuilder.build();
  } catch (Exception e) {
    throw new ProtobufException(
        "Could not generate Protobuf object for " + pojo.getClass() + ": " + e, e);
  }
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:60,代码来源:ProtobufSerializer.java


示例12: get

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
public Message get(String key, Builder<?> builder) throws Exception {
	byte[] data = get(key);
	return (data == null) ? null : builder.mergeFrom(data).build();
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:5,代码来源:ZStore.java


示例13: HttpPBPacket

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
public HttpPBPacket(int opcode, Builder<?> builder) {
		this.opcode = opcode;
		Message msg = builder.build();
//		log.info("[HttpPBPacket][new] \nopode:{}, message:\n[\n{}]" , opcode,  msg);
		this.data = msg.toByteArray();
	}
 
开发者ID:xuerong,项目名称:MMServerEngine,代码行数:7,代码来源:HttpPBPacket.java


示例14: BuilderParser

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
public BuilderParser(Builder builder) {
    this.builder = builder.clone().clear();
}
 
开发者ID:rhlabs,项目名称:louie,代码行数:4,代码来源:DataParser.java


示例15: sendPlayerInfo

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
public void sendPlayerInfo(boolean isAllSynch)
{
	PlayerMsg.Builder playerInfoMsg = PlayerMsg.newBuilder();
	initPlayerMsg(playerInfoMsg, isAllSynch);
	sendPacket(Protocol.S_C_PLAYER_INFO, playerInfoMsg);
}
 
开发者ID:LaoZhongGu,项目名称:RushServer,代码行数:7,代码来源:GamePlayer.java


示例16: buildMessage

import com.google.protobuf.AbstractMessage.Builder; //导入依赖的package包/类
/**
	 * 消息创建
	 */
	public static PBMessage buildMessage(short code, Builder<?> messageBuilder) {
		PBMessage response = new PBMessage(code);
//		response.setMessage(messageBuilder.build());
		return response;
	}
 
开发者ID:LaoZhongGu,项目名称:RushServer,代码行数:9,代码来源:MessageUtil.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EventTranslatorThreeArg类代码示例发布时间:2022-05-23
下一篇:
Java GetContainerReportRequestProto类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap