Encoding properly handles indices/lengths of more than one octet