本文整理汇总了Java中org.apache.mina.core.buffer.IoBuffer.get方法的典型用法代码示例。如果您正苦于以下问题:Java IoBuffer.get方法的具体用法?Java IoBuffer.get怎么用?Java IoBuffer.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.core.buffer.IoBuffer
的用法示例。
在下文中一共展示了IoBuffer.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {
int beginPos = in.position();
int limit = in.limit();
for (int i = beginPos; i < limit; i++) {
byte b = in.get(i);
if (!canSkip(b)) {
in.position(i);
int answer = this.skippedBytes;
this.skippedBytes = 0;
return finishDecode(answer);
}
skippedBytes++;
}
in.position(limit);
return this;
}
示例2: handleData
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void handleData ( final IoBuffer data, final Map<String, Variant> attributes, final Variant timestamp )
{
final byte b = data.get ( toAddress ( this.readIndex ) );
final boolean flag = ( b & 1 << this.readSubIndex ) != 0;
if ( this.invertRead )
{
attributes.put ( this.name, flag ? Variant.FALSE : Variant.TRUE );
}
else
{
attributes.put ( this.name, flag ? Variant.TRUE : Variant.FALSE );
}
if ( !Boolean.valueOf ( flag ).equals ( this.lastValue ) )
{
this.lastValue = flag;
this.lastTimestamp = timestamp;
}
if ( this.enableTimestamp )
{
attributes.put ( this.name + ".timestamp", this.lastTimestamp );
}
}
示例3: readBytesArrayWithPrefix
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
* Read a set of bytes with the first byte being the number of bytes to read
*
* @param buffer
* the buffer to read from
* @return the result read
*/
private static byte[] readBytesArrayWithPrefix ( final IoBuffer buffer )
{
final short numOfBytes = buffer.getUnsigned ();
logger.trace ( "Prepare to read {} bytes", numOfBytes );
final byte[] result = new byte[numOfBytes];
buffer.get ( result, 0, numOfBytes );
return result;
}
示例4: decodeResponseData
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private void decodeResponseData ( final IoBuffer data, final ProtocolDecoderOutput output, final int sequence ) throws ProtocolCodecException
{
final byte nin = data.get ();
final Object[] vars = new Object[nin];
for ( int i = 0; i < nin; i++ )
{
vars[i] = decodeData ( data );
}
final DataMessage msg = new DataMessage ( sequence, CommandCode.RESPOND_DATA, vars );
output.write ( msg );
}
示例5: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.ae.data.message.StartBrowse decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.ae.data.message.StartBrowse ();
}
示例6: decode
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {
boolean found = false;
boolean finished = false;
while (in.hasRemaining()) {
byte b = in.get();
if (!hasCR) {
if (b == CR) {
hasCR = true;
} else {
if (b == LF) {
found = true;
} else {
in.position(in.position() - 1);
found = false;
}
finished = true;
break;
}
} else {
if (b == LF) {
found = true;
finished = true;
break;
}
throw new ProtocolDecoderException("Expected LF after CR but was: " + (b & 0xff));
}
}
if (finished) {
hasCR = false;
return finishDecode(found, out);
}
return this;
}
示例7: isCloseNotify
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private boolean isCloseNotify(Object message) {
if (!(message instanceof IoBuffer)) {
return false;
}
IoBuffer buf = (IoBuffer) message;
int offset = buf.position();
return (buf.get(offset + 0) == 0x15) /* Alert */
&& (buf.get(offset + 1) == 0x03) /* TLS/SSL */
&& ((buf.get(offset + 2) == 0x00) /* SSL 3.0 */
|| (buf.get(offset + 2) == 0x01) /* TLS 1.0 */
|| (buf.get(offset + 2) == 0x02) /* TLS 1.1 */
|| (buf.get(offset + 2) == 0x03)) /* TLS 1.2 */
&& (buf.get(offset + 3) == 0x00); /* close_notify */
}
示例8: inlindeDecodeValueEntry
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
protected static org.eclipse.scada.hd.data.ValueEntry inlindeDecodeValueEntry ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// number of fields
final byte numberOfFields = _data.get ();
// decode attributes
String valueType = null;
java.util.List<Double> values = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
valueType = _context.decodeString ( _data );
}
break;
case 2:
{
values = _context.decodeDoubleList ( _data );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.hd.data.ValueEntry ( valueType, values );
}
示例9: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.ae.data.message.SubscribeMonitorPool decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
String monitorPoolId = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
monitorPoolId = _context.decodeString ( _data );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.ae.data.message.SubscribeMonitorPool ( monitorPoolId );
}
示例10: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.ca.data.message.GetConfigurationRequest decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
org.eclipse.scada.core.data.Request request = null;
String factoryId = null;
String configurationId = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
request = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeRequest ( _context, _data, false );
}
break;
case 2:
{
factoryId = _context.decodeString ( _data );
}
break;
case 3:
{
configurationId = _context.decodeString ( _data );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.ca.data.message.GetConfigurationRequest ( request, factoryId, configurationId );
}
示例11: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.ca.data.message.ErrorResponse decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
org.eclipse.scada.core.data.Response response = null;
org.eclipse.scada.core.data.ErrorInformation errorInformation = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
response = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeResponse ( _context, _data, false );
}
break;
case 2:
{
errorInformation = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeErrorInformation ( _context, _data, false );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.ca.data.message.ErrorResponse ( response, errorInformation );
}
示例12: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.core.data.message.SessionRejected decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
String errorReason = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
errorReason = _context.decodeString ( _data );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.core.data.message.SessionRejected ( errorReason );
}
示例13: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.core.data.message.SessionAccepted decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
java.util.Map<String, String> properties = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
properties = _context.decodeProperties ( _data );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.core.data.message.SessionAccepted ( properties );
}
示例14: decode
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public MessageDecoderResult decode(IoSession session, IoBuffer buf, ProtocolDecoderOutput out) throws Exception {
CjyTcpMessage message = new CjyTcpMessage();
logger.info("收到采集仪消息" + buf.getHexDump());
buf.mark();
//帧起始符 0x68
buf.get();
// 获取设备编码
int address_i = buf.getInt();
message.setAddress(CommUtils.highAndLowAddressSwap(address_i));
//帧起始符 0x16
if ( buf.get() != 0x68){
return null;
}
//控制码
byte control = buf.get();
message.setD7(control >> 7);
message.setD6(control >> 6);
//控制码 , 协议簇
message.setCmd(control&0x0f);
//数据体长度
int length = buf.get();
message.setLength(length);
//数据体
byte[] data = MessageUtil.getBytes(buf, length);
message.setData(data);
//CRC
byte crc = (buf.get());
//结束标志
int finished = buf.get();
if ( finished != 0x16 ){
return MessageDecoderResult.NOT_OK;
}
buf.reset();
//获取校验位前字节
byte[] cpData = MessageUtil.getBytes(buf, 8 + length);
int t = 0;
for( int i =0; i< cpData.length; i ++){
t += cpData[i];
}
int crc_cal = (t%256) ;
logger.info("获取的CRC值" + (crc & 0xFF) + ",计算的crc值:" + crc_cal + ",address:" + message.getAddress());
//如果校验码校验不通过,则为无效消息
if ( (crc & 0xFF) != (crc_cal & 0xFF)){
return MessageDecoderResult.NOT_OK;
}
buf.get();
buf.get();
out.write(message);
return MessageDecoderResult.OK;
}
示例15: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public org.eclipse.scada.core.data.message.RespondCallbacks decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
org.eclipse.scada.core.data.Response response = null;
java.util.List<org.eclipse.scada.core.data.CallbackResponse> callbacks = null;
org.eclipse.scada.core.data.ErrorInformation errorInformation = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
response = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeResponse ( _context, _data, false );
}
break;
case 2:
{
callbacks = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeListCallbackResponse ( _context, _data, true );
}
break;
case 3:
{
errorInformation = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeErrorInformation ( _context, _data, true );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.core.data.message.RespondCallbacks ( response, callbacks, errorInformation );
}