powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / C++ [игнор отключен] [закрыт для гостей] / Как перекодировать в base64?
3 сообщений из 3, страница 1 из 1
Как перекодировать в base64?
    #32597567
Фотография Petro123
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Как перекодировать на клиенте в base64?
================
У кого есть инфа по этому поводу?
В SQL есть поле image. Мне желательно именно средствами через аннотированную схему для XML отправить на сервер. Схема ругается на тип base64.
Именно на строку - <xsd:element name="City" type="bin.base64" />.
Неправильный тип.

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:annotation>
  <xsd:appinfo>
    <sql:relationship name="CustCustOrder"
          parent="Cust"
          parent-key="CustomerID"
          child="CustOrder"
          child-key="CustomerID" />
  </xsd:appinfo>
</xsd:annotation>

  <xsd:element name="Customers" sql:relation="Cust" >
   <xsd:complexType>
     <xsd:sequence>
       <xsd:element name="CustomerID"  type="xsd:integer" />
       <xsd:element name="CompanyName" type="xsd:string" />
       <xsd:element name="City"        type="bin.base64" />
       <xsd:element name="Order" 
                          sql:relation="CustOrder"
                          sql:relationship="CustCustOrder" >
         <xsd:complexType>
          <xsd:attribute name="OrderID" type="xsd:integer" />
         </xsd:complexType>
       </xsd:element>
     </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

</xsd:schema>
 
 
Нало вставить бинарные данные в XML.
...
Рейтинг: 0 / 0
Как перекодировать в base64?
    #32598319
Lepsik
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
возьми attach base64.h

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
//  main.cpp 
//  Autor Konstantin Pilipchuk
//  mailto:lostd@ukr.net
//
#include "base64.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <windows.h>
#include <oleauto.h>


using namespace std;


SAFEARRAY * GetArray(void)
{
   unsigned int i;
   SAFEARRAYBOUND rgsabound[ 1 ];
   rgsabound[ 0 ].lLbound =  0 ;
	int count =  4000 ;
   rgsabound[ 0 ].cElements = count;
   SAFEARRAY * psa = SafeArrayCreate(VT_UI1,  1 , rgsabound);

	char HUGEP *ptr;
	HRESULT hr;
	// Get a pointer to the elements of the array.
	hr = SafeArrayAccessData(psa, (void HUGEP**)&ptr);
   for(i =  0 ; i < count; i++)
   {
	   ptr[i] = ( 32 +i+ 1 ) %  256 ;
   }
   ptr[ 1 ] =  0 ;
	hr = SafeArrayUnaccessData(psa);
   return psa;
}

void test(void)
{
	int state =  0 ;
	SAFEARRAY * psa = GetArray();
	char HUGEP *ptr;
	base64<char> encoder;
	int count = psa->rgsabound->cElements;
	HRESULT hr = SafeArrayAccessData(psa, (void HUGEP**)&ptr);
	{
		ofstream org_ostr("test_out.org.txt", ios::binary);
		ostreambuf_iterator<char> i_org_out(org_ostr);
		for(char HUGEP *p = ptr; p != ptr+count; p++ )
		{
			*i_org_out = *p;
		}

		ofstream ostr("test_out.txt");
		ostreambuf_iterator<char> i_out(ostr);
		encoder.put(ptr, ptr+psa->rgsabound->cElements, i_out, state, base64<>::crlf());
	}

	{   // decode from file ...
		ifstream istr("test_out.txt");
		istreambuf_iterator<char> i_from(istr.rdbuf());
		istreambuf_iterator<char> i_to( 0 );

		// ... to console
	    ostringstream buf;
		//ostreambuf_iterator<char> i_out(cout);
		ofstream ostr("test_out.decoded.txt", ios::binary);
		ostreambuf_iterator<char> i_out(ostr);

		encoder.get(i_from, i_to, i_out, state);
		string s = buf.str();
		int lng = s.length();
	}
	hr = SafeArrayUnaccessData(psa);
}

int main()
{
#if  1 
	test();
	int state =  0 ;
	//base64<char> encoder;
	istringstream sstr;
#else
	{   
		// encode from cin ...
		istream& istr = cin;
		sstr.str("alsdkl;askdoQQQQQQQQQQQQQWWWWWWWWWWWWWWWWWWWWWWWQQQQQQQQQQQQQQQQQQQQQQpkmdkjfiowejioowjfjweof");
		//istreambuf_iterator<char> i_from(istr.rdbuf());
		istreambuf_iterator<char> i_from(sstr.rdbuf());
		istreambuf_iterator<char> i_to( 0 );

		// ... to output file
		ofstream ostr("test_out.txt");
		ostreambuf_iterator<char> i_out(ostr);


		encoder.put(i_from, i_to, i_out, state, base64<>::crlf());
	}
	{   // decode from file ...
		ifstream istr("test_out.txt");
		istreambuf_iterator<char> i_from(istr.rdbuf());
		istreambuf_iterator<char> i_to( 0 );

		// ... to console
	    ostringstream buf;
		//ostreambuf_iterator<char> i_out(cout);
		ostreambuf_iterator<char> i_out(buf);

		encoder.get(i_from, i_to, i_out, state);
		string s = buf.str();
		if(s != sstr.str())
			cout << "error!" << endl;
		else	
			cout << s << endl << sstr.str() << endl << "success!" << endl;
	}
#endif
	return  0 ;
}
...
Рейтинг: 0 / 0
Как перекодировать в base64?
    #32598329
Lepsik
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
вот проще

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
To encode:
 
 int state =  0 ;
    t_ostringstream o_stream; //(ios_base::out);
 base64<_TCHAR> encoder;
    ostream_iterator<_TCHAR, _TCHAR> i_out(o_stream);
    encoder.put(bytes, bytes+size, i_out, state, base64<>::noline());
    tstring result = o_stream.str().c_str();
(end)
 
To decode:
 
    vector<unsigned char>& bytes; // put results here
    bytes.clear();
    base64<_TCHAR> encoder;
    t_istringstream istr;
    istr.str(texture);
    istreambuf_iterator<char> i_from(istr.rdbuf());
    istreambuf_iterator<char> i_to( 0 );
    bytes.reserve(istr.str().length());
    back_insert_iterator<vector<unsigned char> > i_ins(bytes);
    int state =  0 ;
    encoder.get(i_from, i_to, i_ins, state);
(end)
 
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / C++ [игнор отключен] [закрыт для гостей] / Как перекодировать в base64?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]