本文整理汇总了Java中io.vertx.core.buffer.Buffer.getByte方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.getByte方法的具体用法?Java Buffer.getByte怎么用?Java Buffer.getByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.getByte方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseHeader
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
/**
* 解析报文头。
*
* @param headerBuffer header Buffer
* @param expectedCommand expectedCommand
* @param expectedBodyLength expectedBodyLength
* @return async result of the length of the packet body
*/
public static Future<Long> parseHeader(Buffer headerBuffer, byte expectedCommand, long expectedBodyLength) {
if (headerBuffer.length() != HEADER_BYTE_LENGTH) {
return Future.failedFuture(new FdfsException("receive packet size" + headerBuffer.length()
+ " is not equal to the expected header size: " + HEADER_BYTE_LENGTH));
}
byte command = headerBuffer.getByte(PROTO_HEADER_CMD_INDEX);
if (command != expectedCommand) {
return Future.failedFuture(new FdfsException(
"receive command: " + command + " is not equal to the expected command: " + expectedCommand));
}
byte status = headerBuffer.getByte(PROTO_HEADER_STATUS_INDEX);
if (status != HEADER_STATUS_SUCCESS) {
return Future.failedFuture(new FdfsException("receive packet errno is: " + status));
}
long bodyLength = headerBuffer.getLong(0);
if (expectedBodyLength > 0 && bodyLength != expectedBodyLength) {
return Future.failedFuture(new FdfsException("receive packet body length: " + bodyLength
+ " is not equal to the expected: " + expectedBodyLength));
}
return Future.succeededFuture(bodyLength);
}
示例2: parseStorage
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
private Future<FdfsStorageOptions> parseStorage(Buffer bodyBuffer, String charset, boolean hasPathIndex) {
try {
FdfsStorageOptions storageOptions = new FdfsStorageOptions(options);
String group = FdfsUtils
.fdfsTrim(bodyBuffer.getString(0, FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN, options.getCharset()));
String ip = FdfsUtils.fdfsTrim(bodyBuffer.getString(FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN,
FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN + FdfsProtocol.FDFS_IPADDR_SIZE - 1, options.getCharset()));
long port = bodyBuffer.getLong(FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN + FdfsProtocol.FDFS_IPADDR_SIZE - 1);
storageOptions.setGroup(group).setAddress(SocketAddress.inetSocketAddress((int) port, ip));
if (hasPathIndex && bodyBuffer.length() > FdfsProtocol.TRACKER_QUERY_STORAGE_FETCH_BODY_LEN) {
byte storePathIndex = bodyBuffer.getByte(FdfsProtocol.TRACKER_QUERY_STORAGE_FETCH_BODY_LEN);
storageOptions.setStorePathIndex(storePathIndex);
}
return Future.succeededFuture(storageOptions);
} catch (Exception e) {
return Future.failedFuture(e);
}
}