本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.readByte方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.readByte方法的具體用法?Java ChannelBuffer.readByte怎麽用?Java ChannelBuffer.readByte使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.buffer.ChannelBuffer
的用法示例。
在下文中一共展示了ChannelBuffer.readByte方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: read
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Reads the channel buffer and returns object of IPReachabilityInformationTlv.
*
* @param cb ChannelBuffer
* @param length of value field
* @return object of IPReachabilityInformationTlv
*/
public static IPReachabilityInformationTlv read(ChannelBuffer cb, short length) {
byte preficLen = cb.readByte();
byte[] prefix;
if (preficLen == 0) {
prefix = new byte[] {0};
} else {
int len = preficLen / ONE_BYTE_LEN;
int reminder = preficLen % ONE_BYTE_LEN;
if (reminder > 0) {
len = len + 1;
}
prefix = new byte[len];
cb.readBytes(prefix, 0, len);
}
return IPReachabilityInformationTlv.of(preficLen, prefix, length);
}
示例2: read
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Reads from channel buffer and returns object of PcepErrorObject.
*
* @param cb of channel buffer.
* @return object of PCEP-ERROR-OBJECT
*/
public static PcepErrorObject read(ChannelBuffer cb) {
PcepObjectHeader errorObjHeader;
byte errorType;
byte errorValue;
LinkedList<PcepValueType> optionalTlv;
errorObjHeader = PcepObjectHeader.read(cb);
//take only ErrorObject buffer.
ChannelBuffer tempCb = cb.readBytes(errorObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
tempCb.readByte(); //ignore Reserved
tempCb.readByte(); //ignore Flags
errorType = tempCb.readByte();
errorValue = tempCb.readByte();
optionalTlv = parseOptionalTlv(tempCb);
return new PcepErrorObjectVer1(errorObjHeader, errorType, errorValue, optionalTlv);
}
示例3: read
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Reads from ChannelBuffer and parses Origin.
*
* @param cb ChannelBuffer
* @return object of Origin
* @throws BgpParseException while parsing Origin path attribute
*/
public static Origin read(ChannelBuffer cb) throws BgpParseException {
ChannelBuffer tempCb = cb.copy();
Validation parseFlags = Validation.parseAttributeHeader(cb);
int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if ((parseFlags.getLength() > ORIGIN_VALUE_LEN) || (cb.readableBytes() < parseFlags.getLength())) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
byte originValue;
originValue = cb.readByte();
if ((originValue != OriginType.INCOMPLETE.value) && (originValue != OriginType.IGP.value) &&
(originValue != OriginType.EGP.value)) {
throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.INVALID_ORIGIN_ATTRIBUTE, data);
}
return new Origin(originValue);
}
示例4: sendResponse
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private static void sendResponse(Channel channel, int device, long id, int crc) {
if (channel != null) {
ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
response.writeByte(device);
response.writeByte(MSG_ACK);
response.writeInt((int) id);
response.writeShort(crc);
response.writeShort(Checksum.crc16(
Checksum.CRC16_XMODEM, response.toByteBuffer()));
ChannelBuffer encoded = ChannelBuffers.dynamicBuffer();
encoded.writeByte(0x01); // header
while (response.readable()) {
int b = response.readByte();
if (b == 0x01 || b == 0x04 || b == 0x10 || b == 0x11 || b == 0x13) {
encoded.writeByte(0x10);
b += 0x20;
}
encoded.writeByte(b);
}
encoded.writeByte(0x04); // ending
channel.write(encoded);
}
}
示例5: read
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Read from channel buffer and Returns PCEP Objects header.
*
* @param cb of type channel buffer
* @return PCEP Object header
*/
public static PcepObjectHeader read(ChannelBuffer cb) {
byte objClass;
byte objType;
boolean bPFlag;
boolean bIFlag;
short objLen;
objClass = cb.readByte();
byte temp = cb.readByte();
bIFlag = (temp & IFLAG_SET) == IFLAG_SET;
bPFlag = (temp & PFLAG_SET) == PFLAG_SET;
objType = (byte) (temp >> OBJECT_TYPE_SHIFT_VALUE);
objLen = cb.readShort();
return new PcepObjectHeader(objClass, objType, bPFlag, bIFlag, objLen);
}
示例6: readFrom
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public PcepOpenMsg readFrom(ChannelBuffer cb) throws PcepParseException {
if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException("Packet size is less than the minimum length.");
}
byte version = cb.readByte();
version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
if (version != PACKET_VERSION) {
log.error("[readFrom] Invalid version: " + version);
throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1);
}
// fixed value property type == 1
byte type = cb.readByte();
if (type != MSG_TYPE.getType()) {
log.error("[readFrom] Unexpected type: " + type);
throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1);
}
int length = cb.readShort();
if (length < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException(
"Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " + length);
}
return new PcepOpenMsgVer1(PcepOpenObjectVer1.read(cb));
}
示例7: read
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Reads the channel buffer and returns object of IPv4SubObject.
*
* @param c type of channel buffer
* @return object of IPv4SubObject
*/
public static PcepValueType read(ChannelBuffer c) {
int ipAddess = c.readInt();
byte prefixLen = c.readByte();
byte resvd = c.readByte();
return new IPv4SubObject(ipAddess, prefixLen, resvd);
}
示例8: getOspfHeader
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Gets the OSPF packet Header.
*
* @param channelBuffer channel buffer instance.
* @return Ospf Header instance.
*/
private OspfPacketHeader getOspfHeader(ChannelBuffer channelBuffer) throws Exception {
OspfPacketHeader ospfPacketHeader = new OspfPacketHeader();
// Determine OSPF version & Packet Type
int version = channelBuffer.readByte(); //byte 1 is ospf version
int packetType = channelBuffer.readByte(); //byte 2 is ospf packet type
// byte 3 & 4 combine is packet length.
int packetLength = channelBuffer.readShort();
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
Ip4Address routerId = Ip4Address.valueOf(tempByteArray);
tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
Ip4Address areaId = Ip4Address.valueOf(tempByteArray);
int checkSum = channelBuffer.readUnsignedShort();
int auType = channelBuffer.readUnsignedShort();
int authentication = (int) channelBuffer.readLong();
ospfPacketHeader.setOspfVer(version);
ospfPacketHeader.setOspftype(packetType);
ospfPacketHeader.setOspfPacLength(packetLength);
ospfPacketHeader.setRouterId(routerId);
ospfPacketHeader.setAreaId(areaId);
ospfPacketHeader.setChecksum(checkSum);
ospfPacketHeader.setAuthType(auType);
ospfPacketHeader.setAuthentication(authentication);
return ospfPacketHeader;
}
示例9: read
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Returns PCEP rsvp IPv6 error spce object.
*
* @param cb channel buffer
* @return PCEP rsvp IPv6 error spce object
*/
public static PcepRsvpErrorSpec read(ChannelBuffer cb) {
PcepRsvpSpecObjHeader objHeader;
byte[] ipv6Addr = new byte[IPV6_LEN];
byte flags;
byte errCode;
short errValue;
objHeader = PcepRsvpSpecObjHeader.read(cb);
cb.readBytes(ipv6Addr, 0, IPV6_LEN);
flags = cb.readByte();
errCode = cb.readByte();
errValue = cb.readShort();
return new PcepRsvpIpv6ErrorSpec(objHeader, ipv6Addr, flags, errCode, errValue);
}
示例10: readFrom
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Reads from channel buffer and populate instance.
*
* @param channelBuffer channelBuffer instance.
* @throws OspfParseException might throws exception while parsing buffer
*/
public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
try {
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.setNetworkMask(Ip4Address.valueOf(tempByteArray));
int unusedByte = channelBuffer.readByte();
this.setMetric(channelBuffer.readUnsignedMedium());
} catch (Exception e) {
log.debug("Error::AsbrSummaryLsa:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
}
}
示例11: read
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Read from channel buffer and Returns BGP header.
*
* @param cb ChannelBuffer
* @return object of BGPHeader
*/
public static BgpHeader read(ChannelBuffer cb) {
byte[] marker = new byte[MARKER_LENGTH];
byte type;
short length;
cb.readBytes(marker, 0, MARKER_LENGTH);
length = cb.readShort();
type = cb.readByte();
return new BgpHeader(marker, length, type);
}
示例12: processHandshake
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private Object processHandshake(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
buf.readByte(); // semicolon symbol
if (getDeviceSession(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII)) != null) {
sendReply(channel, ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<S", StandardCharsets.US_ASCII));
}
return null;
}
示例13: read
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Reads from the channel buffer and returns Object of PcepLSObject.
*
* @param cb of type channel buffer
* @return Object of PcepLSObject
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepLSObject read(ChannelBuffer cb) throws PcepParseException {
log.debug("read");
PcepObjectHeader lsObjHeader;
byte protocolId;
// 2-flags
boolean removeFlag;
boolean syncFlag;
long lsId;
List<PcepValueType> optionalTlvList;
lsObjHeader = PcepObjectHeader.read(cb);
//take only LSObject buffer.
ChannelBuffer tempCb = cb.readBytes(lsObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
protocolId = tempCb.readByte();
//ignore first two bytes of Flags
tempCb.readShort();
Integer iTemp = (int) tempCb.readByte(); //read 3rd byte Flag
syncFlag = (iTemp & FLAG_SET_S_FLAG) == FLAG_SET_S_FLAG;
removeFlag = (iTemp & FLAG_SET_R_FLAG) == FLAG_SET_R_FLAG;
lsId = tempCb.readLong();
// parse optional TLV
optionalTlvList = parseOptionalTlv(tempCb);
return new PcepLSObjectVer1(lsObjHeader, protocolId, removeFlag, syncFlag, lsId, optionalTlvList);
}
示例14: readFrom
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public PcepCloseMsg readFrom(ChannelBuffer cb) throws PcepParseException {
if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException("Packet size is less than the minimum length.");
}
// fixed value property version == 1
byte version = cb.readByte();
version = (byte) (version >> SHIFT_FLAG);
if (version != PACKET_VERSION) {
throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), got=" + version);
}
// fixed value property type == 7
byte type = cb.readByte();
if (type != MSG_TYPE.getType()) {
throw new PcepParseException("Wrong type. Expected=PcepType.CLOSE(7), got=" + type);
}
short length = cb.readShort();
if (length < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: "
+ length);
}
closeObjHeader = PcepObjectHeader.read(cb);
// Reserved
cb.readShort();
// Flags
cb.readByte();
// Reason
yReason = cb.readByte();
// parse optional TLV
llOptionalTlv = parseOptionalTlv(cb);
return new PcepCloseMsgVer1(closeObjHeader, yReason, llOptionalTlv);
}
示例15: read
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Reads from channel buffer and returns object of PcepOpenObject.
*
* @param cb of type channel buffer
* @return object of PcepOpenObject
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepOpenObject read(ChannelBuffer cb) throws PcepParseException {
PcepObjectHeader openObjHeader;
byte version;
byte keepAliveTime;
byte deadTime;
byte sessionID;
LinkedList<PcepValueType> llOptionalTlv;
openObjHeader = PcepObjectHeader.read(cb);
version = cb.readByte();
version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
if (version != OPEN_OBJECT_VERSION) {
throw new PcepParseException("Wrong version: Expected=PcepVersion.PCEP_1(1), got=" + version);
}
/* Keepalive */
keepAliveTime = cb.readByte();
/* DeadTimer */
deadTime = cb.readByte();
/* SID */
sessionID = cb.readByte();
// Optional TLV
llOptionalTlv = parseOptionalTlv(cb);
return new PcepOpenObjectVer1(openObjHeader, keepAliveTime, deadTime, sessionID, llOptionalTlv);
}