int length = tlv.getLength(); while ( tlv.getLengthBytesRead() < tlv.getLengthNbBytes() ) tlv.incLengthBytesRead(); length = ( length << 8 ) | ( octet & 0x00FF ); tlv.setLength( length ); if ( tlv.getLengthBytesRead() < tlv.getLengthNbBytes() ) tlv.setLength( length ); container.setState( TLVStateEnum.LENGTH_STATE_END );
/** * Compute the OrFilter length * <br> * OrFilter : * <pre> * 0xA1 L1 super.computeLength() * * Length(OrFilter) = Length(0xA1) + Length(super.computeLength()) + * super.computeLength() * </pre> * * @return The encoded length */ @Override public int computeLength() { filtersLength = super.computeLength(); return 1 + TLV.getNbBytes( filtersLength ) + filtersLength; }
/** * Check if the TLV tree is fully decoded * * @param container The container * @return <code>true</code> if the TLV has been decoded */ private boolean isTLVDecoded( Asn1Container container ) { TLV current = container.getCurrentTLV(); TLV parent = current.getParent(); while ( parent != null ) { if ( parent.getExpectedLength() != 0 ) { return false; } parent = parent.getParent(); } BerValue value = current.getValue(); if ( ( value != null ) && ( value.getData() != null ) ) { return current.getExpectedLength() == value.getData().length; } else { return current.getExpectedLength() == 0; } }
/** * {@inheritDoc} */ @Override public void updateParent() { TLV parentTlv = tlv.getParent(); while ( ( parentTlv != null ) && ( parentTlv.getExpectedLength() == 0 ) ) { parentTlv = parentTlv.getParent(); } this.parentTLV = parentTlv; }
/** * Dump the current TLV tree * * @param container The container */ private void dumpTLVTree( Asn1Container container ) { StringBuilder sb = new StringBuilder(); TLV current = container.getCurrentTLV(); sb.append( "TLV" ).append( Asn1StringUtils.dumpByte( current.getTag() ) ).append( "(" ).append( current.getExpectedLength() ).append( ")" ); current = current.getParent(); while ( current != null ) { sb.append( "-TLV" ).append( Asn1StringUtils.dumpByte( current.getTag() ) ).append( "(" ).append( current.getExpectedLength() ).append( ")" ); current = current.getParent(); } if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_01001_TLV_TREE, sb.toString() ) ); } }
int length = tlv.getLength(); tlv.setExpectedLength( length ); container.setParentTLV( tlv ); int expectedLength = parentTLV.getExpectedLength(); int currentLength = tlv.getSize(); parentTLV.setExpectedLength( 0 ); if ( tlv.isConstructed() ) if ( parentTLV.getExpectedLength() != 0 ) parentTLV = parentTLV.getParent(); tlv.setParent( parentTLV ); tlv.setExpectedLength( length ); tlv.setExpectedLength( length ); if ( parentTLV.getExpectedLength() != 0 ) parentTLV = parentTLV.getParent(); parentTLV.setExpectedLength( expectedLength - currentLength ); tlv.setExpectedLength( length ); if ( tlv.isConstructed() )
/** * {@inheritDoc} */ @Override public final void action( C container ) throws DecoderException { TLV tlv = container.getCurrentTLV(); // The Length should not be null, and should be 5 if ( tlv.getLength() != 5 ) { String msg = I18n.err( I18n.ERR_01100_INCORRECT_LENGTH, 5, tlv.getLength() ); LOG.error( msg ); // This will generate a PROTOCOL_ERROR throw new DecoderException( msg ); } byte[] data = tlv.getValue().getData(); setBitString( data, container ); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_01101_BITSTRING_VALUE, Strings.dumpBytes( data ) ) ); } } }
/** * Encode the Referral message to a PDU. * * @param buffer The buffer where to put the PDU * @param referral The referral to encode * @exception EncoderException If the encoding failed */ public static void encodeReferral( ByteBuffer buffer, Referral referral ) throws EncoderException { Collection<byte[]> ldapUrlsBytes = referral.getLdapUrlsBytes(); if ( ( ldapUrlsBytes != null ) && ( !ldapUrlsBytes.isEmpty() ) ) { // Encode the referrals sequence // The referrals length MUST have been computed before ! buffer.put( ( byte ) LdapCodecConstants.LDAP_RESULT_REFERRAL_SEQUENCE_TAG ); buffer.put( TLV.getBytes( referral.getReferralLength() ) ); // Each referral for ( byte[] ldapUrlBytes : ldapUrlsBytes ) { // Encode the current referral BerValue.encode( buffer, ldapUrlBytes ); } } }
public void action( AdDirSyncContainer container ) { BerValue value = container.getCurrentTLV().getValue(); byte[] cookie = value.getData(); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_08000_COOKIE, Strings.dumpBytes( cookie ) ) ); } container.getAdDirSyncControl().setCookie( cookie ); container.setGrammarEndAllowed( true ); } } );
TLV localParent = tlv.getParent(); Filter localFilter = terminalFilter; while ( ( localParent != null ) && ( localParent.getExpectedLength() == 0 ) ) if ( localParent.getId() != parentTlvId ) localParent = localParent.getParent(); localParent = localParent.getParent();
public void action( ControlsContainer container ) throws DecoderException { TLV tlv = container.getCurrentTLV(); int expectedLength = tlv.getLength(); // The Length should be null if ( expectedLength == 0 ) { String msg = I18n.err( I18n.ERR_08213_NULL_CONTROL_LENGTH ); LOG.error( msg ); // This will generate a PROTOCOL_ERROR throw new DecoderException( msg ); } } } );
/** * {@inheritDoc} */ @Override public int getTlvId() { return tlv.getId(); }
/** * {@inheritDoc} */ @Override public void rewind() { int start = stream.position() - 1 - tlv.getLengthNbBytes(); stream.position( start ); }
int length = tlv.getLength(); tlv.setExpectedLength( length ); container.setParentTLV( tlv ); int expectedLength = parentTLV.getExpectedLength(); int currentLength = tlv.getSize(); parentTLV.setExpectedLength( 0 ); if ( tlv.isConstructed() ) if ( parentTLV.getExpectedLength() != 0 ) parentTLV = parentTLV.getParent(); tlv.setParent( parentTLV ); tlv.setExpectedLength( length ); tlv.setExpectedLength( length ); if ( parentTLV.getExpectedLength() != 0 ) parentTLV = parentTLV.getParent(); parentTLV.setExpectedLength( expectedLength - currentLength ); tlv.setExpectedLength( length ); if ( tlv.isConstructed() )
public void action( PagedResultsContainer container ) { BerValue value = container.getCurrentTLV().getValue(); if ( container.getCurrentTLV().getLength() == 0 ) { container.getDecorator().setCookie( Strings.EMPTY_BYTES ); } else { container.getDecorator().setCookie( value.getData() ); } // We can have an END transition container.setGrammarEndAllowed( true ); } } );
/** * Encode the Referral message to a PDU. * * @param buffer The buffer where to put the PDU * @param referral The referral to encode * @exception EncoderException If the encoding failed */ public static void encodeReferral( ByteBuffer buffer, Referral referral ) throws EncoderException { Collection<byte[]> ldapUrlsBytes = referral.getLdapUrlsBytes(); if ( ( ldapUrlsBytes != null ) && ( !ldapUrlsBytes.isEmpty() ) ) { // Encode the referrals sequence // The referrals length MUST have been computed before ! buffer.put( ( byte ) LdapCodecConstants.LDAP_RESULT_REFERRAL_SEQUENCE_TAG ); buffer.put( TLV.getBytes( referral.getReferralLength() ) ); // Each referral for ( byte[] ldapUrlBytes : ldapUrlsBytes ) { // Encode the current referral BerValue.encode( buffer, ldapUrlBytes ); } } }
@Override public void action( SortRequestContainer container ) throws DecoderException { BerValue value = container.getCurrentTLV().getValue(); String matchingRuleOid = Strings.utf8ToString( value.getData() ); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_05309_MATCHING_RULE_OID, matchingRuleOid ) ); } container.getCurrentKey().setMatchingRuleId( matchingRuleOid ); container.setGrammarEndAllowed( true ); }
TLV localParent = tlv.getParent(); Filter localFilter = terminalFilter; while ( ( localParent != null ) && ( localParent.getExpectedLength() == 0 ) ) if ( localParent.getId() != parentTlvId ) localParent = localParent.getParent(); localParent = localParent.getParent();
public void action( ControlsContainer container ) throws DecoderException { TLV tlv = container.getCurrentTLV(); int expectedLength = tlv.getLength(); // The Length should be null if ( expectedLength == 0 ) { String msg = I18n.err( I18n.ERR_08213_NULL_CONTROL_LENGTH ); LOG.error( msg ); // This will generate a PROTOCOL_ERROR throw new DecoderException( msg ); } } } );