Библиотека mFast: Как преобразовать каналы, полученные от exchange, в шестнадцатеричный формат в кодировке UTF-8? - PullRequest
0 голосов
/ 16 октября 2018

Я столкнулся с проблемой в библиотеке mFast (https://github.com/objectcomputing/mFAST). Когда я получаю данные из системы обмена и преобразовываю их в шестнадцатеричный формат в кодировке UTF-8.

Пример полученных данных ("Ýÿ”20181009-06: 49: 09.66 ± Ï € œ €βooden‚ _À € COCUDAKL20DEC201¸2972³ø2? IÁÁβcedescedesβтка ясннгого • € €ЂЂβ маст Очистннному «ö €‚ œ €тим ")

После преобразования приложение требует в формате: пример: "\ xE2 \ x80 \ x9D \ x32 \ x30 \ x31"

Я должен добавить \ x перед двумя байтами в строке. так как '\' нужно экранировать, приложение интерпретирует как '\'.

Как мне сделать его единичным '\'?

Что я пробовал: пробовал с использованием rawстроки. Пробовал c ++ / cli

Мой код:

#include <WinSock2.h>
#include <WS2tcpip.h>
#include <iostream>
#include <string>
#include<conio.h>

#include <mfast.h>
#include <mfast/coder/fast_decoder.h>
#include <mfast/coder/fast_encoder.h>
#include <mfast/json/json.h>
#include <mfast/xml_parser/dynamic_templates_description.h>
#include "FastGWMsgConfig.h"
#include "KSFast.h"
#include <msclr\marshal_cppstd.h>

using std::string;
using std::ostringstream;
using std::cout;
using std::endl;

using mfast::templates_description;
using mfast::dynamic_templates_description;
using mfast::fast_decoder;
using mfast::message_cref;
using mfast::ascii_string_cref;
using mfast::json::encode;


using namespace System;
using namespace System::IO;
using namespace System::Security::Cryptography;
using namespace System::Runtime::InteropServices;
using namespace Text;

int main()
{
    string fast_message;
    msclr::interop::marshal_context context;

    String^ toBeEncoded = gcnew String("Ýÿ”20181009-06:49:09.66±±jÏ€€€‚_À€ôCOCUDAKL20DEC201¸2972³ø2?IÁ€€€€€€€s•€€€€€€€€€€“ö€‚ ");

    String^ finalString;
    array<Byte>^ byteArray = Encoding::UTF8->GetBytes(toBeEncoded);

    int ch = 92;
    char character = (char)ch;

    for each(Byte v in byteArray)
    {
        finalString += String::Format("{0}x{1:X2}", Char::ConvertFromUtf32(92), v);    //Done this to avoid double  '\\' but yet while debugging found '\\' in the 
//String which i think is Causing failure of decoder.decode
        }
        Console::WriteLine("FINAL STRING OBTAINED   \n"+    finalString);

    fast_message = context.marshal_as<string>(finalString);

    const templates_description* descriptions[] = { FastGWMsgConfig::description() };
    fast_decoder decoder;
    decoder.include(descriptions);

    const char* start = fast_message.c_str();
    const char* end = start + fast_message.length();

    message_cref msg = decoder.decode(start, end); //Failure Point.

    cout << "Template id: " << msg.id() << endl;
    cout << "Template name: " << msg.name() << endl;
    cout << endl;

    ascii_string_cref field = static_cast<ascii_string_cref>((msg)[0]);
    cout << "Field id: " << field.id() << endl;
    cout << "Field name: " << field.name() << endl;



    return 0;
}



Exception:Unhandled Exception: System.Runtime.InteropServices.SEHException: External compo
nent has thrown an exception.
   at mfast.fast_decoder.decode(fast_decoder* , message_cref* , SByte** , SByte*
 , Boolean )
...