Merge lp:~zorba-coders/zorba/ft-base64Binary into lp:zorba
- ft-base64Binary
- Merge into trunk
Status: | Superseded | ||||
---|---|---|---|---|---|
Proposed branch: | lp:~zorba-coders/zorba/ft-base64Binary | ||||
Merge into: | lp:zorba | ||||
Diff against target: |
1268 lines (+756/-104) 31 files modified
ChangeLog (+1/-0) include/zorba/item.h (+22/-0) include/zorba/item_factory.h (+19/-0) modules/com/zorba-xquery/www/modules/converters/base64.xq (+6/-3) modules/org/expath/ns/file.xq.src/file.cpp (+8/-13) modules/org/expath/ns/file.xq.src/file_function.cpp (+20/-4) src/api/item.cpp (+23/-0) src/api/itemfactoryimpl.cpp (+20/-1) src/api/itemfactoryimpl.h (+7/-0) src/api/options.cpp (+1/-0) src/api/serialization/serializer.cpp (+86/-40) src/runtime/base64/base64_impl.cpp (+53/-21) src/store/api/item.h (+8/-1) src/store/api/item_factory.h (+25/-0) src/store/naive/atomic_items.cpp (+223/-6) src/store/naive/atomic_items.h (+97/-8) src/store/naive/item.cpp (+19/-1) src/store/naive/simple_item_factory.cpp (+30/-3) src/store/naive/simple_item_factory.h (+13/-0) src/types/casting.cpp (+12/-1) src/zorbaserialization/zorba_class_serializer.cpp (+25/-2) src/zorbatypes/binary.cpp (+10/-0) test/rbkt/ExpQueryResults/zorba/base64/binary_1.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/base64/file_read_1.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/base64/file_read_2.xml.res (+1/-0) test/rbkt/Queries/zorba/base64/binary_1.xq (+1/-0) test/rbkt/Queries/zorba/base64/decoded-text (+1/-0) test/rbkt/Queries/zorba/base64/encoded (+1/-0) test/rbkt/Queries/zorba/base64/encoded-text (+1/-0) test/rbkt/Queries/zorba/base64/file_read_1.xq (+10/-0) test/rbkt/Queries/zorba/base64/file_read_2.xq (+11/-0) |
||||
To merge this branch: | bzr merge lp:~zorba-coders/zorba/ft-base64Binary | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Zorba Coders | Pending | ||
Review via email: mp+94074@code.launchpad.net |
This proposal has been superseded by a proposal from 2012-02-22.
Commit message
more efficient implementation of xs:base64Binary items
Description of the change
more efficient implementation of xs:base64Binary items
Zorba Build Bot (zorba-buildbot) wrote : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/ft-base64Binary into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job ft-base64Binary
The final status was:
7 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
- 10672. By Matthias Brantner
-
- added missing reference result
- restored functionality of the binary emitter that was changed in the previous commit - 10673. By Matthias Brantner
-
- improved getBase64Binary
Value
- added getBase64BinaryValue function to public api - 10674. By Matthias Brantner
-
implemented reviewer comments
Unmerged revisions
Preview Diff
1 | === modified file 'ChangeLog' |
2 | --- ChangeLog 2012-02-21 19:20:00 +0000 |
3 | +++ ChangeLog 2012-02-22 04:06:19 +0000 |
4 | @@ -20,6 +20,7 @@ |
5 | * Fixed bug #911585 (management of variables during eval) |
6 | * Fixed bug #866423 (fn:empty and fn:exists iterators must reset their input in |
7 | case of early-out) |
8 | + * More efficient implementation for base64Binary items |
9 | * Added index management function to the C++ api's StaticCollectionManager. |
10 | * Fixed bug #872288 (reset recursive flag during node rename) |
11 | * Fixed bug #905041 (allow for the default element and function namespaces to be |
12 | |
13 | === modified file 'include/zorba/item.h' |
14 | --- include/zorba/item.h 2012-01-11 17:30:25 +0000 |
15 | +++ include/zorba/item.h 2012-02-22 04:06:19 +0000 |
16 | @@ -363,6 +363,28 @@ |
17 | std::istream& |
18 | getStream(); |
19 | |
20 | + /** |
21 | + * Returns true if the contents of a binary item is already encoded |
22 | + * |
23 | + * @return true if the content is already encoded, false otherwise |
24 | + */ |
25 | + bool |
26 | + isEncoded() const; |
27 | + |
28 | + /** |
29 | + * Returns the value and size of the given base64Binary item |
30 | + * |
31 | + * The value is a string which is base64 encoded if isEncoded() |
32 | + * returns true. Otherwise, it is the original unencoded binary |
33 | + * data. |
34 | + * |
35 | + * If the given item is streamable (i.e. isStreamable() returns true), |
36 | + * the stream returned by getStream() needs to be used to retrieve |
37 | + * the value. |
38 | + */ |
39 | + const char* |
40 | + getBase64BinaryValue(size_t& s) const; |
41 | + |
42 | /** \brief Returns the name of the collection this node is stored in. |
43 | * |
44 | * @return The name of the collection or 0 if the given item is not |
45 | |
46 | === modified file 'include/zorba/item_factory.h' |
47 | --- include/zorba/item_factory.h 2012-01-11 17:30:25 +0000 |
48 | +++ include/zorba/item_factory.h 2012-02-22 04:06:19 +0000 |
49 | @@ -149,6 +149,25 @@ |
50 | virtual Item |
51 | createBase64Binary(const unsigned char* aBinData, size_t aLength) = 0; |
52 | |
53 | + /** \brief Creates a streamable Base64Binary Item |
54 | + * see [http://www.w3.org/TR/xmlschema-2/#base64Binary] |
55 | + * |
56 | + * @param stream An istream whence to read the binary's content. |
57 | + * @param streamReleaser A function pointer which is invoked once |
58 | + * the StreamableBase64Binary is destroyed. Normally this function |
59 | + * will delete the std::istream object passed to it. |
60 | + * @param seekable is the given stream seekable |
61 | + * @param encoded is the contents of the given stream already base64 |
62 | + * encoded |
63 | + * @return The streamable String Item |
64 | + */ |
65 | + virtual Item |
66 | + createStreamableBase64Binary( |
67 | + std::istream &stream, |
68 | + StreamReleaser streamReleaser, |
69 | + bool seekable = false, |
70 | + bool encoded = false) = 0; |
71 | + |
72 | /** \brief Creates a Boolean Item |
73 | * see [http://www.w3.org/TR/xmlschema-2/#bool] |
74 | * |
75 | |
76 | === modified file 'modules/com/zorba-xquery/www/modules/converters/base64.xq' |
77 | --- modules/com/zorba-xquery/www/modules/converters/base64.xq 2011-08-01 10:18:53 +0000 |
78 | +++ modules/com/zorba-xquery/www/modules/converters/base64.xq 2012-02-22 04:06:19 +0000 |
79 | @@ -28,14 +28,17 @@ |
80 | declare namespace ver = "http://www.zorba-xquery.com/options/versioning"; |
81 | declare option ver:module-version "2.0"; |
82 | |
83 | - |
84 | (:~ |
85 | : Decode a xs:base64Binary. |
86 | : |
87 | + : The function assumes that the content after decoding is valid |
88 | + : UTF-8. |
89 | + : |
90 | : @param $base64 The xs:base64Binary item to decode |
91 | - : @return the decoded xs:base64Binary item as string |
92 | + : @return the base64 decoded value as string |
93 | :) |
94 | -declare function base64:decode($base64 as xs:base64Binary) as xs:string external; |
95 | +declare function base64:decode($base64 as xs:base64Binary) |
96 | +as xs:string external; |
97 | |
98 | (:~ |
99 | : Encode a xs:string as xs:base64Binary. |
100 | |
101 | === modified file 'modules/org/expath/ns/file.xq.src/file.cpp' |
102 | --- modules/org/expath/ns/file.xq.src/file.cpp 2012-02-16 14:11:02 +0000 |
103 | +++ modules/org/expath/ns/file.xq.src/file.cpp 2012-02-22 04:06:19 +0000 |
104 | @@ -144,19 +144,14 @@ |
105 | // actual read |
106 | Item lItem; |
107 | try { |
108 | - std::ifstream lInStream; |
109 | - lFile->openInputStream(lInStream, true, false); |
110 | - |
111 | - std::stringstream lStrStream; |
112 | - char lBuf[1024]; |
113 | - while (!lInStream.eof()) { |
114 | - lInStream.read(lBuf, 1024); |
115 | - lStrStream.write(lBuf, lInStream.gcount()); |
116 | - } |
117 | - |
118 | - String lContent(lStrStream.str()); |
119 | - String lEncodedContent = encoding::Base64::encode(lContent); |
120 | - lItem = theModule->getItemFactory()->createBase64Binary(lEncodedContent.data(), lEncodedContent.size()); |
121 | + std::unique_ptr<std::ifstream> lInStream; |
122 | + lInStream.reset( new std::ifstream() ); |
123 | + lFile->openInputStream(*lInStream.get(), true, false); |
124 | + |
125 | + lItem = theModule->getItemFactory()->createStreamableBase64Binary( |
126 | + *lInStream.release(), &FileModule::streamReleaser, true |
127 | + ); |
128 | + |
129 | } catch (ZorbaException& ze) { |
130 | std::stringstream lSs; |
131 | lSs << "An unknown error occured: " << ze.what() << "Can not read file"; |
132 | |
133 | === modified file 'modules/org/expath/ns/file.xq.src/file_function.cpp' |
134 | --- modules/org/expath/ns/file.xq.src/file_function.cpp 2012-02-16 14:11:02 +0000 |
135 | +++ modules/org/expath/ns/file.xq.src/file_function.cpp 2012-02-22 04:06:19 +0000 |
136 | @@ -26,6 +26,7 @@ |
137 | #include <zorba/user_exception.h> |
138 | #include <zorba/util/path.h> |
139 | #include <zorba/xquery_functions.h> |
140 | +#include <zorba/singleton_item_sequence.h> |
141 | #include <zorba/zorba.h> |
142 | |
143 | #include "file_module.h" |
144 | @@ -255,10 +256,25 @@ |
145 | |
146 | // if this is a binary write |
147 | if (lBinary) { |
148 | - Zorba_SerializerOptions lOptions; |
149 | - lOptions.ser_method = ZORBA_SERIALIZATION_METHOD_BINARY; |
150 | - Serializer_t lSerializer = Serializer::createSerializer(lOptions); |
151 | - lSerializer->serialize(aArgs[1], lOutStream); |
152 | + Item lBinaryItem; |
153 | + Iterator_t lContentSeq = aArgs[1]->getIterator(); |
154 | + lContentSeq->open(); |
155 | + while (lContentSeq->next(lBinaryItem)) |
156 | + { |
157 | + if (lBinaryItem.isStreamable() && !lBinaryItem.isEncoded()) |
158 | + { |
159 | + lOutStream << lBinaryItem.getStream().rdbuf(); |
160 | + } |
161 | + else |
162 | + { |
163 | + Zorba_SerializerOptions lOptions; |
164 | + lOptions.ser_method = ZORBA_SERIALIZATION_METHOD_BINARY; |
165 | + Serializer_t lSerializer = Serializer::createSerializer(lOptions); |
166 | + SingletonItemSequence lSeq(lBinaryItem); |
167 | + lSerializer->serialize(&lSeq, lOutStream); |
168 | + } |
169 | + |
170 | + } |
171 | } |
172 | // if we only write text |
173 | else { |
174 | |
175 | === modified file 'src/api/item.cpp' |
176 | --- src/api/item.cpp 2012-02-02 09:56:52 +0000 |
177 | +++ src/api/item.cpp 2012-02-22 04:06:19 +0000 |
178 | @@ -470,6 +470,29 @@ |
179 | // TODO: throw exception |
180 | } |
181 | |
182 | +bool |
183 | +Item::isEncoded() const |
184 | +{ |
185 | + ITEM_TRY |
186 | + SYNC_CODE(AutoLock lock(GENV_STORE.getGlobalLock(), Lock::READ);) |
187 | + |
188 | + return m_item->isEncoded(); |
189 | + ITEM_CATCH |
190 | + // TODO: throw exception |
191 | +} |
192 | + |
193 | +const char* |
194 | +Item::getBase64BinaryValue(size_t& s) const |
195 | +{ |
196 | + ITEM_TRY |
197 | + SYNC_CODE(AutoLock lock(GENV_STORE.getGlobalLock(), Lock::READ);) |
198 | + |
199 | + return m_item->getBase64BinaryValue(s); |
200 | + ITEM_CATCH |
201 | + // TODO: throw exception |
202 | +} |
203 | + |
204 | + |
205 | Item |
206 | Item::getCollectionName() const |
207 | { |
208 | |
209 | === modified file 'src/api/itemfactoryimpl.cpp' |
210 | --- src/api/itemfactoryimpl.cpp 2012-01-11 17:30:25 +0000 |
211 | +++ src/api/itemfactoryimpl.cpp 2012-02-22 04:06:19 +0000 |
212 | @@ -212,13 +212,32 @@ |
213 | std::stringstream lSs; |
214 | while (aEncodedStream.good()) |
215 | { |
216 | - lSs.put(aEncodedStream.get()); |
217 | + char c = aEncodedStream.get(); |
218 | + if (aEncodedStream.good()) |
219 | + { |
220 | + lSs.put(c); |
221 | + } |
222 | } |
223 | std::string lContent = lSs.str(); |
224 | return createBase64Binary(lContent.c_str(), lContent.size()); |
225 | } |
226 | |
227 | |
228 | +Item |
229 | +ItemFactoryImpl::createStreamableBase64Binary( |
230 | + std::istream &stream, |
231 | + StreamReleaser streamReleaser, |
232 | + bool seekable, |
233 | + bool encoded) |
234 | +{ |
235 | + store::Item_t lItem; |
236 | + theItemFactory->createStreamableBase64Binary( |
237 | + lItem, stream, streamReleaser, seekable, encoded |
238 | + ); |
239 | + return &*lItem; |
240 | +} |
241 | + |
242 | + |
243 | Item ItemFactoryImpl::createBoolean(bool aValue) |
244 | { |
245 | store::Item_t lItem; |
246 | |
247 | === modified file 'src/api/itemfactoryimpl.h' |
248 | --- src/api/itemfactoryimpl.h 2012-01-11 17:30:25 +0000 |
249 | +++ src/api/itemfactoryimpl.h 2012-02-22 04:06:19 +0000 |
250 | @@ -69,6 +69,13 @@ |
251 | virtual Item |
252 | createBase64Binary(const unsigned char* aBinData, size_t aLength); |
253 | |
254 | + virtual Item |
255 | + createStreamableBase64Binary( |
256 | + std::istream &stream, |
257 | + StreamReleaser streamReleaser, |
258 | + bool seekable = false, |
259 | + bool encoded = false); |
260 | + |
261 | virtual Item |
262 | createBoolean(bool aValue); |
263 | |
264 | |
265 | === modified file 'src/api/options.cpp' |
266 | --- src/api/options.cpp 2012-01-11 17:30:25 +0000 |
267 | +++ src/api/options.cpp 2012-02-22 04:06:19 +0000 |
268 | @@ -63,6 +63,7 @@ |
269 | else if (strcmp(value, "html") == 0) ser_method = ZORBA_SERIALIZATION_METHOD_HTML; |
270 | else if (strcmp(value, "xhtml") == 0) ser_method = ZORBA_SERIALIZATION_METHOD_XHTML; |
271 | else if (strcmp(value, "text") == 0) ser_method = ZORBA_SERIALIZATION_METHOD_TEXT; |
272 | + else if (strcmp(value, "binary") == 0) ser_method = ZORBA_SERIALIZATION_METHOD_BINARY; |
273 | else |
274 | { |
275 | ; // TODO signal errors for incorrect values? |
276 | |
277 | === modified file 'src/api/serialization/serializer.cpp' |
278 | --- src/api/serialization/serializer.cpp 2012-01-11 17:30:25 +0000 |
279 | +++ src/api/serialization/serializer.cpp 2012-02-22 04:06:19 +0000 |
280 | @@ -368,22 +368,50 @@ |
281 | void serializer::emitter::emit_streamable_item(store::Item* item) |
282 | { |
283 | // Streamable item |
284 | - char buffer[1024]; |
285 | - int rollover = 0; |
286 | - std::streambuf * pbuf; |
287 | - std::streamsize read_bytes; |
288 | - std::istream& is = item->getStream(); |
289 | - |
290 | - // read bytes and do string expansion |
291 | - do |
292 | - { |
293 | - //std::istream::read uses a try/catch internally so the Zorba_Exception is lost: that is why we are using std::streambuf::sgetn |
294 | - pbuf = is.rdbuf(); |
295 | - read_bytes = pbuf->sgetn(buffer + rollover, 1024 - rollover); |
296 | - rollover = emit_expanded_string(buffer, static_cast<zstring::size_type>(read_bytes + rollover)); |
297 | - memmove(buffer, buffer + 1024 - rollover, rollover); |
298 | - } |
299 | - while (read_bytes > 0); |
300 | + store::SchemaTypeCode lTypeCode = item->getTypeCode(); |
301 | + |
302 | + switch (lTypeCode) |
303 | + { |
304 | + case store::XS_STRING: |
305 | + { |
306 | + char buffer[1024]; |
307 | + int rollover = 0; |
308 | + std::streambuf * pbuf; |
309 | + std::streamsize read_bytes; |
310 | + std::istream& is = item->getStream(); |
311 | + |
312 | + // read bytes and do string expansion |
313 | + do |
314 | + { |
315 | + //std::istream::read uses a try/catch internally so the Zorba_Exception is lost: that is why we are using std::streambuf::sgetn |
316 | + pbuf = is.rdbuf(); |
317 | + read_bytes = pbuf->sgetn(buffer + rollover, 1024 - rollover); |
318 | + rollover = emit_expanded_string(buffer, static_cast<zstring::size_type>(read_bytes + rollover)); |
319 | + memmove(buffer, buffer + 1024 - rollover, rollover); |
320 | + } |
321 | + while (read_bytes > 0); |
322 | + break; |
323 | + } |
324 | + case store::XS_BASE64BINARY: |
325 | + { |
326 | + if (item->isEncoded()) |
327 | + { |
328 | + std::istream& is = item->getStream(); |
329 | + char buf[1024]; |
330 | + while (is.good()) |
331 | + { |
332 | + is.read(buf, 1024); |
333 | + tr.write(buf, is.gcount()); |
334 | + } |
335 | + } |
336 | + else |
337 | + { |
338 | + tr << item->getStringValue(); |
339 | + } |
340 | + break; |
341 | + } |
342 | + default: assert(false); |
343 | + } |
344 | |
345 | } |
346 | |
347 | @@ -1866,30 +1894,48 @@ |
348 | ********************************************************************************/ |
349 | void serializer::binary_emitter::emit_item(store::Item* item) |
350 | { |
351 | - xs_base64Binary lValue; |
352 | - |
353 | - // First assume the item is a base64Binary item and try to get its value. |
354 | - try |
355 | - { |
356 | - lValue = item->getBase64BinaryValue(); |
357 | - } |
358 | - catch (...) |
359 | - { |
360 | - // If this fails, then just get the string value of the item and convert |
361 | - // it to base64 |
362 | - zstring lStringValue; |
363 | - item->getStringValue2(lStringValue); |
364 | - Base64::encode(lStringValue, lValue); |
365 | - } |
366 | - |
367 | - std::vector<char> lDecodedData; |
368 | - lValue.decode(lDecodedData); |
369 | - |
370 | - for (std::vector<char>::const_iterator lIter = lDecodedData.begin(); |
371 | - lIter != lDecodedData.end(); |
372 | - ++lIter) |
373 | - { |
374 | - tr << *lIter; |
375 | + if (item->isStreamable()) |
376 | + { |
377 | + std::istream& stream = item->getStream(); |
378 | + if (item->isEncoded()) |
379 | + { |
380 | + tr << Base64::decode(stream); |
381 | + } |
382 | + else |
383 | + { |
384 | + char buf[1024]; |
385 | + while (!stream.eof()) |
386 | + { |
387 | + stream.read(buf, 1024); |
388 | + tr.write(buf, stream.gcount()); |
389 | + } |
390 | + } |
391 | + } |
392 | + else |
393 | + { |
394 | + if (!item->isNode() && |
395 | + item->getTypeCode() == store::XS_BASE64BINARY) |
396 | + { |
397 | + size_t len; |
398 | + const char* value = item->getBase64BinaryValue(len); |
399 | + |
400 | + if (item->isEncoded()) |
401 | + { |
402 | + std::stringstream tmp; |
403 | + tmp.write(value, len); |
404 | + tr << Base64::decode(tmp); |
405 | + } |
406 | + else |
407 | + { |
408 | + tr.write(value, len); |
409 | + } |
410 | + } |
411 | + else |
412 | + { |
413 | + zstring lStringValue; |
414 | + item->getStringValue2(lStringValue); |
415 | + tr << lStringValue; |
416 | + } |
417 | } |
418 | } |
419 | |
420 | |
421 | === modified file 'src/runtime/base64/base64_impl.cpp' |
422 | --- src/runtime/base64/base64_impl.cpp 2011-06-14 17:26:33 +0000 |
423 | +++ src/runtime/base64/base64_impl.cpp 2012-02-22 04:06:19 +0000 |
424 | @@ -22,37 +22,74 @@ |
425 | |
426 | #include "runtime/base64/base64.h" |
427 | |
428 | - |
429 | #include "store/api/item.h" |
430 | #include "store/api/item_factory.h" |
431 | |
432 | namespace zorba { |
433 | |
434 | -bool Base64DecodeIterator::nextImpl(store::Item_t& result, PlanState& planState) const |
435 | +bool Base64DecodeIterator::nextImpl( |
436 | + store::Item_t& result, |
437 | + PlanState& planState) const |
438 | { |
439 | store::Item_t lItem; |
440 | - Base64 lDecodedData; |
441 | zstring lResultString; |
442 | + const char* lContent; |
443 | + size_t lSize; |
444 | + result = NULL; |
445 | |
446 | PlanIteratorState *state; |
447 | DEFAULT_STACK_INIT(PlanIteratorState, state, planState); |
448 | |
449 | - if (consumeNext(lItem, theChildren[0].getp(), planState)) |
450 | - { |
451 | - lDecodedData = lItem->getBase64BinaryValue(); |
452 | - lResultString = lDecodedData.decode().str(); |
453 | + consumeNext(lItem, theChildren[0].getp(), planState); |
454 | + |
455 | + if (lItem->isStreamable()) |
456 | + { |
457 | + if (lItem->isEncoded()) |
458 | + { |
459 | + // decode and eventually transcode |
460 | + lResultString = Base64::decode(lItem->getStream()); |
461 | + } |
462 | + else |
463 | + { |
464 | + // streamable string eventually transcoding |
465 | + GENV_ITEMFACTORY->createStreamableString( |
466 | + result, |
467 | + lItem->getStream(), |
468 | + lItem->getStreamReleaser(), |
469 | + lItem->isSeekable()); |
470 | + } |
471 | + } |
472 | + else |
473 | + { |
474 | + lContent = lItem->getBase64BinaryValue(lSize); |
475 | + |
476 | + if (lItem->isEncoded()) |
477 | + { |
478 | + std::vector<char> encoded(lContent, lContent+lSize); |
479 | + std::vector<char> decoded; |
480 | + Base64::decode(encoded, decoded); |
481 | + lResultString.insert(0, &decoded[0], decoded.size()); |
482 | + } |
483 | + else |
484 | + { |
485 | + lResultString.insert(0, lContent, lSize); |
486 | + } |
487 | + } |
488 | + if (!result) // otherwise it's a streamable string already |
489 | + { |
490 | GENV_ITEMFACTORY->createString(result, lResultString); |
491 | - STACK_PUSH (true, state); |
492 | } |
493 | + STACK_PUSH (true, state); |
494 | |
495 | STACK_END (state); |
496 | } |
497 | |
498 | |
499 | -bool Base64EncodeIterator::nextImpl(store::Item_t& result, PlanState& planState) const |
500 | +bool Base64EncodeIterator::nextImpl( |
501 | + store::Item_t& result, |
502 | + PlanState& planState) const |
503 | { |
504 | store::Item_t lItem; |
505 | - Base64 lBase64; |
506 | zstring lTmpString; |
507 | |
508 | PlanIteratorState* state; |
509 | @@ -61,17 +98,12 @@ |
510 | if (consumeNext(lItem, theChildren[0].getp(), planState)) |
511 | { |
512 | lItem->getStringValue2(lTmpString); |
513 | - Base64::encode(lTmpString, lBase64); |
514 | - if (GENV_ITEMFACTORY->createBase64Binary(result, lBase64)) |
515 | - { |
516 | - STACK_PUSH (true, state); |
517 | - } |
518 | - else |
519 | - { |
520 | - throw XQUERY_EXCEPTION( |
521 | - zerr::ZXQP0025_ITEM_CREATION_FAILED, ERROR_LOC( loc ) |
522 | - ); |
523 | - } |
524 | + // create a base64Binary item |
525 | + // the content is the non-encoded string |
526 | + GENV_ITEMFACTORY->createBase64Binary( |
527 | + result, lTmpString.c_str(), lTmpString.size(), false |
528 | + ); |
529 | + STACK_PUSH (true, state); |
530 | } |
531 | STACK_END (state); |
532 | } |
533 | |
534 | === modified file 'src/store/api/item.h' |
535 | --- src/store/api/item.h 2012-02-07 15:53:23 +0000 |
536 | +++ src/store/api/item.h 2012-02-22 04:06:19 +0000 |
537 | @@ -274,7 +274,14 @@ |
538 | |
539 | /** Accessor for xs:base64Binary |
540 | */ |
541 | - virtual xs_base64Binary getBase64BinaryValue() const; |
542 | + virtual const char* getBase64BinaryValue(size_t& size) const; |
543 | + |
544 | + /** |
545 | + * Checks whether a base64 item's content is already encoded |
546 | + * |
547 | + * @return true only if it is. |
548 | + */ |
549 | + virtual bool isEncoded() const; |
550 | |
551 | /** Accessor for xs:boolean |
552 | */ |
553 | |
554 | === modified file 'src/store/api/item_factory.h' |
555 | --- src/store/api/item_factory.h 2011-12-21 14:40:33 +0000 |
556 | +++ src/store/api/item_factory.h 2012-02-22 04:06:19 +0000 |
557 | @@ -205,6 +205,31 @@ |
558 | virtual bool createBase64Binary(Item_t& result, xs_base64Binary value) = 0; |
559 | |
560 | /** |
561 | + * Specification: [http://www.w3.org/TR/xmlschema-2/#base64Binary] |
562 | + * creates a base64Binary item with the given content |
563 | + * the encoded flag specifies whether the given content is already |
564 | + * base64 encoded or not. |
565 | + */ |
566 | + virtual bool createBase64Binary( |
567 | + Item_t& result, |
568 | + const char* value, |
569 | + size_t size, |
570 | + bool encoded) = 0; |
571 | + |
572 | + /** |
573 | + * Specification: [http://www.w3.org/TR/xmlschema-2/#base64Binary] |
574 | + * the encoded flag specifies whether the given content is already |
575 | + * base64 encoded or not. |
576 | + */ |
577 | + virtual bool createStreamableBase64Binary( |
578 | + Item_t& result, |
579 | + std::istream&, |
580 | + StreamReleaser, |
581 | + bool seekable = false, |
582 | + bool encoded = false) = 0; |
583 | + |
584 | + |
585 | + /** |
586 | * Specification: [http://www.w3.org/TR/xmlschema-2/#bool] |
587 | * @param value |
588 | */ |
589 | |
590 | === modified file 'src/store/naive/atomic_items.cpp' |
591 | --- src/store/naive/atomic_items.cpp 2012-02-15 10:25:02 +0000 |
592 | +++ src/store/naive/atomic_items.cpp 2012-02-22 04:06:19 +0000 |
593 | @@ -3059,6 +3059,45 @@ |
594 | /******************************************************************************* |
595 | class Base64BinaryItem |
596 | ********************************************************************************/ |
597 | +bool |
598 | +Base64BinaryItem::equals( |
599 | + const store::Item* other, |
600 | + long timezone, |
601 | + const XQPCollator* aCollation) const |
602 | +{ |
603 | + if (isEncoded() == other->isEncoded()) |
604 | + { |
605 | + size_t this_size, other_size; |
606 | + const char* this_data = getBase64BinaryValue(this_size); |
607 | + const char* other_data = other->getBase64BinaryValue(other_size); |
608 | + return this_size == other_size && |
609 | + memcmp(this_data, other_data, this_size) == 0; |
610 | + } |
611 | + else |
612 | + { |
613 | + return getStringValue().compare(other->getStringValue()) == 0; |
614 | + } |
615 | +} |
616 | + |
617 | + |
618 | +uint32_t |
619 | +Base64BinaryItem::hash(long timezone, const XQPCollator* aCollation) const |
620 | +{ |
621 | + // always need to hash on the string-value because otherwise |
622 | + // a base64 item that is encoded would have a different hash-value |
623 | + // as a base64 item that is decoded but represents the same binary content |
624 | + return utf8::hash(getStringValue(), aCollation); |
625 | +} |
626 | + |
627 | + |
628 | +const char* |
629 | +Base64BinaryItem::getBase64BinaryValue(size_t& size) const |
630 | +{ |
631 | + size = theValue.size(); |
632 | + return &theValue[0]; |
633 | +} |
634 | + |
635 | + |
636 | store::Item* Base64BinaryItem::getType() const |
637 | { |
638 | return GET_STORE().theSchemaTypeNames[store::XS_BASE64BINARY]; |
639 | @@ -3067,19 +3106,51 @@ |
640 | |
641 | zstring Base64BinaryItem::getStringValue() const |
642 | { |
643 | - return theValue.str(); |
644 | + if (theIsEncoded) |
645 | + { |
646 | + zstring tmp(&theValue[0], theValue.size()); |
647 | + return tmp; |
648 | + } |
649 | + else |
650 | + { |
651 | + std::vector<char> encoded; |
652 | + encoded.reserve(theValue.size()); |
653 | + Base64::encode(theValue, encoded); |
654 | + zstring tmp(&encoded[0], encoded.size()); |
655 | + return tmp; |
656 | + } |
657 | } |
658 | |
659 | |
660 | void Base64BinaryItem::getStringValue2(zstring& val) const |
661 | { |
662 | - val = theValue.str(); |
663 | + if (theIsEncoded) |
664 | + { |
665 | + val.insert(0, &theValue[0], theValue.size()); |
666 | + } |
667 | + else |
668 | + { |
669 | + std::vector<char> encoded; |
670 | + encoded.reserve(theValue.size()); |
671 | + Base64::encode(theValue, encoded); |
672 | + val.insert(0, &encoded[0], encoded.size()); |
673 | + } |
674 | } |
675 | |
676 | |
677 | void Base64BinaryItem::appendStringValue(zstring& buf) const |
678 | { |
679 | - buf += theValue.str(); |
680 | + if (theIsEncoded) |
681 | + { |
682 | + buf.insert(buf.size(), &theValue[0], theValue.size()); |
683 | + } |
684 | + else |
685 | + { |
686 | + std::vector<char> encoded; |
687 | + encoded.reserve(theValue.size()); |
688 | + Base64::encode(theValue, encoded); |
689 | + buf.insert(buf.size(), &encoded[0], encoded.size()); |
690 | + } |
691 | } |
692 | |
693 | |
694 | @@ -3092,9 +3163,155 @@ |
695 | } |
696 | |
697 | |
698 | -uint32_t Base64BinaryItem::hash(long timezone, const XQPCollator* aCollation) const |
699 | -{ |
700 | - return theValue.hash(); |
701 | +/******************************************************************************* |
702 | + class StreamableStringItem |
703 | +********************************************************************************/ |
704 | +zstring StreamableBase64BinaryItem::getStringValue() const |
705 | +{ |
706 | + if (!theIsMaterialized) |
707 | + { |
708 | + materialize(); |
709 | + } |
710 | + return Base64BinaryItem::getStringValue(); |
711 | +} |
712 | + |
713 | + |
714 | +void StreamableBase64BinaryItem::getStringValue2(zstring& val) const |
715 | +{ |
716 | + if (!theIsMaterialized) |
717 | + { |
718 | + materialize(); |
719 | + } |
720 | + Base64BinaryItem::getStringValue2(val); |
721 | +} |
722 | + |
723 | + |
724 | +void StreamableBase64BinaryItem::appendStringValue(zstring& buf) const |
725 | +{ |
726 | + if (!theIsMaterialized) |
727 | + { |
728 | + materialize(); |
729 | + } |
730 | + Base64BinaryItem::appendStringValue(buf); |
731 | +} |
732 | + |
733 | + |
734 | +zstring StreamableBase64BinaryItem::show() const |
735 | +{ |
736 | + if (!theIsMaterialized) |
737 | + { |
738 | + materialize(); |
739 | + } |
740 | + zstring res("xs:base64Binary("); |
741 | + appendStringValue(res); |
742 | + res += ")"; |
743 | + return res; |
744 | +} |
745 | + |
746 | + |
747 | +uint32_t |
748 | +StreamableBase64BinaryItem::hash(long timezone, const XQPCollator* aCollation) const |
749 | +{ |
750 | + if (!theIsMaterialized) |
751 | + { |
752 | + materialize(); |
753 | + } |
754 | + return Base64BinaryItem::hash(timezone, aCollation); |
755 | +} |
756 | + |
757 | + |
758 | +const char* |
759 | +StreamableBase64BinaryItem::getBase64BinaryValue(size_t& s) const |
760 | +{ |
761 | + if (!theIsMaterialized) |
762 | + { |
763 | + materialize(); |
764 | + } |
765 | + return Base64BinaryItem::getBase64BinaryValue(s); |
766 | +} |
767 | + |
768 | + |
769 | +bool StreamableBase64BinaryItem::isStreamable() const |
770 | +{ |
771 | + return true; |
772 | +} |
773 | + |
774 | + |
775 | +bool StreamableBase64BinaryItem::isSeekable() const |
776 | +{ |
777 | + return theIsSeekable; |
778 | +} |
779 | + |
780 | + |
781 | +StreamReleaser StreamableBase64BinaryItem::getStreamReleaser() |
782 | +{ |
783 | + return theStreamReleaser; |
784 | +} |
785 | + |
786 | + |
787 | +void StreamableBase64BinaryItem::setStreamReleaser(StreamReleaser aReleaser) |
788 | +{ |
789 | + theStreamReleaser = aReleaser; |
790 | +} |
791 | + |
792 | + |
793 | +std::istream& StreamableBase64BinaryItem::getStream() |
794 | +{ |
795 | + // a non-seekable stream can only be consumed once |
796 | + // we raise an error if getStream is called twice |
797 | + // if a query requires a stream to be consumed more than once, |
798 | + // the query needs to make sure that the stream is explicitly |
799 | + // materialized before |
800 | + if (!theIsSeekable && theIsConsumed) |
801 | + { |
802 | + throw ZORBA_EXCEPTION( zerr::ZSTR0055_STREAMABLE_STRING_CONSUMED ); |
803 | + } |
804 | + else |
805 | + { |
806 | + // if the stream is seekable, we seek to the beginning. |
807 | + // We are not using theIstream.seekg because the USER_ERROR that is thrown |
808 | + // by Zorba is lost possibly in an internal try/catch of the seekg |
809 | + std::streambuf * pbuf; |
810 | + pbuf = theIstream.rdbuf(); |
811 | + pbuf->pubseekoff(0, std::ios::beg); |
812 | + } |
813 | + theIsConsumed = true; |
814 | + return theIstream; |
815 | +} |
816 | + |
817 | + |
818 | +void StreamableBase64BinaryItem::materialize() const |
819 | +{ |
820 | + StreamableBase64BinaryItem* const s |
821 | + = const_cast<StreamableBase64BinaryItem*>(this); |
822 | + std::istream& lStream = s->getStream(); |
823 | + |
824 | + s->theIsMaterialized = true; |
825 | + s->theIsConsumed = true; |
826 | + |
827 | + if (isSeekable()) |
828 | + { |
829 | + lStream.seekg(0, std::ios::end); |
830 | + size_t len = lStream.tellg(); |
831 | + lStream.seekg(0, std::ios::beg); |
832 | + s->theValue.reserve(len); |
833 | + char buf[1024]; |
834 | + while (lStream.good()) |
835 | + { |
836 | + lStream.read(buf, 1024); |
837 | + s->theValue.insert(s->theValue.end(), buf, buf+lStream.gcount()); |
838 | + } |
839 | + } |
840 | + else |
841 | + { |
842 | + char buf[4048]; |
843 | + while (lStream.good()) |
844 | + { |
845 | + lStream.read(buf, 4048); |
846 | + s->theValue.reserve(s->theValue.size() + lStream.gcount()); |
847 | + s->theValue.insert(s->theValue.end(), buf, buf+lStream.gcount()); |
848 | + } |
849 | + } |
850 | } |
851 | |
852 | |
853 | |
854 | === modified file 'src/store/naive/atomic_items.h' |
855 | --- src/store/naive/atomic_items.h 2012-01-26 19:56:14 +0000 |
856 | +++ src/store/naive/atomic_items.h 2012-02-22 04:06:19 +0000 |
857 | @@ -20,6 +20,7 @@ |
858 | #include <zorba/config.h> |
859 | #include <iostream> |
860 | #include <vector> |
861 | +#include <cstring> |
862 | |
863 | #include <zorba/streams.h> |
864 | #ifndef ZORBA_NO_FULL_TEXT |
865 | @@ -153,7 +154,10 @@ |
866 | |
867 | const zstring& getString() const { return theBaseItem->getString(); } |
868 | |
869 | - xs_base64Binary getBase64BinaryValue() const { return theBaseItem->getBase64BinaryValue(); } |
870 | + const char* getBase64BinaryValue(size_t& s) const |
871 | + { |
872 | + return theBaseItem->getBase64BinaryValue(s); |
873 | + } |
874 | |
875 | xs_hexBinary getHexBinaryValue() const { return theBaseItem->getHexBinaryValue(); } |
876 | |
877 | @@ -2218,30 +2222,115 @@ |
878 | friend class BasicItemFactory; |
879 | |
880 | protected: |
881 | - xs_base64Binary theValue; |
882 | + std::vector<char> theValue; |
883 | + bool theIsEncoded; |
884 | |
885 | protected: |
886 | - Base64BinaryItem(xs_base64Binary aValue) : theValue(aValue) {} |
887 | + Base64BinaryItem(bool aIsEncoded) |
888 | + : theIsEncoded(aIsEncoded) {} |
889 | |
890 | - Base64BinaryItem() {} |
891 | + Base64BinaryItem(const char* aValue, size_t aSize, bool aIsEncoded = true) |
892 | + : theIsEncoded(aIsEncoded) |
893 | + { |
894 | + theValue.reserve(aSize); |
895 | + theValue.insert(theValue.begin(), aValue, aValue + aSize); |
896 | + } |
897 | |
898 | public: |
899 | - xs_base64Binary getBase64BinaryValue() const { return theValue; } |
900 | + const char* getBase64BinaryValue(size_t& data) const; |
901 | |
902 | store::SchemaTypeCode getTypeCode() const { return store::XS_BASE64BINARY; } |
903 | |
904 | store::Item* getType() const; |
905 | |
906 | + bool isEncoded() const { return theIsEncoded; } |
907 | + |
908 | uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; |
909 | |
910 | bool equals( |
911 | const store::Item* other, |
912 | long timezone = 0, |
913 | - const XQPCollator* aCollation = 0 ) const |
914 | - { |
915 | - return theValue.equal(other->getBase64BinaryValue()); |
916 | + const XQPCollator* aCollation = 0 ) const; |
917 | + |
918 | + zstring getStringValue() const; |
919 | + |
920 | + void getStringValue2(zstring& val) const; |
921 | + |
922 | + void appendStringValue(zstring& buf) const; |
923 | + |
924 | + zstring show() const; |
925 | + |
926 | +protected: |
927 | + // used in hash doing simple xor of the data |
928 | + struct hash_functor |
929 | + { |
930 | + uint32_t hash_value; |
931 | + |
932 | + void operator() (char c) |
933 | + { |
934 | + hash_value ^= (uint32_t) c; |
935 | + } |
936 | + }; |
937 | +}; |
938 | + |
939 | + |
940 | +/******************************************************************************* |
941 | + class StreamableBase64BinaryItem |
942 | +********************************************************************************/ |
943 | +class StreamableBase64BinaryItem : public Base64BinaryItem |
944 | +{ |
945 | + friend class BasicItemFactory; |
946 | + |
947 | +protected: |
948 | + std::istream & theIstream; |
949 | + |
950 | + bool theIsMaterialized; |
951 | + bool theIsConsumed; |
952 | + bool theIsSeekable; |
953 | + |
954 | + StreamReleaser theStreamReleaser; |
955 | + |
956 | +protected: |
957 | + StreamableBase64BinaryItem( |
958 | + std::istream& aStream, |
959 | + StreamReleaser streamReleaser, |
960 | + bool seekable = false, |
961 | + bool is_encoded = false) |
962 | + : Base64BinaryItem(is_encoded), |
963 | + theIstream(aStream), |
964 | + theIsMaterialized(false), |
965 | + theIsConsumed(false), |
966 | + theIsSeekable(seekable), |
967 | + theStreamReleaser(streamReleaser) |
968 | + {} |
969 | + |
970 | + void materialize() const; |
971 | + |
972 | +public: |
973 | + virtual ~StreamableBase64BinaryItem() |
974 | + { |
975 | + if (theStreamReleaser) |
976 | + { |
977 | + theStreamReleaser(&theIstream); |
978 | + } |
979 | } |
980 | |
981 | + bool isStreamable() const; |
982 | + |
983 | + bool isSeekable() const; |
984 | + |
985 | + std::istream& getStream(); |
986 | + |
987 | + StreamReleaser getStreamReleaser(); |
988 | + |
989 | + void setStreamReleaser(StreamReleaser aReleaser); |
990 | + |
991 | + const char* getBase64BinaryValue(size_t&) const; |
992 | + |
993 | + store::SchemaTypeCode getTypeCode() const { return store::XS_BASE64BINARY; } |
994 | + |
995 | + uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; |
996 | + |
997 | zstring getStringValue() const; |
998 | |
999 | void getStringValue2(zstring& val) const; |
1000 | |
1001 | === modified file 'src/store/naive/item.cpp' |
1002 | --- src/store/naive/item.cpp 2012-02-15 10:25:02 +0000 |
1003 | +++ src/store/naive/item.cpp 2012-02-22 04:06:19 +0000 |
1004 | @@ -430,7 +430,7 @@ |
1005 | /** |
1006 | * Accessor for xs:base64Binary |
1007 | */ |
1008 | -xs_base64Binary Item::getBase64BinaryValue() const |
1009 | +const char* Item::getBase64BinaryValue(size_t&) const |
1010 | { |
1011 | throw ZORBA_EXCEPTION( |
1012 | zerr::ZSTR0040_TYPE_ERROR, |
1013 | @@ -441,6 +441,24 @@ |
1014 | ); |
1015 | } |
1016 | |
1017 | + |
1018 | +/** |
1019 | + * Checks whether a base64 item's content is already encoded |
1020 | + * |
1021 | + * @return true only if it is. |
1022 | + */ |
1023 | +bool Item::isEncoded() const |
1024 | +{ |
1025 | + throw ZORBA_EXCEPTION( |
1026 | + zerr::ZSTR0040_TYPE_ERROR, |
1027 | + ERROR_PARAMS( |
1028 | + ZED( OperationNotDef_23 ), "Item::isEncoded()", |
1029 | + getType()->getStringValue() |
1030 | + ) |
1031 | + ); |
1032 | +} |
1033 | + |
1034 | + |
1035 | /** |
1036 | * Accessor for xs:boolean |
1037 | */ |
1038 | |
1039 | === modified file 'src/store/naive/simple_item_factory.cpp' |
1040 | --- src/store/naive/simple_item_factory.cpp 2012-02-15 10:25:02 +0000 |
1041 | +++ src/store/naive/simple_item_factory.cpp 2012-02-22 04:06:19 +0000 |
1042 | @@ -997,9 +997,36 @@ |
1043 | } |
1044 | |
1045 | |
1046 | -bool BasicItemFactory::createBase64Binary(store::Item_t& result, xs_base64Binary value) |
1047 | -{ |
1048 | - result = new Base64BinaryItem(value); |
1049 | +bool BasicItemFactory::createBase64Binary( |
1050 | + store::Item_t& result, |
1051 | + xs_base64Binary value) |
1052 | +{ |
1053 | + const std::vector<char>& data = value.getData(); |
1054 | + result = new Base64BinaryItem(&data[0], data.size(), true); |
1055 | + return true; |
1056 | +} |
1057 | + |
1058 | +bool BasicItemFactory::createBase64Binary( |
1059 | + store::Item_t& result, |
1060 | + const char* value, |
1061 | + size_t size, |
1062 | + bool encoded) |
1063 | +{ |
1064 | + result = new Base64BinaryItem(value, size, encoded); |
1065 | + return true; |
1066 | +} |
1067 | + |
1068 | + |
1069 | +bool BasicItemFactory::createStreamableBase64Binary( |
1070 | + store::Item_t& result, |
1071 | + std::istream& aStream, |
1072 | + StreamReleaser aReleaser, |
1073 | + bool seekable, |
1074 | + bool encoded) |
1075 | +{ |
1076 | + result = new StreamableBase64BinaryItem( |
1077 | + aStream, aReleaser, seekable, encoded |
1078 | + ); |
1079 | return true; |
1080 | } |
1081 | |
1082 | |
1083 | === modified file 'src/store/naive/simple_item_factory.h' |
1084 | --- src/store/naive/simple_item_factory.h 2011-12-21 14:40:33 +0000 |
1085 | +++ src/store/naive/simple_item_factory.h 2012-02-22 04:06:19 +0000 |
1086 | @@ -107,6 +107,19 @@ |
1087 | |
1088 | bool createBase64Binary(store::Item_t& result, xs_base64Binary value); |
1089 | |
1090 | + bool createBase64Binary( |
1091 | + store::Item_t& result, |
1092 | + const char* value, |
1093 | + size_t size, |
1094 | + bool encoded); |
1095 | + |
1096 | + bool createStreamableBase64Binary( |
1097 | + store::Item_t& result, |
1098 | + std::istream&, |
1099 | + StreamReleaser, |
1100 | + bool seekable = false, |
1101 | + bool encoded = false); |
1102 | + |
1103 | bool createBoolean(store::Item_t& result, xs_boolean value); |
1104 | |
1105 | |
1106 | |
1107 | === modified file 'src/types/casting.cpp' |
1108 | --- src/types/casting.cpp 2012-01-30 15:23:21 +0000 |
1109 | +++ src/types/casting.cpp 2012-02-22 04:06:19 +0000 |
1110 | @@ -1267,7 +1267,18 @@ |
1111 | |
1112 | T1_TO_T2(b64, hxB) |
1113 | { |
1114 | - return aFactory->createHexBinary(result, xs_hexBinary(aItem->getBase64BinaryValue())); |
1115 | + size_t s; |
1116 | + const char* c = aItem->getBase64BinaryValue(s); |
1117 | + Base64 tmp; |
1118 | + if (aItem->isEncoded()) |
1119 | + { |
1120 | + Base64::parseString(c, s, tmp); |
1121 | + } |
1122 | + else |
1123 | + { |
1124 | + Base64::encode((const unsigned char*)c, s, tmp); |
1125 | + } |
1126 | + return aFactory->createHexBinary(result, xs_hexBinary(tmp)); |
1127 | } |
1128 | |
1129 | |
1130 | |
1131 | === modified file 'src/zorbaserialization/zorba_class_serializer.cpp' |
1132 | --- src/zorbaserialization/zorba_class_serializer.cpp 2012-01-11 17:30:25 +0000 |
1133 | +++ src/zorbaserialization/zorba_class_serializer.cpp 2012-02-22 04:06:19 +0000 |
1134 | @@ -673,8 +673,31 @@ |
1135 | |
1136 | else if(name_of_type == "base64Binary") |
1137 | { |
1138 | - SERIALIZE_REF_FIELD(xs_base64Binary, value, getBase64BinaryValue()); |
1139 | - FINALIZE_SERIALIZE(createBase64Binary, (result, value_in)); |
1140 | + if (ar.is_serializing_out()) |
1141 | + { |
1142 | + size_t s; |
1143 | + const char* c = obj->getBase64BinaryValue(s); |
1144 | + if (obj->isEncoded()) |
1145 | + { |
1146 | + Base64 tmp; |
1147 | + Base64::parseString(c, s, tmp); |
1148 | + ar.dont_allow_delay(); |
1149 | + ar & tmp; |
1150 | + } |
1151 | + else |
1152 | + { |
1153 | + Base64 tmp((const unsigned char*)c, s); |
1154 | + ar.dont_allow_delay(); |
1155 | + ar & tmp; |
1156 | + } |
1157 | + } |
1158 | + else |
1159 | + { |
1160 | + ar.dont_allow_delay(); |
1161 | + Base64 tmp; |
1162 | + ar & tmp; |
1163 | + FINALIZE_SERIALIZE(createBase64Binary, (result, tmp)); |
1164 | + } |
1165 | } |
1166 | else if(name_of_type == "hexBinary") |
1167 | { |
1168 | |
1169 | === modified file 'src/zorbatypes/binary.cpp' |
1170 | --- src/zorbatypes/binary.cpp 2011-06-14 17:26:33 +0000 |
1171 | +++ src/zorbatypes/binary.cpp 2012-02-22 04:06:19 +0000 |
1172 | @@ -306,6 +306,16 @@ |
1173 | } |
1174 | |
1175 | |
1176 | +Base64::Base64(const unsigned char *bin_data, size_t len) |
1177 | +{ |
1178 | + std::vector<char> tmp; |
1179 | + tmp.reserve(len); |
1180 | + tmp.insert(tmp.begin(), (const char*)bin_data, ((const char*)bin_data) + len); |
1181 | + theData.reserve(len); |
1182 | + encode(tmp, theData); |
1183 | +} |
1184 | + |
1185 | + |
1186 | void Base64::serialize(::zorba::serialization::Archiver& ar) |
1187 | { |
1188 | ar & theData; |
1189 | |
1190 | === added directory 'test/rbkt/ExpQueryResults/zorba/base64' |
1191 | === added file 'test/rbkt/ExpQueryResults/zorba/base64/binary_1.xml.res' |
1192 | --- test/rbkt/ExpQueryResults/zorba/base64/binary_1.xml.res 1970-01-01 00:00:00 +0000 |
1193 | +++ test/rbkt/ExpQueryResults/zorba/base64/binary_1.xml.res 2012-02-22 04:06:19 +0000 |
1194 | @@ -0,0 +1,1 @@ |
1195 | +true |
1196 | |
1197 | === added file 'test/rbkt/ExpQueryResults/zorba/base64/file_read_1.xml.res' |
1198 | --- test/rbkt/ExpQueryResults/zorba/base64/file_read_1.xml.res 1970-01-01 00:00:00 +0000 |
1199 | +++ test/rbkt/ExpQueryResults/zorba/base64/file_read_1.xml.res 2012-02-22 04:06:19 +0000 |
1200 | @@ -0,0 +1,1 @@ |
1201 | +true true f0VMRgEBAQAAAAAAAAAAAAMAAwABAAAAIPxDADQAAAD0JTMHAAAAADQAIAAHACgAKAAlAAEAAAAAAAAAAAAAAAAAAAAv22gBL9toAQUAAAAAEAAAAQAAAJTbaAGU62gBlOtoAehnBwAwpgcABgAAAAAQAAACAAAAvKBuAbywbgG8sG4BGAEAABgBAAAGAAAABAAAAAQAAAAUAQAAFAEAABQBAAAkAAAAJAAAAAQAAAAEAAAAUOV0ZKyHJwGshycBrIcnAfyBCAD8gQgABAAAAAQAAABR5XRkAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAABAAAAFLldGSU22gBlOtoAZTraAFs5AUAbOQFAAQAAAABAAAABAAAABQAAAADAAAAR05VANMOFlHRDhyfmkw9H3+lYuAncwGhG0AAAAYDAAAAIAAAEgAAABBkRVIkEIgUIwhRukiBHLCOBAAEAgggoSCCg0CkED5YAAAGFAIgABkACJAAiQAwAFCQEwAQIABBAIIFYAIACAASAAZARACAABkTpAQB5EQIYEF0IBIAIgAhciYEoEICZGgAAQAABCAAkBACZAJAAQQUEhGAIIAAKBULIJYAAABRAKFV4AIWgQAEIYgAAIAAQECAMgBGiCIGiRAEkAABAMAIgEQAAAQAACgIJYAAAEAAAAGAAgtCpFwEAAZRQACAABAICAASiBBFgRhIAkEBMAApJchACQZDAIAAgABIAKQEgKEACGE05FgCAAAgACEAgEAAQoxkUAEAiBAGAAkCFiBoISRFFCBEBMV3gARBgBAosUJBQQAEEDIAUUCBAABAEAhgAEAAAAAAACApACIBBgHKkAWBQAAEAAAAAACDURggAkEEEIlEgIEADQZwAAATC5AQNYxCABABAAAAAAEAlQD0WGD3gAAAIEDKCCAQQMGNIAAQAAAACECCAADAbMAWABABaRAAUFQCgAAAgxJmDAEIAiIZCmIAIAIEgAESCSAjETEQIws2A8AIgAEAAAAAkGkAiEAKDEYEBRGJhFEAIACICAIBKMAGAAAHIAQBqIgAUAECgAAAAhoEER4BASMBBhEIIQGCAFbg8IiBYAgCAQgAgEBwCAAAIAEAQATGAj+QQaAIIQAIAAShAgg2AKQAAAQBkCoASAAAFAAgAYFqAQDCcoOEg0sAIhKAABQAAgpAAghAAIQgIBAkAAQBDA4gRAACAAIgAPBAUgBDARCAggB0GQBaEAg1Mk8CABEAAAQgBBgAECIAvEIhFCRAIBgAAEALyBEQAhACQoIKwAABkBiAVM4QAQlFgBAS4AASAIIkAZEkEgAsBMCABSCAKACAIBMAD4JSLEyAAGQBBqATAUECQUgACQGBGA== |
1202 | |
1203 | === added file 'test/rbkt/ExpQueryResults/zorba/base64/file_read_2.xml.res' |
1204 | --- test/rbkt/ExpQueryResults/zorba/base64/file_read_2.xml.res 1970-01-01 00:00:00 +0000 |
1205 | +++ test/rbkt/ExpQueryResults/zorba/base64/file_read_2.xml.res 2012-02-22 04:06:19 +0000 |
1206 | @@ -0,0 +1,1 @@ |
1207 | +true true true |
1208 | |
1209 | === added directory 'test/rbkt/Queries/zorba/base64' |
1210 | === added file 'test/rbkt/Queries/zorba/base64/binary_1.xq' |
1211 | --- test/rbkt/Queries/zorba/base64/binary_1.xq 1970-01-01 00:00:00 +0000 |
1212 | +++ test/rbkt/Queries/zorba/base64/binary_1.xq 2012-02-22 04:06:19 +0000 |
1213 | @@ -0,0 +1,1 @@ |
1214 | +xs:string(xs:base64Binary("Wm9yYmEgaXMgR3JlYXQhIMOkw7bDvA==")) eq "Wm9yYmEgaXMgR3JlYXQhIMOkw7bDvA==" |
1215 | |
1216 | === added file 'test/rbkt/Queries/zorba/base64/decoded' |
1217 | Binary files test/rbkt/Queries/zorba/base64/decoded 1970-01-01 00:00:00 +0000 and test/rbkt/Queries/zorba/base64/decoded 2012-02-22 04:06:19 +0000 differ |
1218 | === added file 'test/rbkt/Queries/zorba/base64/decoded-text' |
1219 | --- test/rbkt/Queries/zorba/base64/decoded-text 1970-01-01 00:00:00 +0000 |
1220 | +++ test/rbkt/Queries/zorba/base64/decoded-text 2012-02-22 04:06:19 +0000 |
1221 | @@ -0,0 +1,1 @@ |
1222 | +Zorba is Great! äöü |
1223 | \ No newline at end of file |
1224 | |
1225 | === added file 'test/rbkt/Queries/zorba/base64/encoded' |
1226 | --- test/rbkt/Queries/zorba/base64/encoded 1970-01-01 00:00:00 +0000 |
1227 | +++ test/rbkt/Queries/zorba/base64/encoded 2012-02-22 04:06:19 +0000 |
1228 | @@ -0,0 +1,1 @@ |
1229 | +f0VMRgEBAQAAAAAAAAAAAAMAAwABAAAAIPxDADQAAAD0JTMHAAAAADQAIAAHACgAKAAlAAEAAAAAAAAAAAAAAAAAAAAv22gBL9toAQUAAAAAEAAAAQAAAJTbaAGU62gBlOtoAehnBwAwpgcABgAAAAAQAAACAAAAvKBuAbywbgG8sG4BGAEAABgBAAAGAAAABAAAAAQAAAAUAQAAFAEAABQBAAAkAAAAJAAAAAQAAAAEAAAAUOV0ZKyHJwGshycBrIcnAfyBCAD8gQgABAAAAAQAAABR5XRkAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAABAAAAFLldGSU22gBlOtoAZTraAFs5AUAbOQFAAQAAAABAAAABAAAABQAAAADAAAAR05VANMOFlHRDhyfmkw9H3+lYuAncwGhG0AAAAYDAAAAIAAAEgAAABBkRVIkEIgUIwhRukiBHLCOBAAEAgggoSCCg0CkED5YAAAGFAIgABkACJAAiQAwAFCQEwAQIABBAIIFYAIACAASAAZARACAABkTpAQB5EQIYEF0IBIAIgAhciYEoEICZGgAAQAABCAAkBACZAJAAQQUEhGAIIAAKBULIJYAAABRAKFV4AIWgQAEIYgAAIAAQECAMgBGiCIGiRAEkAABAMAIgEQAAAQAACgIJYAAAEAAAAGAAgtCpFwEAAZRQACAABAICAASiBBFgRhIAkEBMAApJchACQZDAIAAgABIAKQEgKEACGE05FgCAAAgACEAgEAAQoxkUAEAiBAGAAkCFiBoISRFFCBEBMV3gARBgBAosUJBQQAEEDIAUUCBAABAEAhgAEAAAAAAACApACIBBgHKkAWBQAAEAAAAAACDURggAkEEEIlEgIEADQZwAAATC5AQNYxCABABAAAAAAEAlQD0WGD3gAAAIEDKCCAQQMGNIAAQAAAACECCAADAbMAWABABaRAAUFQCgAAAgxJmDAEIAiIZCmIAIAIEgAESCSAjETEQIws2A8AIgAEAAAAAkGkAiEAKDEYEBRGJhFEAIACICAIBKMAGAAAHIAQBqIgAUAECgAAAAhoEER4BASMBBhEIIQGCAFbg8IiBYAgCAQgAgEBwCAAAIAEAQATGAj+QQaAIIQAIAAShAgg2AKQAAAQBkCoASAAAFAAgAYFqAQDCcoOEg0sAIhKAABQAAgpAAghAAIQgIBAkAAQBDA4gRAACAAIgAPBAUgBDARCAggB0GQBaEAg1Mk8CABEAAAQgBBgAECIAvEIhFCRAIBgAAEALyBEQAhACQoIKwAABkBiAVM4QAQlFgBAS4AASAIIkAZEkEgAsBMCABSCAKACAIBMAD4JSLEyAAGQBBqATAUECQUgACQGBGA== |
1230 | \ No newline at end of file |
1231 | |
1232 | === added file 'test/rbkt/Queries/zorba/base64/encoded-text' |
1233 | --- test/rbkt/Queries/zorba/base64/encoded-text 1970-01-01 00:00:00 +0000 |
1234 | +++ test/rbkt/Queries/zorba/base64/encoded-text 2012-02-22 04:06:19 +0000 |
1235 | @@ -0,0 +1,1 @@ |
1236 | +Wm9yYmEgaXMgR3JlYXQhIMOkw7bDvA== |
1237 | \ No newline at end of file |
1238 | |
1239 | === added file 'test/rbkt/Queries/zorba/base64/file_read_1.xq' |
1240 | --- test/rbkt/Queries/zorba/base64/file_read_1.xq 1970-01-01 00:00:00 +0000 |
1241 | +++ test/rbkt/Queries/zorba/base64/file_read_1.xq 2012-02-22 04:06:19 +0000 |
1242 | @@ -0,0 +1,10 @@ |
1243 | +import module namespace f = "http://expath.org/ns/file"; |
1244 | + |
1245 | +variable $enc-file-name := resolve-uri("encoded"); |
1246 | +variable $dec-file-name := resolve-uri("decoded"); |
1247 | +variable $base64-1 := f:read-binary($dec-file-name); |
1248 | +variable $base64-2 := f:read-binary($dec-file-name); |
1249 | +variable $ref-result := f:read-text($enc-file-name); |
1250 | + |
1251 | +xs:string($base64-1) eq $ref-result, $base64-1 eq $base64-2, |
1252 | +fn:serialize($base64-1) |
1253 | |
1254 | === added file 'test/rbkt/Queries/zorba/base64/file_read_2.xq' |
1255 | --- test/rbkt/Queries/zorba/base64/file_read_2.xq 1970-01-01 00:00:00 +0000 |
1256 | +++ test/rbkt/Queries/zorba/base64/file_read_2.xq 2012-02-22 04:06:19 +0000 |
1257 | @@ -0,0 +1,11 @@ |
1258 | +import module namespace f = "http://expath.org/ns/file"; |
1259 | +import module namespace b = "http://www.zorba-xquery.com/modules/converters/base64"; |
1260 | + |
1261 | +variable $enc-file-name := resolve-uri("encoded-text"); |
1262 | +variable $dec-file-name := resolve-uri("decoded-text"); |
1263 | +variable $encoded := f:read-text($enc-file-name); |
1264 | +variable $decoded := f:read-text($dec-file-name); |
1265 | + |
1266 | +$encoded eq xs:string(b:encode($decoded)), |
1267 | +xs:base64Binary($encoded) eq b:encode($decoded), |
1268 | +b:decode(xs:base64Binary($encoded)) eq $decoded |
Validation queue starting for merge proposal. zorbatest. lambda. nu:8080/ remotequeue/ ft-base64Binary -2012-02- 22T01-41- 08.742Z/ log.html
Log at: http://