com.iohao.game.common.kit.ProtoKit Maven / Gradle / Ivy
/*
* ioGame
* Copyright (C) 2021 - present 渔民小镇 ([email protected]、[email protected]) . All Rights Reserved.
* # iohao.com . 渔民小镇
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package com.iohao.game.common.kit;
import com.baidu.bjf.remoting.protobuf.Codec;
import com.baidu.bjf.remoting.protobuf.ProtobufProxy;
import com.iohao.game.common.consts.CommonConst;
import com.iohao.game.common.consts.IoGameLogName;
import com.iohao.game.common.kit.concurrent.TaskKit;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import java.util.Objects;
/**
* @author 渔民小镇
* @date 2022-01-11
*/
@UtilityClass
@Slf4j(topic = IoGameLogName.CommonStdout)
public class ProtoKit {
/**
* 将对象转为 pb 字节数组
*
* @param data 对象
* @return 字节数组 (一定不为null)
*/
@SuppressWarnings("unchecked")
public byte[] toBytes(Object data) {
if (Objects.isNull(data)) {
return CommonConst.emptyBytes;
}
Class clazz = data.getClass();
Codec