fn parse_tl<T>(tl: u8, i: &mut T) -> Result<SmlTL>
    where T: Iterator<Item=u8>
{
    if tl & TL_ENDOFMSG.1 == TL_ENDOFMSG.0 {
        Ok((TL_ENDOFMSG.0, 0, 0))
    } else if tl & TL_OCTET_STR.1 == TL_OCTET_STR.0 {
        let (size_total, size_net) = parse_tl_len_total(tl, i)?;

        Ok((TL_OCTET_STR.0, size_total, size_net))
    } else if tl & TL_BOOL.1 == TL_BOOL.0 {
        let (size_total, size_net) = parse_tl_len_total(tl, i)?;

        match size_net {
            1 => Ok((TL_BOOL.0, size_total, size_net)),
            _ => Err(SmlError::TLInvalidPrimLen(size_total)),
        }
    } else if tl & TL_INT.1 == TL_INT.0 {
        let (size_total, size_net) = parse_tl_len_total(tl, i)?;

        match size_net {
            1 | 2 | 4 | 8 => Ok((TL_INT.0, size_total, size_net)),
            _ => Err(SmlError::TLInvalidPrimLen(size_total)),
        }
    } else if tl & TL_UINT.1 == TL_UINT.0 {
        let (size_total, size_net) = parse_tl_len_total(tl, i)?;

        match size_net {
            1 | 2 | 4 | 8 => Ok((TL_UINT.0, size_total, size_net)),
            _ => Err(SmlError::TLInvalidPrimLen(size_total)),
        }
    } else if tl & TL_LIST.1 == TL_LIST.0 {
        let (size_total, size_net) = parse_tl_len_net(tl, i)?;

        Ok((TL_LIST.0, size_total, size_net))
    } else {
        Err(SmlError::TLUnknownType)
    }
}
/* parse Type-Length-Field which describes the following message element.
 *
 * bit 0 - bit 3 encode the length of the following data
 *               for simple types this describes the data size in bytes
 *               including the tl field, for lists this describes the
 *               number of list elements, exlusive the tl field
 * bit 4 - bit 6 describes the type of the follwing data
 * bit 7         if set, the following byte encodes an continuation length
 *               field
 *
 * With each continuation length field the current size is shifted 4 bits
 * to the left and the size encoded in the lower 4 bits is added to the
 * result, giving the new length. If bit 7 is set an addition continuation
 * length field follows the current field. Bit 4 to 6 must be zero.
 */
parse Type-Length-Field which describes the following message element.
bit 0 - bit 3 encode the length of the following data
for simple types this describes the data size in bytes
including the tl field, for lists this describes the
number of list elements, exlusive the tl field
bit 4 - bit 6 describes the type of the follwing data
bit 7         if set, the following byte encodes an continuation length
field

With each continuation length field the current size is shifted 4 bits
to the left and the size encoded in the lower 4 bits is added to the
result, giving the new length. If bit 7 is set an addition continuation
length field follows the current field. Bit 4 to 6 must be zero.
parse Type - Length - Field which describes the following message element . bit 0 - bit 3 encode the length of the following data for simple types this describes the data size in bytes including the tl field for lists this describes the number of list elements exlusive the tl field bit 4 - bit 6 describes the type of the follwing data bit 7 if set the following byte encodes an continuation length field With each continuation length field the current size is shifted 4 bits to the left and the size encoded in the lower 4 bits is added to the result giving the new length . If bit 7 is set an addition continuation length field follows the current field . Bit 4 to 6 must be zero .
fn parse_tl<T>(tl: u8, i: &mut T) -> Result<SmlTL>
    where T: Iterator<Item=u8>
{
    if tl & TL_ENDOFMSG.1 == TL_ENDOFMSG.0 {
        Ok((TL_ENDOFMSG.0, 0, 0))
    } else if tl & TL_OCTET_STR.1 == TL_OCTET_STR.0 {
        let (size_total, size_net) = parse_tl_len_total(tl, i)?;
        Ok((TL_OCTET_STR.0, size_total, size_net))
    } else if tl & TL_BOOL.1 == TL_BOOL.0 {
        let (size_total, size_net) = parse_tl_len_total(tl, i)?;
        match size_net {
            1 => Ok((TL_BOOL.0, size_total, size_net)),
            _ => Err(SmlError::TLInvalidPrimLen(size_total)),
        }
    } else if tl & TL_INT.1 == TL_INT.0 {
        let (size_total, size_net) = parse_tl_len_total(tl, i)?;
        match size_net {
            1 | 2 | 4 | 8 => Ok((TL_INT.0, size_total, size_net)),
            _ => Err(SmlError::TLInvalidPrimLen(size_total)),
        }
    } else if tl & TL_UINT.1 == TL_UINT.0 {
        let (size_total, size_net) = parse_tl_len_total(tl, i)?;
        match size_net {
            1 | 2 | 4 | 8 => Ok((TL_UINT.0, size_total, size_net)),
            _ => Err(SmlError::TLInvalidPrimLen(size_total)),
        }
    } else if tl & TL_LIST.1 == TL_LIST.0 {
        let (size_total, size_net) = parse_tl_len_net(tl, i)?;
        Ok((TL_LIST.0, size_total, size_net))
    } else {
        Err(SmlError::TLUnknownType)
    }
}
fn parse_tl < T > ( tl : u8 , i : & mut T ) -> Result < SmlTL > where T : Iterator < Item = u8 > { if tl & TL_ENDOFMSG . 1 == TL_ENDOFMSG . 0 { Ok ( ( TL_ENDOFMSG . 0 , 0 , 0 ) ) } else if tl & TL_OCTET_STR . 1 == TL_OCTET_STR . 0 { let ( size_total , size_net ) = parse_tl_len_total ( tl , i ) ? ; Ok ( ( TL_OCTET_STR . 0 , size_total , size_net ) ) } else if tl & TL_BOOL . 1 == TL_BOOL . 0 { let ( size_total , size_net ) = parse_tl_len_total ( tl , i ) ? ; match size_net { 1 => Ok ( ( TL_BOOL . 0 , size_total , size_net ) ) , _ => Err ( SmlError :: TLInvalidPrimLen ( size_total ) ) , } } else if tl & TL_INT . 1 == TL_INT . 0 { let ( size_total , size_net ) = parse_tl_len_total ( tl , i ) ? ; match size_net { 1 | 2 | 4 | 8 => Ok ( ( TL_INT . 0 , size_total , size_net ) ) , _ => Err ( SmlError :: TLInvalidPrimLen ( size_total ) ) , } } else if tl & TL_UINT . 1 == TL_UINT . 0 { let ( size_total , size_net ) = parse_tl_len_total ( tl , i ) ? ; match size_net { 1 | 2 | 4 | 8 => Ok ( ( TL_UINT . 0 , size_total , size_net ) ) , _ => Err ( SmlError :: TLInvalidPrimLen ( size_total ) ) , } } else if tl & TL_LIST . 1 == TL_LIST . 0 { let ( size_total , size_net ) = parse_tl_len_net ( tl , i ) ? ; Ok ( ( TL_LIST . 0 , size_total , size_net ) ) } else { Err ( SmlError :: TLUnknownType ) } }
parse Type-Length-Field which describes the following message element.
parse Type - Length - Field which describes the following message element .
tl
u8
i
&mut T