org.apache.mina.core.buffer.IoBuffer Java Examples

The following examples show how to use org.apache.mina.core.buffer.IoBuffer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SkippingState.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@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;
}
 
Example #2
Source File: ProtocolDecoderImpl.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private boolean processWriteResult ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
    final int len = messageLength ( data );
    if ( len < 0 )
    {
        return false;
    }

    try
    {
        final int operationId = data.getInt ();
        final int errorCode = data.getUnsignedShort ();
        final String errorMessage = decodeString ( session, data );

        out.write ( new WriteResult ( operationId, errorCode, errorMessage ) );
    }
    catch ( final CharacterCodingException e )
    {
        throw new ProtocolCodecException ( e );
    }

    return true;
}
 
Example #3
Source File: ShortIntegerDecodingState.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {

    while (in.hasRemaining()) {
        switch (counter) {
        case 0:
            highByte = in.getUnsigned();
            break;
        case 1:
            counter = 0;
            return finishDecode((short) ((highByte << 8) | in.getUnsigned()), out);
        default:
            throw new InternalError();
        }

        counter++;
    }
    return this;
}
 
Example #4
Source File: DefaultBinaryContext.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private <T extends Collection<Variant>> T decodeVariantCollection ( final IoBuffer buffer, final CollectionAllocator<Variant, T> allactor ) throws Exception
{
    final byte type = checkType ( buffer, TYPE_VARIANT_LIST, true );

    if ( type == TYPE_NULL )
    {
        return null;
    }
    else
    {
        final int items = buffer.getInt ();
        final T result = allactor.allocate ( items );
        fillVariantCollection ( buffer, items, result );
        return result;
    }
}
 
Example #5
Source File: ServerProtocolTCPDecoder.java    From seed with Apache License 2.0 6 votes vote down vote up
/**
 * 该方法相当于预读取,用于判断是否是可用的解码器,这里对IoBuffer读取不会影响数据包的大小
 * 该方法结束后IoBuffer会复原,所以不必担心调用该方法时,position已经不在缓冲区起始位置
 */
@Override
public MessageDecoderResult decodable(IoSession session, IoBuffer in) {
    //in.remaining()=in.limit()-in.position();
    if(in.remaining() < 6){
        return MessageDecoderResult.NEED_DATA;
    }
    if(session.getLocalAddress().toString().contains(":" + ConfigUtil.INSTANCE.getProperty("server.port.tcp"))){
        byte[] messageLength = new byte[6];
        in.get(messageLength);
        if(in.limit() >= Integer.parseInt(StringUtils.toEncodedString(messageLength, Charset.forName(SeedConstants.DEFAULT_CHARSET)))){
            return MessageDecoderResult.OK;
        }else{
            return MessageDecoderResult.NEED_DATA;
        }
    }else{
        return MessageDecoderResult.NOT_OK;
    }
}
 
Example #6
Source File: ObjectSerializationProtocol.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public DataMessage encodeMessage ( final Object message ) throws Exception
{
    if ( ! ( message instanceof Serializable ) )
    {
        if ( message != null )
        {
            throw new NotSerializableException ( message.getClass ().getName () );
        }
        else
        {
            throw new NotSerializableException ();
        }
    }

    final IoBuffer data = IoBuffer.allocate ( 64 );
    data.setAutoExpand ( true );
    data.putObject ( message );
    data.flip ();
    return new DataMessage ( data );
}
 
Example #7
Source File: TestRTMPProtocolDecoder.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecodeBuffer() {
    log.debug("\ntestDecodeBuffer");
    RTMPProtocolDecoder dec = new RTMPProtocolDecoder();
    List<Object> objs;
    RTMPConnection conn = new RTMPMinaConnection();
    conn.getState().setState(RTMP.STATE_CONNECTED);
    conn.setHandler(this);
    IoBuffer p00 = IoBuffer.wrap(IOUtils.hexStringToByteArray(
            "8639ae8685ad4e802fb905a7918b480416b013e0632e41773e6ba30a1ee089ddb94df6eff6b59aa6251a2707215a2907dc6b51a749ff6680b37792b6c302d43e80f4780361ab7b3c79de5f917aece673e6192e0d45606a5a56dc23ee8113b3381a5d428074f461db71f8caaefa650517809b63edc8412c1f88b4e4d43584ca491a89dfdbb78df1b00c1cedc8e2139fe831becd70527adf4d17760c1cbfff47a1116aaa8f603d3f5319a0688bbc215c1cae1cfb06b6546abd4b76cc7f32cbc84b4531ba2f539d6ae5c4c081bcc51a73b7c14881f8b6bddb480d8a4430b98577f15d31215480d6ebb9cb56931ad3703c2bf024c943b3c45c18717d467387141cdcc88f389548bc335b10ead0daf8e8c69e67f43099ab1f5f2afcb343c08d4b065ec7ce3a437d9891ec8388155d5bdae8dcfd6b4419df2d9c7ca584511e240cc6b1f04ccc098a74d5037c921e4f5916affa17ff71daed20d621687b12bd3f7fcb8f538360b39eb237ca05ada13dc433dc10c2504c55e5ca2e6528b3279eb49e4629218acfc33fce315c58533076d7e3fff6e49650d4283c8fa4ee766f93fc3d10b10bd10b8c2393e2a1da4e6c53dcc5ddbd6efd7b844b7546b0472346b9229cdb6e8d45f70f1e6d23b96cbb2c41fcd486e25fef021e19568c4617248e58ca195fb7aad5ca34dcf27ac7f03dc71a8b4831d1bbb273f6bba56ed9cdf49eef6c45df5071d19d9e8e23fb33b34a65648141cd61db72f79fa7944e3232cd8e30ba310d566fdac6d51b683a3c27af315ca5dc0f614d62c6672e97c036d181e00d6cf08b41a130d7a24783ad616593dc10753959529657f94aec63fa073ae24afe44b2d7075164ebc25305db954607b92c1c7ded5f88e587227ce411010292b6e392aeaeca456d64dadec73cac5de51ec2d3b530db0cdb9869fbdabe1f0aae10bcc1479dc927178a323ac0b2c1def11a086605ee0a66d5a9f1652b5b5860cdbd3594c8e2511c004d8704ccb2732197f37e687753ce0ed00717f20ca6e7076fd4d06b49ba8c665a2adc41e702753225868ace398baebb6944c29c149b838fb71b1e8c20ed3c9561129867c56bc800be10f8dba659f37bbe2242b0cbdcf342396e5ee61f327e7759500d4647e313937c81809b602af08493812ca199698ed35de9ebeded83e1ef5d8f8ad56c368acd7a6d7a05118541bf9d60bc3e45d64431a7700770c814f48f5dcd1c35270a5288b8cbde9333b5b8c40dfd6f0d31d51bea52e0bc6e6e4f46b1bfe85268a494a83d20668829dcfa492325e5f372f45a74bc19c9be07eda5bb1060376b0563081f541801b7d7ce5f7408e5bb11f63d0638419f7cb8aaaa55afa32dfb1e4f0df11fc355ad6c30405b8824f8fff87feeb3b5390cde76040008bb422200a571cd0c19fda9df620ad6ca881c833728081e7cefecc78b280cc06b4c7de3d1c9cebc04d84e1c43fb9fc8b52cc07e0eb15012872c0739322b1da9d7888b6c0f968863ac571837fd63457f98d574665e3cbe1f3b497fb03d1ab8e481985732de26051919d0aba7f18281d8f512b05a625746e4dd50e0c4be16ab4b59aa3cf24e1648ee9d74e4f3b2a92fc7828a5eb2040a706d52e354fb079df3062d404c46fb78de4931caac381020c5bf6b38fecdc5f7d66c3ea3fb087f4ed8ac98a81a24a42053282c7524c2953a5885c1ff5d736d46c472d318312f2a427dc3526fd513c88dbb8583d607031c0a2825f9e74428b859d8874e0cb013b458b27d549a41e4330682dac90e073b79c458dcb2cba317f816bd2dabdcee96d77ab6466021a23a932d134ba33279956aae938787a3a59216b53d50dc0554fe34b5f51d1e050f84e03a7442b29604684291a2ee79198a3911f8a54a1e47c0bf9ec25114f60dae43d4aa4639e5a5c89010ba3884014c2721cab878795f22ba8136f7d4685c9a5c348bda08b60a1ff1afe6d5578d52f5051eeafa9e3b9501701a272a880aaeb30fbc2db66a5e48d7c811a56c9a809c92567d8a10472c142f3dc38c0123e20ed3feb067a550e0a997b38061e191a3bb5b47a04ef70fdd94e69bfc9be160d8a8cc7dc163e8d595cc987c1d676a7b543f56305be60921c19113be5ea988c864b636e216c1c6d71319e0c96b58eb619ac63016ffb97761b79a3eea0016cfacadc7c10300000100014d1400000000020007636f6e6e656374003ff0000000000000030003617070020003766f640008666c61736856657202000e4c4e582032302c302c302c323836000673776655726c020036687474703a2f2f6c6f63616c686f73743a353038302f766f642f6d696e69706c617965722e7377662f5b5b44594e414d49435d5d2f320005746355c3726c02001972746d703a2f2f6c6f63616c686f73743a313933352f766f640004667061640100000c6361706162696c697469657300406de00000000000000b617564696f436f646563730040abee0000000000000b766964656f436f6465637300406f800000000000000d766964656f46756e6374696f6e003ff00000000000c30000077061676555726c020024687474703a2f2f6c6f63616c686f73743a353038302f766f642f696e6465782e68746d6c000e6f626a656374456e636f64696e67004008000000000000000009"));
    p00.position(1536);
    objs = dec.decodeBuffer(conn, p00);
    log.debug("Objects #00: {}", objs);
    assertNotNull("Objects should not be null", objs);
    assertFalse("Objects should not be empty", objs.isEmpty());
    assertEquals("Method should be 'connect'", "connect", ((Invoke) ((Packet) objs.get(0)).getMessage()).getCall().getServiceMethodName());

    IoBuffer p01 = IoBuffer.wrap(IOUtils.hexStringToByteArray(
            "030000000001431400000000020007636f6e6e656374003ff0000000000000030003617070020003766f640008666c61736856657202000e4c4e582032302c302c302c323836000673776655726c020036687474703a2f2f6c6f63616c686f73743a353038302f766f642f6d696e69706c617965722e7377662f5b5b44594e414d49435d5d2f320005746355c3726c02001972746d703a2f2f6c6f63616c686f73743a313933352f766f640004667061640100000c6361706162696c697469657300406de00000000000000b617564696f436f646563730040abee0000000000000b766964656f436f6465637300406f800000000000000d766964656f46756e6374696f6e003ff00000000000c30000077061676555726c02001a687474703a2f2f6c6f63616c686f73743a353038302f766f642f000e6f626a656374456e636f64696e6700400800000000000000000902fffe410000040500000000009896800300003100001a11000000000002000c63726561746553747265616d00400000000000000005"));
    objs = dec.decodeBuffer(conn, p01);
    log.debug("Objects #01: {}", objs);
}
 
Example #8
Source File: FASTCodec.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
private boolean doRealDecode(
		IoSession session,
		IoBuffer in,
		ProtocolDecoderOutput out) throws IOException, ConverterException {
       int startPosition = in.position();
       byte[] data = new byte[in.remaining()];
       in.get(data);
       DecodeResult decodeResult = decoder.decode(data, getInputContext(session), settings.isLengthPresent());
       boolean isSuccessDecoded = decodeResult.isSuccess();
       if (isSuccessDecoded) {
           IMessage decodedMessage = decodeResult.getDecodedMessage();
           fillMessageMetadata(session, in, decodedMessage);
           out.write(decodedMessage);
       }
       in.position(startPosition + decodeResult.getProcessedDataLength());
       return isSuccessDecoded;
}
 
Example #9
Source File: AbstractIoSession.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * TODO Add method documentation
 */
public final void increaseWrittenMessages(WriteRequest request, long currentTime) {
    Object message = request.getMessage();
    if (message instanceof IoBuffer) {
        IoBuffer b = (IoBuffer) message;
        if (b.hasRemaining()) {
            return;
        }
    }

    writtenMessages++;
    lastWriteTime = currentTime;
    if (getService() instanceof AbstractIoService) {
        ((AbstractIoService) getService()).getStatistics().increaseWrittenMessages(currentTime);
    }

    decreaseScheduledWriteMessages();
}
 
Example #10
Source File: DefaultBinaryContext.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void encodeBooleanCollection ( final IoBuffer buffer, final byte fieldNumber, final Collection<Boolean> data ) throws Exception
{
    buffer.put ( fieldNumber );
    if ( data != null )
    {
        buffer.put ( TYPE_BOOLEAN_LIST );
        buffer.putInt ( data.size () );
        // FIXME: encode as bit array
        for ( final Boolean entry : data )
        {
            buffer.put ( entry ? (byte)0xFF : (byte)0x00 );
        }
    }
    else
    {
        buffer.put ( TYPE_NULL );
    }
}
 
Example #11
Source File: ModbusRequestBlock.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void writeData ( final int blockAddress, byte[] data )
{
    if ( this.request.getType () != RequestType.HOLDING )
    {
        throw new IllegalStateException ( String.format ( "Modbus can only write data when the block is of type %s", RequestType.HOLDING ) );
    }
    if ( data.length == 2 )
    {
        final IoBuffer buffer = IoBuffer.wrap ( data );
        buffer.order ( this.dataOrder );
        final int value = buffer.getUnsignedShort ();
        this.slave.writeCommand ( new WriteSingleDataRequest ( this.transactionId.incrementAndGet (), this.slave.getSlaveAddress (), Constants.FUNCTION_CODE_WRITE_SINGLE_REGISTER, toWriteAddress ( blockAddress ), value ), this.request.getTimeout () );
    }
    else
    {
        data = ModbusProtocol.encodeData ( data, this.dataOrder ); // apply requested byte order
        this.slave.writeCommand ( new WriteMultiDataRequest ( this.transactionId.incrementAndGet (), this.slave.getSlaveAddress (), Constants.FUNCTION_CODE_WRITE_MULTIPLE_REGISTERS, toWriteAddress ( blockAddress ), data, data.length / 2 ), this.request.getTimeout () );
    }
    requestUpdate ();
}
 
Example #12
Source File: BinaryProtocol.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object decodeMessage ( final DataMessage message ) throws Exception
{
    final IoBuffer data = message.getData ();

    // we only peek
    final int messageCode = data.getInt ( 0 );

    logger.trace ( "Decoding message: {}", messageCode );

    final BinaryMessageCodec codec = this.codeMap.get ( messageCode );
    if ( codec == null )
    {
        throw new IllegalStateException ( String.format ( "Unable to decode unknown message code: 0x%08x", messageCode ) );
    }

    return codec.decodeMessage ( this.context, data );
}
 
Example #13
Source File: DefaultBinaryContext.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void fillBooleanCollection ( final IoBuffer buffer, final int items, final Collection<Boolean> data ) throws Exception
{
    // FIXME: decode as bit array
    for ( int i = 0; i < items; i++ )
    {
        data.add ( buffer.get () != (byte)0x00 );
    }
}
 
Example #14
Source File: Structures.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected static void inlineEncodeResponse ( final BinaryContext context, final IoBuffer data, final org.eclipse.scada.core.data.Response value ) throws Exception
{
    // number of fields
    data.put ( (byte)1 );

    // encode attributes
    org.eclipse.scada.core.protocol.ngp.codec.Structures.encodeRequest ( context, data, (byte)1, value.getRequest () );

}
 
Example #15
Source File: AbstractPollingConnectionlessIoAcceptor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void readHandle( H handle ) throws Exception
{
    IoBuffer readBuf = IoBuffer.allocate( getSessionConfig().getReadBufferSize() );

    SocketAddress remoteAddress = receive( handle, readBuf );

    if ( remoteAddress != null )
    {
        IoSession session = newSessionWithoutLock( remoteAddress, localAddress( handle ) );

        readBuf.flip();

        session.getFilterChain().fireMessageReceived( readBuf );
    }
}
 
Example #16
Source File: RTMPProtocolDecoder.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/**
 * Decodes the buffer data.
 * 
 * @param conn
 *            RTMP connection
 * @param state
 *            Stores state for the protocol, ProtocolState is just a marker interface
 * @param in
 *            IoBuffer of data to be decoded
 * @return one of three possible values:
 * 
 *         <pre>
 * 1. null : the object could not be decoded, or some data was skipped, just continue 
 * 2. ProtocolState : the decoder was unable to decode the whole object, refer to the protocol state 
 * 3. Object : something was decoded, continue
 * </pre>
 * @throws ProtocolException
 *             on error
 */
public Object decode(RTMPConnection conn, RTMPDecodeState state, IoBuffer in) throws ProtocolException {
    //if (log.isTraceEnabled()) {
    //log.trace("Decoding for {}", conn.getSessionId());
    //}
    try {
        final byte connectionState = conn.getStateCode();
        switch (connectionState) {
            case RTMP.STATE_CONNECTED:
                return decodePacket(conn, state, in);
            case RTMP.STATE_ERROR:
            case RTMP.STATE_DISCONNECTING:
            case RTMP.STATE_DISCONNECTED:
                // throw away any remaining input data:
                in.clear();
                return null;
            default:
                throw new IllegalStateException("Invalid RTMP state: " + connectionState);
        }
    } catch (ProtocolException pe) {
        // raise to caller unmodified
        throw pe;
    } catch (RuntimeException e) {
        throw new ProtocolException("Error during decoding", e);
    } finally {
        //if (log.isTraceEnabled()) {
        //log.trace("Decoding finished for {}", conn.getSessionId());
        //}
    }
}
 
Example #17
Source File: StartBrowse.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IoBuffer encodeMessage ( final BinaryContext context, final Object objectMessage ) throws Exception
{
    final IoBuffer data = IoBuffer.allocate ( 5 );
    data.putInt ( MESSAGE_CODE );
    data.put ( (byte)0 ); // number of fields 

    data.flip ();
    return data;
}
 
Example #18
Source File: ObjectSerializationDecoder.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    if (!in.prefixedDataAvailable(4, maxObjectSize)) {
        return false;
    }

    out.write(in.getObject(classLoader));
    return true;
}
 
Example #19
Source File: DefaultBinaryContext.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void encodeBoolean ( final IoBuffer buffer, final byte fieldNumber, final Boolean data ) throws Exception
{
    buffer.put ( fieldNumber );
    if ( data != null )
    {
        buffer.put ( TYPE_BOOLEAN );
        buffer.put ( data ? (byte)0xFF : (byte)0x00 );
    }
    else
    {
        buffer.put ( TYPE_NULL );
    }
}
 
Example #20
Source File: DefaultBinaryContext.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void encodePrimitiveInt ( final IoBuffer buffer, final byte fieldNumber, final int data ) throws Exception
{
    buffer.put ( fieldNumber );
    buffer.put ( TYPE_INT );
    buffer.putInt ( data );
}
 
Example #21
Source File: DaveFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void finishEncode ( final IoBuffer data, final short parameterLen, final short dataLen )
{
    // set parameter len
    data.putShort ( 6, parameterLen );
    // set data len
    data.putShort ( 8, dataLen );
}
 
Example #22
Source File: TestITCHHelper.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
protected IMessage decode(Object lastMessage, ITCHCodec codec) throws Exception {
       if(codec == null) {
           codec = (ITCHCodec)messageHelper.getCodec(serviceContext);
       }
	MockProtocolDecoderOutput decoderOutput = new MockProtocolDecoderOutput();
	IoSession decodeSession = new DummySession();
	IoBuffer toDecode = IoBuffer.wrap( ((IoBuffer)lastMessage).array() );
	boolean decodeResult = codec.doDecode( decodeSession, toDecode, decoderOutput );
	    
	Assert.assertTrue("Decoding error.", decodeResult);
       Assert.assertTrue("Message queue size must not less then 1.", decoderOutput.getMessageQueue().size() >= 1);

	return (IMessage) decoderOutput.getMessageQueue().element();
}
 
Example #23
Source File: PrefixedStringDecoder.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    if (in.prefixedDataAvailable(prefixLength, maxDataLength)) {
        String msg = in.getPrefixedString(prefixLength, charset.newDecoder());
        out.write(msg);
        return true;
    }

    return false;
}
 
Example #24
Source File: Structures.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected static void inlineEncodeValueInformation ( final BinaryContext context, final IoBuffer data, final org.eclipse.scada.hd.data.ValueInformation value ) throws Exception
{
    // number of fields
    data.put ( (byte)5 );

    // encode attributes
    context.encodePrimitiveDouble ( data, (byte)1, value.getQuality () );
    context.encodePrimitiveDouble ( data, (byte)2, value.getManualPercentage () );
    context.encodePrimitiveLong ( data, (byte)3, value.getStartTimestamp () );
    context.encodePrimitiveLong ( data, (byte)4, value.getEndTimestamp () );
    context.encodePrimitiveLong ( data, (byte)5, value.getSourceValues () );

}
 
Example #25
Source File: SorensonVideo.java    From red5-io with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public IoBuffer getKeyframe() {
    if (dataCount > 0) {
        IoBuffer result = IoBuffer.allocate(dataCount);
        result.put(blockData, 0, dataCount);
        result.rewind();
        return result;
    }
    return null;
}
 
Example #26
Source File: SlaveHost.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected Object makeReadReply ( final BaseMessage baseMessage, final boolean[] data )
{
    final byte[] reply = new byte[data.length / 8 + 1];

    for ( int i = 0; i < data.length; i++ )
    {
        if ( data[i] )
        {
            reply[i / 8] = (byte) ( reply[i / 8] | 1 << i % 8 );
        }
    }

    return new ReadResponse ( baseMessage.getTransactionId (), baseMessage.getUnitIdentifier (), baseMessage.getFunctionCode (), IoBuffer.wrap ( reply ) );
}
 
Example #27
Source File: DefaultBinaryContext.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void encodePrimitiveBoolean ( final IoBuffer buffer, final byte fieldNumber, final boolean data ) throws Exception
{
    buffer.put ( fieldNumber );
    buffer.put ( TYPE_BOOLEAN );
    buffer.put ( data ? (byte)0xFF : (byte)0x00 );
}
 
Example #28
Source File: ClientConnection.java    From CXTouch with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send message to device.
 * @param msg
 * @throws IOException
 */
public void sendMessage(Message msg) throws MessageException {
    if (messageSession == null || !messageSession.isConnected()) {
        throw new MessageException("与客户端无连接,无法发送, 当前连接:" + id + ", message ID: " + msg.getId());
    }

    IoBuffer buffer = msg.getBinary();
    buffer.flip();
    messageSession.write(buffer);
}
 
Example #29
Source File: Structures.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected static void inlineEncodeConfigurationInformation ( final BinaryContext context, final IoBuffer data, final org.eclipse.scada.ca.data.ConfigurationInformation value ) throws Exception
{
    // number of fields
    data.put ( (byte)5 );

    // encode attributes
    context.encodeString ( data, (byte)1, value.getFactoryId () );
    context.encodeString ( data, (byte)2, value.getId () );
    context.encodeEnum ( data, (byte)3, value.getState () );
    context.encodeProperties ( data, (byte)4, value.getData () );
    context.encodeString ( data, (byte)5, value.getErrorInformation () );

}
 
Example #30
Source File: AVCVideoTest.java    From red5-io with Apache License 2.0 5 votes vote down vote up
@Test
public void testA7SliceBug() {
    log.info("\n testA7SliceBug");
    Path path = Paths.get("target/test-classes/fixtures/ipadmini-A7.flv");
    try {
        File file = path.toFile();
        log.info("Reading: {}", file.getName());
        FLVReader reader = new FLVReader(file, true);
        ITag tag = null;
        AVCVideo video = new AVCVideo();
        while (reader.hasMoreTags()) {
            tag = reader.readTag();
            int timestamp = tag.getTimestamp();
            log.debug("Tag: {} timestamp: {}", tag.getDataType(), timestamp);
            if (tag.getDataType() == 9) {
                IoBuffer buf = tag.getBody();
                if (video.canHandleData(buf)) {
                    video.addData(buf, tag.getTimestamp());
                }
            }
            // when the audio comes in for ts 2176, check for the 2 proceeding sliced keyframes
            if (timestamp == 2176) {
                assertTrue(video.getKeyframes().length == 2);
            }
        }
        reader.close();
        log.info("Finished reading: {}\n", file.getName());
    } catch (IOException e) {
        e.printStackTrace();
    }
    log.info("testA7SliceBug end\n");
}