Refine search
public PUBLISH decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); header(frame.header()); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); topicName = MessageSupport.readUTF(is); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { messageId = is.readShort(); } payload = is.readBuffer(is.available()); if( payload == null ) { payload = new Buffer(0); } return this; }
public SUBSCRIBE decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); header(frame.header()); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { messageId = is.readShort(); } ArrayList<Topic> list = new ArrayList<Topic>(); while(is.available() > 0) { Topic topic = new Topic(MessageSupport.readUTF(is), QoS.values()[is.readByte()]); list.add(topic); } topics = list.toArray(new Topic[list.size()]); return this; }
static protected UTF8Buffer readUTF(DataByteArrayInputStream is) throws ProtocolException { int size = is.readUnsignedShort(); Buffer buffer = is.readBuffer(size); if (buffer == null || buffer.length != size) { throw new ProtocolException("Invalid message encoding"); } return buffer.utf8(); }
protected AckBase decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); messageId = is.readShort(); return this; }
public SUBACK decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); messageId = is.readShort(); grantedQos = is.readBuffer(is.available()).toByteArray(); return this; }
@Override public void onWebSocketBinary(byte[] bytes, int offset, int length) { if (!transportStartedAtLeastOnce()) { LOG.debug("Waiting for MQTTSocket to be properly started..."); try { socketTransportStarted.await(); } catch (InterruptedException e) { LOG.warn("While waiting for MQTTSocket to be properly started, we got interrupted!! Should be okay, but you could see race conditions..."); } } protocolLock.lock(); try { receiveCounter += length; codec.parse(new DataByteArrayInputStream(new Buffer(bytes, offset, length)), length); } catch (Exception e) { onException(IOExceptionSupport.create(e)); } finally { protocolLock.unlock(); } }
@Override public void parse(DataByteArrayInputStream data, int readSize) throws IOException { if (currentBuffer == null) { if (contentLength < scratch.length()) { currentBuffer = scratch; currentBuffer.length = contentLength; } else { currentBuffer = new Buffer(contentLength); } } int length = Math.min(readSize, contentLength - payLoadRead); payLoadRead += data.read(currentBuffer.data, payLoadRead, length); if (payLoadRead == contentLength) { processCommand(); currentParser = initializeHeaderParser(); readSize = readSize - length; if (readSize > 0) { currentParser.parse(data, readSize); } } }
protected Buffer looseUnmarshalBuffer(DataByteArrayInputStream dataIn) throws IOException { Buffer rc = null; if (dataIn.readBoolean()) { int size = dataIn.readInt(); byte[] t = new byte[size]; dataIn.readFully(t); rc = new Buffer(t, 0, size); } return rc; } }
private Buffer readBuffer(DataByteArrayInputStream bais) throws IOException { byte b[] = new byte[bais.readVarInt()]; bais.readFully(b); return new Buffer(b); }
public synchronized Object unmarshal(Buffer sequence) throws IOException { bytesIn.restart(sequence); // DataByteArrayInputStreamStream dis = new DataByteArrayInputStreamStream(new // ByteArrayInputStream(sequence)); if (!sizePrefixDisabled) { int size = bytesIn.readInt(); if (sequence.getLength() - 4 != size) { // throw new IOException("Packet size does not match marshaled // size"); } if (size > maxFrameSize) { throw new IOException( "Frame size of " + (size / (1024 * 1024)) + " MB larger than max allowed " + (maxFrameSize / (1024 * 1024)) + " MB"); } } Object command = doUnmarshal(bytesIn); // if( !cacheEnabled && ((DataStructure)command).isMarshallAware() ) { // ((MarshallAware) command).setCachedMarshalledForm(this, sequence); // } return command; }
public CONNACK decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); is.skip(1); byte c = is.readByte(); if( c >= Code.values().length ) { throw new ProtocolException("Invalid CONNACK encoding"); } code = Code.values()[c]; return this; }
protected void processBuffer(ByteBuffer buffer, int readSize) throws Exception { buffer.flip(); DataByteArrayInputStream dis = new DataByteArrayInputStream(buffer.array()); codec.parse(dis, readSize); receiveCounter += readSize; // clear the buffer buffer.clear(); }
public CONNECT decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); version = is.readByte() & 0xFF; if( version < 4 ) { throw new ProtocolException("Invalid CONNECT frame: protocol name/version mismatch"); version = is.readByte() & 0xFF; if( version != 3 ) { throw new ProtocolException("Invalid CONNECT frame: protocol name/version mismatch"); byte flags = is.readByte(); boolean username_flag = (flags & 0x80) > 0; boolean password_flag = (flags & 0x40) > 0; cleanSession = (flags & 0x02) > 0; keepAlive = is.readShort(); clientId = MessageSupport.readUTF(is); if( clientId.length == 0 ) {
void decode(Buffer buffer) throws PagingException { DataByteArrayInputStream is = new DataByteArrayInputStream(buffer); int length = readFields(is); is.setPos((FILE_HEADER_SIZE / 2) - 8); long expectedChecksum = is.readLong(); CRC32 checksum = new CRC32(); checksum.update(buffer.data, 0, length); if (checksum.getValue() != expectedChecksum) { // Try the 2nd copy.. is.setPos(FILE_HEADER_SIZE / 2); length = readFields(is); is.setPos(FILE_HEADER_SIZE - 8); expectedChecksum = is.readLong(); checksum = new CRC32(); checksum.update(buffer.data, 0, length); if (checksum.getValue() != expectedChecksum) { throw new PagingException("file header corruption detected."); } } }
@Override protected byte readByte() throws IOException { return DataByteArrayInputStream.this.readByte(); }
protected byte[] looseUnmarshalByteArray(DataByteArrayInputStream dataIn) throws IOException { byte rc[] = null; if (dataIn.readBoolean()) { int size = dataIn.readInt(); rc = new byte[size]; dataIn.readFully(rc); } return rc; }
public long tightUnmarshalLong(OpenWireFormat wireFormat, DataByteArrayInputStream dataIn, BooleanStream bs) throws IOException { if (bs.readBoolean()) { if (bs.readBoolean()) { return dataIn.readLong(); } else { return toLong(dataIn.readInt()); } } else { if (bs.readBoolean()) { return toLong(dataIn.readShort()); } else { return 0; } } }