iOS 的 c++,c,obj-C,swift 混用 (用在解密服务器发过来的信息)

C++

DecodeConfigurationApiValue.hpp


#ifndef DecodeConfigurationApiValue_hpp

#define DecodeConfigurationApiValue_hpp


#include <stdio.h>

#include <string.h>

#include <stdlib.h>


class DecodeConfigurationApiValue {

public:

    void decodeConfigurationApiValue(const char *encodedString, char &buf);

};


#endif /* DecodeConfigurationApiValue_hpp */



DecodeConfigurationApiValue.cpp

#include "DecodeConfigurationApiValue.hpp"


char AscIIToChar(const char *asc)

{

int num = 0;

char buf[16] = {0};

strncpy(buf, asc, 2);

sscanf(buf, "%02X", &num);

printf("%s:%d\n", buf, num);

return num;

}


void Unescape(const char *from, unsigned long from_len, char *to, int &to_len)

{

int pos = 0;

for(int i=0; i < from_len; i++)

{

if(from[i] == '|')

{

to[pos++] = AscIIToChar(from+i+1);

i+=2;

}

else

{

to[pos++] = from[i];

}

}

to_len = pos;

}


void UNab(const char *from, unsigned long from_len, char *to, int &to_len)

{

Unescape(from, from_len, to, to_len);


to[0] = to[0] - to_len;

for (int i=1; i<to_len; i++)

{

to[i] = to[i] - to[i-1];

}

}


void DecodeConfigurationApiValue::decodeConfigurationApiValue(const char *encodedString, char &buf)

{

//const char *from="|80|DC|E8|E4|E3|ADi|5E|A6|EE|EE|A5gp|A1|D3|CA|D4|E8|A3|91|D2|DC|9C";

  //char buf[2048] = {0};

int to_len = 0;

UNab(encodedString, strlen(encodedString), &buf, to_len);

printf("%s\n%d\n", &buf, to_len);

}




Objective-C

DecodeConfigurationApiValue_Wrapper.h

#ifndef DecodeConfigurationApiValue_Wrapper_h

#define DecodeConfigurationApiValue_Wrapper_h


#import <UIKit/UIKit.h>


@interface DecodeConfigurationApiValue_Wrapper : NSObject


+ (NSString *)decodeConfigurationApiValue_wrapper:(NSString *)strValue;


@end


#endif /* DecodeConfigurationApiValue_Wrapper_h */




DecodeConfigurationApiValue_Wrapper.mm

#import "DecodeConfigurationApiValue_Wrapper.h"

#include "DecodeConfigurationApiValue.hpp"


@implementation DecodeConfigurationApiValue_Wrapper


+ (NSString *)decodeConfigurationApiValue_wrapper:(NSString *)strValue {

    DecodeConfigurationApiValue cpp;

    char buf[2048] = {0};

    cpp.decodeConfigurationApiValue([strValue cStringUsingEncoding:NSUTF8StringEncoding], *buf);

    NSString *result = [NSString stringWithFormat:@"%s", buf];

    return result;

}

@end



VPNOn-Bridging-Header.h

#import "DecodeConfigurationApiValue_Wrapper.h"




ConfigViewController.swift

var strQQ: String?

if let strQQ_temp = jsonConfig["QQ"].string {

    strQQ = DecodeConfigurationApiValue_Wrapper.decodeConfigurationApiValue_wrapper(strQQ_temp)

                                    if let strQQ = strQQ {

                                        NSLog("strQQ = %@", strQQ)

                                    } else {

                                        NSLog("strQQ = null")

                                    }

                                }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值