Библиотека mFast: Как преобразовать каналы, полученные от exchange, в шестнадцатеричный формат в кодировке UTF-8?
Я столкнулся с проблемой в библиотеке mFast ( https://github.com/objectcomputing/mFAST). Когда я получаю данные с биржи и конвертирую их в шестнадцатеричный формат в кодировке UTF-8.
Пример полученных данных ( "201" 20181009-06:49:09.66± Ï€ œ €βcedes ‚_À ôCOCUDAKL20DEC201¸2972³ø2?IÁœ угннвозябн¬нн €‚€Ђ €")
После конвертации приложение требует в формате: пример: "\xE2\x80\x9D\x32\x30\x31"
Я должен добавить \ x перед двумя байтами в строке. поскольку "\" должен быть экранирован, приложение интерпретируется как "\".
Как я могу сделать это один '\'?
Что я пробовал: пробовал с использованием сырых строк. Пробовал с ++/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 )