protected final int decodeLength ( ) { // if we don't have enough bytes to determine our frame size, stop // here and let the caller know that we're not ready if ( _have < HEADER_SIZE ) { return - 1 ; } // decode the frame length _buffer . rewind ( ) ; int length = ( _buffer . get ( ) & 0xFF ) << 24 ; length += ( _buffer . get ( ) & 0xFF ) << 16 ; length += ( _buffer . get ( ) & 0xFF ) << 8 ; length += ( _buffer . get ( ) & 0xFF ) ; _buffer . position ( _have ) ; return length ; }
Decodes and returns the length of the current frame from the buffer if possible . Returns - 1 otherwise .