@ TargetApi ( Build . VERSION_CODES . GINGERBREAD ) public static Pdu parse ( byte [ ] bytes , int startIndex ) { Pdu pdu = null ; if ( bytes . length - startIndex >= 2 ) { byte length = bytes [ startIndex ] ; if ( length > 0 ) { byte type = bytes [ startIndex + 1 ] ; int firstIndex = startIndex + 2 ; if ( firstIndex < bytes . length ) { pdu = new Pdu ( ) ; // The End index is the startIndex + the length, because the first byte is the // length field and the length field does not include the length field itself in // the count pdu . mEndIndex = startIndex + length ; if ( pdu . mEndIndex >= bytes . length ) { pdu . mEndIndex = bytes . length - 1 ; } pdu . mType = type ; pdu . mDeclaredLength = length ; pdu . mStartIndex = firstIndex ; pdu . mBytes = bytes ; } } } return pdu ; }
Parse a PDU from a byte array looking offset by startIndex