本文整理汇总了Java中com.google.protobuf.MessageLite类的典型用法代码示例。如果您正苦于以下问题:Java MessageLite类的具体用法?Java MessageLite怎么用?Java MessageLite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageLite类属于com.google.protobuf包,在下文中一共展示了MessageLite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGroup
import com.google.protobuf.MessageLite; //导入依赖的package包/类
/**
* @param commandId
* @param clusterMessage
* @since 1.0
*/
private void doGroup(short commandId, MyClusterMessage clusterMessage) {
logger.debug("MyClusterMessageListener#doSwitch");
IMHeader header = clusterMessage.getHeader();
try {
MessageLite body = clusterMessage.getMessage();
switch (commandId) {
case GroupCmdID.CID_GROUP_CHANGE_MEMBER_NOTIFY_VALUE:// todebug
groupChangeMemberNotify(header, body);
break;
default:
logger.warn("Unsupport command id {}", commandId);
break;
}
} catch (IOException e) {
logger.error("decode failed.", e);
}
}
示例2: extract
import com.google.protobuf.MessageLite; //导入依赖的package包/类
/**
* Attempts to extract a protocol buffer from the specified extra.
* @throws MalformedDataException if the intent is null, the extra is missing or not a byte
* array, or the protocol buffer could not be parsed.
*/
@NonNull
public static <T extends MessageLite> T extract(
@NonNull String extraName,
@NonNull Parser<T> protoParser,
@NonNull String failureDescription,
@Nullable Intent intent)
throws MalformedDataException {
if (intent == null) {
throw new MalformedDataException(failureDescription);
}
byte[] protoBytes = intent.getByteArrayExtra(extraName);
if (protoBytes == null) {
throw new MalformedDataException(failureDescription);
}
try {
return protoParser.parseFrom(protoBytes);
} catch (IOException ex) {
throw new MalformedDataException(failureDescription, ex);
}
}
示例3: pushShield
import com.google.protobuf.MessageLite; //导入依赖的package包/类
@Override
public void pushShield(IMHeader header, MessageLite body, ChannelHandlerContext ctx) {
IMPushShieldReq pushShieldReq = (IMPushShieldReq) body;
long userId = super.getUserId(ctx);
IMHeader resHeader = null;
IMPushShieldRsp pushShieldRsp = null;
try {
BaseModel<Integer> pushShieldRes = loginService.pushShield(userId, pushShieldReq.getShieldStatus());
pushShieldRsp = IMPushShieldRsp.newBuilder()
.setUserId(userId)
.setResultCode(pushShieldRes.getCode())
.build();
resHeader = header.clone();
resHeader.setCommandId((short)LoginCmdID.CID_LOGIN_RES_PUSH_SHIELD_VALUE);
ctx.writeAndFlush(new IMProtoMessage<>(resHeader, pushShieldRsp));
} catch(Exception e){
logger.error("服务器端异常", e);
ctx.writeAndFlush(new IMProtoMessage<>(resHeader, pushShieldRsp));
}
}
示例4: getResponseDefaultInstance
import com.google.protobuf.MessageLite; //导入依赖的package包/类
public static MessageLite getResponseDefaultInstance(int rpcType) throws RpcException {
switch (rpcType) {
case RpcType.ACK_VALUE:
return Ack.getDefaultInstance();
case RpcType.HANDSHAKE_VALUE:
return BitControlHandshake.getDefaultInstance();
case RpcType.RESP_FRAGMENT_HANDLE_VALUE:
return FragmentHandle.getDefaultInstance();
case RpcType.RESP_FRAGMENT_STATUS_VALUE:
return FragmentStatus.getDefaultInstance();
case RpcType.RESP_BIT_STATUS_VALUE:
return BitStatus.getDefaultInstance();
case RpcType.RESP_QUERY_STATUS_VALUE:
return QueryProfile.getDefaultInstance();
default:
throw new UnsupportedOperationException();
}
}
示例5: getHandshakeHandler
import com.google.protobuf.MessageLite; //导入依赖的package包/类
@Override
protected ServerHandshakeHandler<BitClientHandshake> getHandshakeHandler(final BitServerConnection connection) {
return new ServerHandshakeHandler<BitClientHandshake>(RpcType.HANDSHAKE, BitClientHandshake.PARSER) {
@Override
public MessageLite getHandshakeResponse(BitClientHandshake inbound) throws Exception {
// logger.debug("Handling handshake from other bit. {}", inbound);
if (inbound.getRpcVersion() != DataRpcConfig.RPC_VERSION) {
throw new RpcException(String.format("Invalid rpc version. Expected %d, actual %d.",
inbound.getRpcVersion(), DataRpcConfig.RPC_VERSION));
}
if (inbound.getChannel() != RpcChannel.BIT_DATA) {
throw new RpcException(String.format("Invalid NodeMode. Expected BIT_DATA but received %s.",
inbound.getChannel()));
}
return BitServerHandshake.newBuilder().setRpcVersion(DataRpcConfig.RPC_VERSION).build();
}
};
}
示例6: handleKickUser
import com.google.protobuf.MessageLite; //导入依赖的package包/类
/**
* 发送当前踢人消息 handleKickUser
*
* @param MessageLite
* @param ChannelHandlerContext
* @since 1.0 李春生
*/
private void handleKickUser(MessageLite body) {
// 转换body中的数据,判断是否是真正的kickUser消息,如果是,则进行下面的操作,不是抛出异常
IMServerKickUser kickUser = (IMServerKickUser) body;
long userId = kickUser.getUserId();
int clientType = kickUser.getClientType().getNumber();
int reason = kickUser.getReason();
logger.debug("HandleKickUser, userId={}, clientType={}, reason={}", userId, clientType,
reason);
ClientUser clientUser = ClientUserManager.getUserById(userId);
if (clientUser != null) {
// 踢掉用户,根据ClientType进行判断
clientUser.kickSameClientType(clientType, reason, null);
}
}
示例7: getResponseDefaultInstance
import com.google.protobuf.MessageLite; //导入依赖的package包/类
@Override
protected MessageLite getResponseDefaultInstance(int rpcType) throws RpcException {
switch (rpcType) {
case RpcType.ACK_VALUE:
return Ack.getDefaultInstance();
case RpcType.HANDSHAKE_VALUE:
return BitToUserHandshake.getDefaultInstance();
case RpcType.QUERY_HANDLE_VALUE:
return QueryId.getDefaultInstance();
case RpcType.QUERY_RESULT_VALUE:
return QueryResult.getDefaultInstance();
case RpcType.QUERY_DATA_VALUE:
return QueryData.getDefaultInstance();
}
throw new RpcException(String.format("Unable to deal with RpcType of %d", rpcType));
}
示例8: writeMessageList
import com.google.protobuf.MessageLite; //导入依赖的package包/类
/**
* Creates a {@link ByteString} by serializing the list of protos. Use
* {@link #readMessageList(ByteString, Parser)} to deserialize.
*/
public static <T extends MessageLite> ByteString writeMessageList(List<T> protos) {
Output output = ByteString.newOutput();
try {
writeMessageListTo(output, protos);
} catch (IOException ex) {
throw new IllegalStateException("Unable to write protobufs to memory");
}
return output.toByteString();
}
示例9: readMessageList
import com.google.protobuf.MessageLite; //导入依赖的package包/类
/**
* Reads a list of protos, using the provided parser, from the provided input stream.
* @throws IOException if the proto list could not be parsed.
*/
public static <T extends MessageLite> List<T> readMessageList(
InputStream stream,
Parser<T> parser)
throws IOException {
DataInputStream dis = new DataInputStream(stream);
int messageCount = dis.readInt();
ArrayList<T> messages = new ArrayList<>(messageCount);
for (int i = 0; i < messageCount; i++) {
messages.add(parser.parseDelimitedFrom(stream));
}
return messages;
}
示例10: getMessage
import com.google.protobuf.MessageLite; //导入依赖的package包/类
/**
* Convert a protobuf to message object according to the serviceId and commandId.
*
* @param serviceId the service id
* @param commandId the command id
* @param bytes the protobuf to be parsed
* @return the parsed message object
* @throws IOException
* @since 1.0
*/
public static MessageLite getMessage(final int serviceId, final int commandId, final byte[] bytes)
throws IOException {
Map<Integer, ProtobufParseMap.Parsing> parserMap = parseServiceMap.get(serviceId);
if (parserMap == null) {
throw new IOException("UnKnown Protocol service: " + serviceId);
}
ProtobufParseMap.Parsing parser = parserMap.get(commandId);
if (parser == null) {
throw new IOException(
"UnKnown Protocol commandId: service=" + serviceId + ",command=" + commandId);
}
MessageLite msg = parser.process(bytes);
return msg;
}
示例11: encode
import com.google.protobuf.MessageLite; //导入依赖的package包/类
@Override
protected void encode(ChannelHandlerContext context, OutboundRpcMessage message, List<Object> out) throws Exception {
if (message.mode != RpcMode.RESPONSE_FAILURE) {
out.add(message);
return;
}
final MessageLite pBody = message.pBody;
if (!(pBody instanceof DremioPBError)) {
out.add(message);
return;
}
DremioPBError error = (DremioPBError) pBody;
DremioPBError newError = ErrorCompatibility.convertIfNecessary(error);
out.add(new OutboundRpcMessage(message.mode, message.rpcType, message.coordinationId, newError, message.dBodies));
}
示例12: doFile
import com.google.protobuf.MessageLite; //导入依赖的package包/类
/**
* 处理File消息
* @param ctx 信道
* @param commandId 命令
* @param header 消息头
* @param body 消息体
* @since 1.0
*/
public void doFile(ChannelHandlerContext ctx, short commandId, IMHeader header, MessageLite body) {
// 判断是否登录
if (!hasLogin(ctx)) {
return ;
}
switch (commandId) {
case FileCmdID.CID_FILE_REQUEST_VALUE:
imFileHandle.fileReq(header, body, ctx);
break;
case FileCmdID.CID_FILE_HAS_OFFLINE_REQ_VALUE:
imFileHandle.hasOfflineReq(header, body, ctx);
break;
case FileCmdID.CID_FILE_ADD_OFFLINE_REQ_VALUE:
imFileHandle.addOfflineReq(header, body, ctx);
break;
case FileCmdID.CID_FILE_DEL_OFFLINE_REQ_VALUE:
imFileHandle.delOfflineReq(header, body, ctx);
break;
default:
logger.warn("Unsupport command id {}", commandId);
break;
}
}
示例13: doSwitch
import com.google.protobuf.MessageLite; //导入依赖的package包/类
/**
* @param commandId
* @param clusterMessage
* @since 1.0
*/
private void doSwitch(short commandId, MyClusterMessage clusterMessage) {
logger.debug("MyClusterMessageListener#doSwitch");
IMHeader header = clusterMessage.getHeader();
try {
MessageLite body = clusterMessage.getMessage();
switch (commandId) {
case SwitchServiceCmdID.CID_SWITCH_P2P_CMD_VALUE:// todebug
switchP2p(header, body);
default:
logger.warn("Unsupport command id {}", commandId);
break;
}
} catch (IOException e) {
logger.error("decode failed.", e);
}
}
示例14: getResponseDefaultInstance
import com.google.protobuf.MessageLite; //导入依赖的package包/类
@Override
protected MessageLite getResponseDefaultInstance(int rpcType) throws RpcException {
switch (rpcType) {
case RpcType.ACK_VALUE:
return Ack.getDefaultInstance();
case RpcType.HANDSHAKE_VALUE:
return BitToUserHandshake.getDefaultInstance();
case RpcType.QUERY_HANDLE_VALUE:
return QueryId.getDefaultInstance();
case RpcType.QUERY_RESULT_VALUE:
return QueryResult.getDefaultInstance();
case RpcType.QUERY_DATA_VALUE:
return QueryData.getDefaultInstance();
case RpcType.QUERY_PLAN_FRAGMENTS_VALUE:
return QueryPlanFragments.getDefaultInstance();
case RpcType.CATALOGS_VALUE:
return GetCatalogsResp.getDefaultInstance();
case RpcType.SCHEMAS_VALUE:
return GetSchemasResp.getDefaultInstance();
case RpcType.TABLES_VALUE:
return GetTablesResp.getDefaultInstance();
case RpcType.COLUMNS_VALUE:
return GetColumnsResp.getDefaultInstance();
case RpcType.PREPARED_STATEMENT_VALUE:
return CreatePreparedStatementResp.getDefaultInstance();
case RpcType.SERVER_META_VALUE:
return GetServerMetaResp.getDefaultInstance();
}
throw new RpcException(String.format("Unable to deal with RpcType of %d", rpcType));
}
示例15: readBufferedMessage
import com.google.protobuf.MessageLite; //导入依赖的package包/类
/** Attempts to read a buffered message from the underlying connection. This is more efficient
* than attempting to actually read from the underlying connection for each message, when ends
* up making a final "empty" read from the non-blocking connection, rather than simply
* consuming all buffered data.
*
* TODO: It would be ideal if there was a way to consume data as we go, instead of buffering
* it all then consuming it. However, this only matters for streams of medium-sized messages
* with a huge backlog, which should be rare? The C++ implementation has a similar issue.
*
* @param builder message builder to be parsed
* @return true if a message was read, false if there is not enough buffered data to read a
* message.
*/
public boolean readBufferedMessage(MessageLite.Builder builder) {
try {
if (nextMessageLength == -1) {
if (connection.available() < 4) {
return false;
}
input.setLimit(4);
nextMessageLength = codedInput.readRawLittleEndian32();
}
assert nextMessageLength >= 0;
if (connection.available() < nextMessageLength) {
assert 0 <= connection.available() && connection.available() < nextMessageLength;
return false;
}
// Parse the response for the next RPC
// TODO: Add .available() to CodedInputStream to avoid many copies to internal buffer?
// or make CodedInputStream wrap a non-blocking interface like C++?
input.setLimit(nextMessageLength);
builder.mergeFrom(codedInput);
assert codedInput.isAtEnd();
codedInput.resetSizeCounter();
nextMessageLength = -1;
return true;
} catch (IOException e) {
throw new RuntimeException(e);
}
}