NCBI C++ ToolKit
objostrasnb.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: objostrasnb.cpp 99877 2023-05-18 17:33:17Z vasilche $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Eugene Vasilchenko
27 *
28 * File Description:
29 * ASN.1 binary object output stream.
30 */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbistd.hpp>
34 #include <corelib/ncbi_limits.hpp>
35 #include <corelib/ncbi_param.hpp>
36 
37 #include <serial/objostrasnb.hpp>
38 #include <serial/objistr.hpp>
39 #include <serial/objcopy.hpp>
40 #include <serial/objistrasnb.hpp>
41 #include <serial/impl/memberid.hpp>
42 #include <serial/enumvalues.hpp>
44 #include <serial/objhook.hpp>
46 #include <serial/impl/choice.hpp>
47 #include <serial/impl/continfo.hpp>
48 #include <serial/delaybuf.hpp>
49 #include <serial/error_codes.hpp>
50 
51 #include <stdio.h>
52 #include <math.h>
53 
54 #undef _TRACE
55 #define _TRACE(arg) ((void)0)
56 
57 #define NCBI_USE_ERRCODE_X Serial_OStream
58 
59 #define USE_OLD_TAGS 0
60 // this is backward compatibility check
61 #define USE_VERIFY_TAGGING 1
62 
64 
65 
67  EOwnership deleteOut)
68 {
69  return new CObjectOStreamAsnBinary(out, deleteOut);
70 }
71 
73  EFixNonPrint how)
75  m_CStyleBigInt(false), m_SkipNextTag(false), m_AutomaticTagging(true)
76 {
77  FixNonPrint(how);
78 #if CHECK_OUTSTREAM_INTEGRITY
79  m_CurrentPosition = 0;
80  m_CurrentTagState = eTagStart;
81  m_CurrentTagLimit = 0;
82 #endif
83 }
84 
86  bool deleteOut,
87  EFixNonPrint how)
89  m_CStyleBigInt(false), m_SkipNextTag(false), m_AutomaticTagging(true)
90 {
91  FixNonPrint(how);
92 #if CHECK_OUTSTREAM_INTEGRITY
93  m_CurrentPosition = 0;
94  m_CurrentTagState = eTagStart;
95  m_CurrentTagLimit = 0;
96 #endif
97 }
98 
100  EOwnership deleteOut,
101  EFixNonPrint how)
102  : CObjectOStream(eSerial_AsnBinary, out, deleteOut),
103  m_CStyleBigInt(false), m_SkipNextTag(false), m_AutomaticTagging(true)
104 {
105  FixNonPrint(how);
106 #if CHECK_OUTSTREAM_INTEGRITY
107  m_CurrentPosition = 0;
108  m_CurrentTagState = eTagStart;
109  m_CurrentTagLimit = 0;
110 #endif
111 }
112 
114 {
115 #if CHECK_OUTSTREAM_INTEGRITY
116  if ( !m_Limits.empty() || m_CurrentTagState != eTagStart )
117  ERR_POST_X(9, "CObjectOStreamAsnBinary not finished");
118 #endif
119 }
120 
121 #if CHECK_OUTSTREAM_INTEGRITY
122 inline
123 void CObjectOStreamAsnBinary::StartTag(Uint1 code)
124 {
125  m_Limits.push(m_CurrentTagLimit);
126  m_CurrentTagCode = code;
127  m_CurrentTagPosition = m_CurrentPosition;
128  m_CurrentTagState = GetTagValue(code) == eLongTag? eTagValue: eLengthStart;
129 }
130 
131 inline
132 void CObjectOStreamAsnBinary::EndTag(void)
133 {
134  if ( m_Limits.empty() )
135  ThrowError(fIllegalCall, "too many tag ends");
136  m_CurrentTagState = eTagStart;
137  m_CurrentTagLimit = m_Limits.top();
138  m_Limits.pop();
139 }
140 
141 inline
142 void CObjectOStreamAsnBinary::SetTagLength(size_t length)
143 {
144  Int8 limit = m_CurrentPosition + 1 + length;
145  if ( limit <= m_CurrentPosition ||
146  (m_CurrentTagLimit != 0 && limit > m_CurrentTagLimit) )
147  ThrowError(fIllegalCall, "tag will overflow enclosing tag");
148  m_CurrentTagLimit = limit;
149  if ( IsTagConstructed(m_CurrentTagCode) ) // constructed
150  m_CurrentTagState = eTagStart;
151  else
152  m_CurrentTagState = eData;
153  if ( length == 0 )
154  EndTag();
155 }
156 #endif
157 
158 #if !CHECK_OUTSTREAM_INTEGRITY
159 inline
160 #endif
162 {
163 #if CHECK_OUTSTREAM_INTEGRITY
164  //_TRACE("WriteByte: " << NStr::PtrToString(byte));
165  if ( m_CurrentTagLimit != 0 &&
166  m_CurrentPosition >= m_CurrentTagLimit )
167  ThrowError(fOverflow, "tag size overflow");
168  switch ( m_CurrentTagState ) {
169  case eTagStart:
170  StartTag(byte);
171  break;
172  case eTagValue:
173  if ( (byte & 0x80) == 0)
174  m_CurrentTagState = eLengthStart;
175  break;
176  case eLengthStart:
177  if ( byte == 0 ) {
178  SetTagLength(0);
179  if ( m_CurrentTagCode == 0 )
180  EndTag();
181  }
182  else if ( byte == 0x80 ) {
183  if ( !IsTagConstructed(m_CurrentTagCode) ) {
185  "cannot use indefinite form for primitive tag");
186  }
187  m_CurrentTagState = eTagStart;
188  }
189  else if ( byte < 0x80 ) {
190  SetTagLength(byte);
191  }
192  else {
193  m_CurrentTagLengthSize = byte - 0x80;
194  if ( m_CurrentTagLengthSize > sizeof(size_t) )
195  ThrowError(fOverflow, "tag length is too big");
196  m_CurrentTagState = eLengthValueFirst;
197  }
198  break;
199  case eLengthValueFirst:
200  if ( byte == 0 )
201  ThrowError(fInvalidData, "first byte of length is zero");
202  if ( --m_CurrentTagLengthSize == 0 ) {
203  SetTagLength(byte);
204  }
205  else {
206  m_CurrentTagLength = byte;
207  m_CurrentTagState = eLengthValue;
208  }
209  break;
210  // fall down to next case (no break needed)
211  case eLengthValue:
212  m_CurrentTagLength = (m_CurrentTagLength << 8) | byte;
213  if ( --m_CurrentTagLengthSize == 0 )
214  SetTagLength(m_CurrentTagLength);
215  break;
216  case eData:
217  _ASSERT( m_CurrentTagLimit != 0);
218  if ( m_CurrentPosition + 1 == m_CurrentTagLimit )
219  EndTag();
220  break;
221  }
222  m_CurrentPosition += 1;
223 #endif
224  m_Output.PutChar(byte);
225 }
226 
227 #if !CHECK_OUTSTREAM_INTEGRITY
228 inline
229 #endif
230 void CObjectOStreamAsnBinary::WriteBytes(const char* bytes, size_t size)
231 {
232  if ( size == 0 )
233  return;
234 #if CHECK_OUTSTREAM_INTEGRITY
235  //_TRACE("WriteBytes: " << size);
236  if ( m_CurrentTagState != eData )
237  ThrowError(fIllegalCall, "WriteBytes only allowed in DATA");
238  Int8 new_pos = m_CurrentPosition + size;
239  if ( new_pos < m_CurrentPosition ||
240  (m_CurrentTagLimit != 0 && new_pos > m_CurrentTagLimit) )
241  ThrowError(fOverflow, "tag DATA overflow");
242  m_CurrentPosition = new_pos;
243  if ( new_pos == m_CurrentTagLimit )
244  EndTag();
245 #endif
246  m_Output.PutString(bytes, size);
247 }
248 
249 template<typename T>
250 inline
252 {
253  for ( size_t shift = (count - 1) * 8; shift > 0; shift -= 8 ) {
254  WriteByte(Uint1(value >> shift));
255  }
257 }
258 
259 inline
261  ETagConstructed tag_constructed,
262  ETagValue tag_value)
263 {
264  if (m_SkipNextTag) {
265  m_SkipNextTag = false;
266  return;
267  }
268  WriteByte(MakeTagByte(tag_class, tag_constructed, tag_value));
269 }
270 
271 inline
273 {
274  if (m_SkipNextTag) {
275  m_SkipNextTag = false;
276  return;
277  }
278  WriteShortTag(eUniversal, ePrimitive, tag_value);
279 }
280 
281 NCBI_PARAM_DECL(bool, SERIAL, WRITE_UTF8STRING_TAG);
282 NCBI_PARAM_DEF_EX(bool, SERIAL, WRITE_UTF8STRING_TAG, false,
283  eParam_NoThread, SERIAL_WRITE_UTF8STRING_TAG);
284 
286 {
287  static CSafeStatic<NCBI_PARAM_TYPE(SERIAL, WRITE_UTF8STRING_TAG)> s_WriteUTF8StringTag;
288  ETagValue value = s_WriteUTF8StringTag->Get() ? eUTF8String: eVisibleString;
290 }
291 
292 inline
294 {
295  static atomic<TByte> s_UTF8StringTag{0};
296  auto tag = s_UTF8StringTag.load(memory_order_acquire);
297  if ( !tag ) {
299  s_UTF8StringTag.store(tag, memory_order_release);
300  }
301  return tag;
302 }
303 
304 inline
306 {
307  if (m_SkipNextTag) {
308  m_SkipNextTag = false;
309  return;
310  }
314 }
315 
317  ETagConstructed tag_constructed,
318  TLongTag tag_value)
319 {
320  if ( tag_value <= 0 )
321  ThrowError(fInvalidData, "negative tag number");
322 
323  // long form
324  WriteShortTag(tag_class, tag_constructed, eLongTag);
325  // calculate largest shift enough for TTag to fit
326  size_t shift = (sizeof(TLongTag) * 8 - 1) / 7 * 7;
327  Uint1 bits;
328  // find first non zero 7bits
329  while ( (bits = (tag_value >> shift) & 0x7f) == 0 ) {
330  shift -= 7;
331  }
332 
333  // beginning of tag
334  while ( shift != 0 ) {
335  shift -= 7;
336  WriteByte(Uint1(tag_value >> shift) | 0x80);
337  }
338  // write remaining bits
339  WriteByte(tag_value & 0x7f);
340 }
341 
342 inline
344  ETagConstructed tag_constructed,
345  TLongTag tag_value)
346 {
347  if (m_SkipNextTag) {
348  m_SkipNextTag = false;
349  return;
350  }
351  if ( tag_value >= 0 && tag_value < eLongTag )
352  WriteShortTag(tag_class, tag_constructed, ETagValue(tag_value));
353  else
354  WriteLongTag(tag_class, tag_constructed, tag_value);
355 }
356 
358 {
359  if (m_SkipNextTag) {
360  m_SkipNextTag = false;
361  return;
362  }
363  const string& tag = typeInfo->GetName();
364  if ( tag.empty() )
365  ThrowError(fInvalidData, "empty tag string");
366 
367  _ASSERT( tag[0] > eLongTag );
368 
369  // long form
371  SIZE_TYPE last = tag.size() - 1;
372  for ( SIZE_TYPE i = 0; i <= last; ++i ) {
373  char c = tag[i];
374  _ASSERT( (c & 0x80) == 0 );
375  if ( i != last )
376  c |= (char)0x80;
377  WriteByte(c);
378  }
379 }
380 
381 inline
383 {
385 }
386 
387 inline
389 {
390  WriteByte(TByte(length));
391 }
392 
394 {
395  // long form
396  size_t count;
397  if ( length <= 0xffU )
398  count = 1;
399  else if ( length <= 0xffffU )
400  count = 2;
401  else if ( length <= 0xffffffU )
402  count = 3;
403  else {
404  count = sizeof(length);
405  if ( sizeof(length) > 4 ) {
406  for ( size_t shift = (count-1)*8;
407  count > 0; --count, shift -= 8 ) {
408  if ( Uint1(length >> shift) != 0 )
409  break;
410  }
411  }
412  }
413  WriteByte(TByte(0x80 + count));
414  WriteBytesOf(length, count);
415 }
416 
417 inline
419 {
420  if ( length <= 127 )
421  WriteShortLength(length);
422  else
423  WriteLongLength(length);
424 }
425 
426 inline
428 {
430  WriteShortLength(0);
431 }
432 
434 {
436  WriteShortLength(0);
437 }
438 
440 {
442  "CObjectOStreamAsnBinary::WriteAnyContentObject: "
443  "unable to write AnyContent object in ASN");
444 }
445 
447 {
449  "CObjectOStreamAsnBinary::CopyAnyContentObject: "
450  "unable to copy AnyContent object in ASN");
451 }
452 
454 {
455 #if BITSTRING_AS_VECTOR
456  bool compressed = false;
457 #else
458  bool compressed = IsCompressed();
459 #endif
460  char* buf=0;
461  size_t len = obj.size();
462  if (compressed) {
463  CBitString::statistics st;
464  obj.calc_stat(&st);
465  buf = (char*)malloc(st.max_serialize_mem);
467  len = 8*bm::serialize(obj, (unsigned char*)buf, tmp_block);
468  bm::aligned_free(tmp_block);
469  }
470 
471  WriteSysTag(compressed ? eOctetString : eBitString);
472  if (len == 0) {
473  WriteLength(0);
474  return;
475  }
476  WriteLength((len+7)/8+(compressed ? 0 : 1));
477  if (!compressed) {
478  WriteByte(TByte(len%8 ? 8-len%8 : 0));
479  }
480  const size_t reserve=128;
481  char bytes[reserve];
482  size_t b=0;
483  Uint1 data, mask;
484  bool done=false;
485 
486 #if BITSTRING_AS_VECTOR
487  for ( CBitString::const_iterator i = obj.begin(); !done; ) {
488  for (data=0, mask=0x80; mask != 0 && !done; mask = Uint1(mask >> 1)) {
489  if (*i) {
490  data |= mask;
491  }
492  done = (++i == obj.end());
493  }
494  bytes[b++] = data;
495  if (b==reserve || done) {
496  WriteBytes(bytes,b);
497  b=0;
498  }
499  }
500 #else
501  if (compressed) {
502  WriteBytes(buf,len/8);
503  free(buf);
504  return;
505  }
507  CBitString::size_type ilast = obj.size();
508  CBitString::enumerator e = obj.first();
509  while (!done) {
510  for (data=0, mask=0x80; !done && mask!=0; mask = Uint1(mask >> 1)) {
511  if (i == *e) {
512  data |= mask;
513  ++e;
514  }
515  done = (++i == ilast);
516  }
517  bytes[b++] = data;
518  if (b==reserve || done) {
519  WriteBytes(bytes,b);
520  b = 0;
521  }
522  }
523 #endif
524 }
525 
527 {
528  CBitString obj;
529  in.ReadBitString(obj);
530  WriteBitString(obj);
531 }
532 
534 {
535  size_t length;
536  if ( data >= Int4(-0x80) && data <= Int4(0x7f) ) {
537  // one byte
538  length = 1;
539  }
540  else if ( data >= Int4(-0x8000) && data <= Int4(0x7fff) ) {
541  // two bytes
542  length = 2;
543  }
544  else if ( data >= Int4(-0x800000) && data <= Int4(0x7fffff) ) {
545  // three bytes
546  length = 3;
547  }
548  else {
549  // full length signed
550  length = sizeof(data);
551  }
552  WriteShortLength(length);
553  WriteBytesOf(data, length);
554 }
555 
557 {
558  size_t length;
559  if ( data >= -Int8(0x80) && data <= Int8(0x7f) ) {
560  // one byte
561  length = 1;
562  }
563  else if ( data >= Int8(-0x8000) && data <= Int8(0x7fff) ) {
564  // two bytes
565  length = 2;
566  }
567  else if ( data >= Int8(-0x800000) && data <= Int8(0x7fffff) ) {
568  // three bytes
569  length = 3;
570  }
571  else if ( data >= NCBI_CONST_INT8(-0x80000000) &&
572  data <= NCBI_CONST_INT8( 0x7fffffff) ) {
573  // four bytes
574  length = 4;
575  }
576  else if ( data >= NCBI_CONST_INT8(-0x8000000000) &&
577  data <= NCBI_CONST_INT8( 0x7fffffffff) ) {
578  // four bytes
579  length = 5;
580  }
581  else if ( data >= NCBI_CONST_INT8(-0x800000000000) &&
582  data <= NCBI_CONST_INT8( 0x7fffffffffff) ) {
583  // four bytes
584  length = 6;
585  }
586  else if ( data >= NCBI_CONST_INT8(-0x80000000000000) &&
587  data <= NCBI_CONST_INT8( 0x7fffffffffffff) ) {
588  // four bytes
589  length = 7;
590  }
591  else {
592  // full length signed
593  length = sizeof(data);
594  }
595  WriteShortLength(length);
596  WriteBytesOf(data, length);
597 }
598 
600 {
601  size_t length;
602  if ( data <= 0x7fU ) {
603  length = 1;
604  }
605  else if ( data <= 0x7fffU ) {
606  // two bytes
607  length = 2;
608  }
609  else if ( data <= 0x7fffffU ) {
610  // three bytes
611  length = 3;
612  }
613  else if ( data <= 0x7fffffffU ) {
614  // four bytes
615  length = 4;
616  }
617  else {
618  // check for high bit to avoid storing unsigned data as negative
619  if ( (data & (Uint4(1) << (sizeof(data) * 8 - 1))) != 0 ) {
620  // full length unsigned - and doesn't fit in signed place
621  WriteShortLength(sizeof(data) + 1);
622  WriteByte(0);
623  WriteBytesOf(data, sizeof(data));
624  return;
625  }
626  else {
627  // full length
628  length = sizeof(data);
629  }
630  }
631  WriteShortLength(length);
632  WriteBytesOf(data, length);
633 }
634 
636 {
637  size_t length;
638  if ( data <= 0x7fUL ) {
639  length = 1;
640  }
641  else if ( data <= 0x7fffUL ) {
642  // two bytes
643  length = 2;
644  }
645  else if ( data <= 0x7fffffUL ) {
646  // three bytes
647  length = 3;
648  }
649  else if ( data <= 0x7fffffffUL ) {
650  // four bytes
651  length = 4;
652  }
653  else if ( data <= NCBI_CONST_UINT8(0x7fffffffff) ) {
654  length = 5;
655  }
656  else if ( data <= NCBI_CONST_UINT8(0x7fffffffffff) ) {
657  length = 6;
658  }
659  else if ( data <= NCBI_CONST_UINT8(0x7fffffffffffff) ) {
660  length = 7;
661  }
662  else if ( data <= NCBI_CONST_UINT8(0x7fffffffffffffff) ) {
663  length = 8;
664  }
665  else {
666  // check for high bit to avoid storing unsigned data as negative
667  if ( (data & (Uint8(1) << (sizeof(data) * 8 - 1))) != 0 ) {
668  // full length unsigned - and doesn't fit in signed place
669  WriteShortLength(sizeof(data) + 1);
670  WriteByte(0);
671  WriteBytesOf(data, sizeof(data));
672  return;
673  }
674  else {
675  // full length
676  length = sizeof(data);
677  }
678  }
679  WriteShortLength(length);
680  WriteBytesOf(data, length);
681 }
682 
684 {
686  WriteShortLength(1);
687  WriteByte(data);
688 }
689 
691 {
693  WriteShortLength(1);
694  WriteByte(data);
695 }
696 
698 {
701 }
702 
704 {
707 }
708 
709 static inline
711 {
713  return type != nullptr && type->GetCodeVersion() < 21600;
714 }
715 
717 {
720  } else {
722  }
724 }
725 
727 {
730  } else {
732  }
734 }
735 
736 static const size_t kMaxDoubleLength = 64;
737 
738 void CObjectOStreamAsnBinary::WriteDouble2(double data, unsigned digits)
739 {
740  char buffer[kMaxDoubleLength + 16];
741  int width = 0;
742  Uint1 type = eDecimal;
744 
745 #if 0
746  if (isnan(data)) {
747  ThrowError(fInvalidData, "invalid double: not a number");
748  }
749  if (!finite(data)) {
750  ThrowError(fInvalidData, "invalid double: infinite");
751  }
752 #else
753 // CXX-5248
754 // for backward compatibility, this stays disabled
755 #if 0
756  if (data == 0.) {
757  double zero = 0.;
758  if (memcmp(&data, &zero, sizeof(double)) == 0) {
759  WriteLength(0);
760  return;
761  }
763  } else
764 #endif
765  if (isnan(data)) {
766  type = eNotANumber;
767  } else if (!finite(data)) {
768  if (data > 0) {
770  } else {
772  }
773  }
774  else
775 #endif
776  if (m_FastWriteDouble) {
777  width = (int)NStr::DoubleToStringPosix(data, digits, buffer, sizeof(buffer));
778  } else {
779  int shift = 0;
780  int precision = int(digits - shift);
781  if ( precision < 0 )
782  precision = 0;
783  else if ( size_t(precision) > kMaxDoubleLength ) // limit precision of data
785 
786  // ensure buffer is large enough to fit result
787  // (additional bytes are for sign, dot and exponent)
788  width = sprintf(buffer, "%.*g", precision, data);
789  if ( width <= 0 || width >= int(sizeof(buffer) - 1) )
790  ThrowError(fOverflow, "buffer overflow");
791  _ASSERT(strlen(buffer) == size_t(width));
792  char* dot = strchr(buffer,',');
793  if (dot) {
794  *dot = '.'; // enforce C locale
795  }
796  }
797 
798  WriteLength(width + 1);
799  if (width) {
800 // CXX-5248
801 // for backward compatibility, this stays disabled
802 #if 0
803  type = eDecimal_NR1;
804  for (const char* p = buffer + width - 1; p >= buffer; --p) {
805  if (*p == '.') {
806  type = eDecimal_NR2;
807  break;
808  } else if (*p == 'e' || *p == 'E') {
809  type = eDecimal_NR3;
810  break;
811  }
812  }
813 #endif
814  WriteByte(type);
815  WriteBytes(buffer, width);
816  } else {
817  WriteByte(type);
818  }
819 }
820 
822 {
823  WriteDouble2(data, DBL_DIG);
824 }
825 
827 {
828  WriteDouble2(data, FLT_DIG);
829 }
830 
832 {
833  size_t length = str.size(), fixed = 0;
836  for ( size_t i = 0; i < length; ++i ) {
837  if ( !GoodVisibleChar(str[i]) ) {
838  ++fixed;
839  }
840  }
841  }
842  WriteLength(length - fixed);
844  size_t done = 0;
845  for ( size_t i = 0; i < length; ++i ) {
846  char c = str[i];
847  if ( !GoodVisibleChar(c) ) {
848 #if SERIAL_ALLOW_UTF8_IN_VISIBLESTRING_ON_WRITING
849  size_t valid = CUtf8::EvaluateSymbolLength(CTempString(str.data()+i,length-done-i));
850  if (valid != 0) {
851  i += valid-1;
852  continue;
853  }
854 #endif
855  if ( i > done ) {
856  WriteBytes(str.data() + done, i - done);
857  }
859  if (c != 0) {
860  WriteByte(c);
861  }
862  done = i + 1;
863  }
864  }
865  if ( done < length ) {
866  WriteBytes(str.data() + done, length - done);
867  }
868  }
869  else {
870  WriteBytes(str.data(), length);
871  }
872 }
873 
875 {
877  size_t length = str.size();
878  WriteLength(length);
879  WriteBytes(str.data(), length);
880 }
881 
883  bool /*checkVisible*/)
884 {
885  size_t length = in.ReadLength();
886  WriteLength(length);
887  while ( length > 0 ) {
888  char buffer[1024];
889  size_t c = min(length, sizeof(buffer));
890  in.ReadBytes(buffer, c);
891 #if 0
892  if ( checkVisible ) {
893  // Check the string for non-printable characters
894  for (size_t i = 0; i < c; i++) {
895  if ( !GoodVisibleChar(buffer[i]) ) {
896  FixVisibleChar(buffer[i], x_FixCharsMethod(), this, string(buffer,c));
897  }
898  }
899  }
900 #endif
901  WriteBytes(buffer, c);
902  length -= c;
903  }
904  in.EndOfTag();
905 }
906 
909 {
910  // do we need to check symbols while copying?
911  // x_FixCharsMethod() != eFNP_Allow, type == eStringTypeVisible
912  const bool checkVisible = false;
914  if ( in.GetDataFormat() == eSerial_AsnBinary ) {
917  bIn.ExpectStringTag(type);
918  CopyStringValue(bIn, checkVisible);
919  }
920  else {
921  string str;
922  in.ReadString(str, type);
923  size_t length = str.size();
924 #if 0
925  if ( checkVisible ) {
926  // Check the string for non-printable characters
927  NON_CONST_ITERATE(string, i, str) {
928  if ( !GoodVisibleChar(*i) ) {
929  FixVisibleChar(*i, x_FixCharsMethod(), this, str);
930  }
931  }
932  }
933 #endif
934  WriteLength(length);
935  WriteBytes(str.data(), length);
936  }
937 }
938 
940 {
942  if ( in.GetDataFormat() == eSerial_AsnBinary ) {
946  CopyStringValue(bIn);
947  }
948  else {
949  string str;
950  in.ReadStringStore(str);
951  size_t length = str.size();
952  WriteLength(length);
953  WriteBytes(str.data(), length);
954  }
955 }
956 
958 {
959  if ( str == 0 ) {
961  WriteShortLength(0);
962  }
963  else {
964  size_t length = strlen(str), fixed = 0;
965  CTempString original(str, length);
967  WriteLength(length);
968  if ( x_FixCharsMethod() != eFNP_Allow ) {
969  size_t done = 0;
970  for ( size_t i = 0; i < length; ++i ) {
971  char c = str[i];
972  if ( !GoodVisibleChar(c) ) {
973 #if SERIAL_ALLOW_UTF8_IN_VISIBLESTRING_ON_WRITING
974  size_t valid = CUtf8::EvaluateSymbolLength(CTempString(str+i,length-done-i));
975  if (valid != 0) {
976  i += valid-1;
977  continue;
978  }
979 #endif
980  if ( i > done ) {
981  WriteBytes(str + done, i - done);
982  }
983  c = ReplaceVisibleChar(c, x_FixCharsMethod(), this, original, x_FixCharsSubst());
984  WriteByte(c);
985  if (c != 0) {
986  WriteByte(c);
987  } else {
988  ++fixed;
989  }
990  done = i + 1;
991  }
992  }
993  if ( done < length ) {
994  WriteBytes(str + done, length - done);
995  }
996  while (fixed--) {
997  WriteByte(0);
998  }
999  }
1000  else {
1001  WriteBytes(str, length);
1002  }
1003  }
1004 }
1005 
1008 {
1009  if ( values.IsInteger() ) {
1011  }
1012  else {
1013  values.FindName(value, false); // check value
1015  }
1017 }
1018 
1020  CObjectIStream& in)
1021 {
1022  TEnumValueType value = in.ReadEnum(values);
1023  if ( values.IsInteger() )
1025  else
1028 }
1029 
1031 {
1033  if ( sizeof(TObjectIndex) == sizeof(Int4) )
1034  WriteNumberValue(Int4(index));
1035  else if ( sizeof(TObjectIndex) == sizeof(Int8) )
1036  WriteNumberValue(Int8(index));
1037  else
1038  ThrowError(fIllegalCall, "invalid size of TObjectIndex"
1039  "must be either sizeof(Int4) or sizeof(Int8)");
1040 }
1041 
1043 {
1044  WriteSysTag(eNull);
1045  WriteShortLength(0);
1046 }
1047 
1049 {
1050  WriteClassTag(typeInfo);
1052 }
1053 
1055 {
1057 }
1058 
1060  TTypeInfo typeInfo)
1061 {
1062  WriteClassTag(typeInfo);
1064  WriteObject(object, typeInfo);
1066 }
1067 
1068 
1069 #ifdef VIRTUAL_MID_LEVEL_IO
1070 
1072 {
1073 #if !USE_OLD_TAGS
1074  bool need_eoc = false;
1075 #if USE_VERIFY_TAGGING
1077 #endif
1078  if (namedTypeInfo->HasTag()) {
1079 #if USE_VERIFY_TAGGING
1080  if (m_AutomaticTagging) {
1081  ThrowError(fInvalidData, "ASN TAGGING ERROR. Report immediately!");
1082  }
1083 #endif
1084  if (!m_SkipNextTag) {
1085  need_eoc = namedTypeInfo->IsTagConstructed();
1086  WriteTag(namedTypeInfo->GetTagClass(),
1087  namedTypeInfo->GetTagConstructed(),
1088  namedTypeInfo->GetTag());
1089  if (need_eoc) {
1091  }
1092  }
1093  m_SkipNextTag = namedTypeInfo->IsTagImplicit();
1094  }
1095  TopFrame().SetNoEOC(!need_eoc);
1096 #endif
1097 }
1098 
1100 {
1101 #if !USE_OLD_TAGS
1102  m_SkipNextTag = false;
1103  if (!TopFrame().GetNoEOC()) {
1105  }
1106 #endif
1107 }
1108 
1110  TTypeInfo namedTypeInfo,TTypeInfo objectType, TConstObjectPtr objectPtr)
1111 {
1112 
1113 #if USE_OLD_TAGS
1114 #ifndef VIRTUAL_MID_LEVEL_IO
1115  BEGIN_OBJECT_FRAME2(eFrameNamed, namedTypeInfo);
1116  BeginNamedType(namedTypeInfo);
1117 #endif
1118  WriteObject(objectPtr, objectType);
1119 #ifndef VIRTUAL_MID_LEVEL_IO
1120  EndNamedType();
1121  END_OBJECT_FRAME();
1122 #endif
1123 #else //USE_OLD_TAGS
1124 
1125  bool need_eoc = false;
1126 #if USE_VERIFY_TAGGING
1128 #endif
1129  if (namedTypeInfo->HasTag()) {
1130 #if USE_VERIFY_TAGGING
1131  if (m_AutomaticTagging) {
1132  ThrowError(fInvalidData, "ASN TAGGING ERROR. Report immediately!");
1133  }
1134 #endif
1135  if (!m_SkipNextTag) {
1136  need_eoc = namedTypeInfo->IsTagConstructed();
1137  WriteTag(namedTypeInfo->GetTagClass(),
1138  namedTypeInfo->GetTagConstructed(),
1139  namedTypeInfo->GetTag());
1140  if (need_eoc) {
1142  }
1143  }
1144  m_SkipNextTag = namedTypeInfo->IsTagImplicit();
1145  }
1146  WriteObject(objectPtr, objectType);
1147  if (need_eoc) {
1149  }
1150 #endif // USE_OLD_TAGS
1151 }
1152 
1154  TTypeInfo namedTypeInfo,TTypeInfo objectType,CObjectStreamCopier& copier)
1155 {
1156  BEGIN_OBJECT_2FRAMES_OF2(copier, eFrameNamed, namedTypeInfo);
1157  copier.In().BeginNamedType(namedTypeInfo);
1158  BeginNamedType(namedTypeInfo);
1159 
1160  CopyObject(objectType, copier);
1161 
1162  EndNamedType();
1163  copier.In().EndNamedType();
1164  END_OBJECT_2FRAMES_OF(copier);
1165 }
1166 
1167 
1169 {
1170 #if USE_OLD_TAGS
1173 #else
1174  _ASSERT(cType->HasTag());
1175  _ASSERT(cType->IsTagConstructed());
1176 #if 0 //USE_VERIFY_TAGGING
1178 #endif
1179  bool need_eoc = !m_SkipNextTag;
1180  if (!m_SkipNextTag) {
1181  WriteTag(cType->GetTagClass(), eConstructed, cType->GetTag());
1183  }
1184 #if USE_VERIFY_TAGGING
1185  else if (m_AutomaticTagging) {
1186  ThrowError(fInvalidData, "ASN TAGGING ERROR. Report immediately!");
1187  }
1188 #endif
1189  m_SkipNextTag = cType->IsTagImplicit();
1190  TopFrame().SetNoEOC(!need_eoc);
1191 #endif
1192 }
1193 
1195 {
1196 #if USE_OLD_TAGS
1198 #else
1199  m_SkipNextTag = false;
1200  if (!TopFrame().GetNoEOC()) {
1202  }
1203 #endif
1204 }
1205 
1207  TConstObjectPtr containerPtr)
1208 {
1209 #if USE_OLD_TAGS
1212 #else
1213  BEGIN_OBJECT_FRAME2(eFrameArray, cType);
1214  _ASSERT(cType->HasTag());
1215  _ASSERT(cType->IsTagConstructed());
1216 #if 0 //USE_VERIFY_TAGGING
1218 #endif
1219  bool need_eoc = !m_SkipNextTag;
1220  if (!m_SkipNextTag) {
1221  WriteTag(cType->GetTagClass(), eConstructed, cType->GetTag());
1223  }
1224 #if USE_VERIFY_TAGGING
1225  else if (m_AutomaticTagging) {
1226  ThrowError(fInvalidData, "ASN TAGGING ERROR. Report immediately!");
1227  }
1228 #endif
1229  m_SkipNextTag = cType->IsTagImplicit();
1230 #endif
1231 
1233  if ( cType->InitIterator(i, containerPtr) ) {
1234  TTypeInfo elementType = cType->GetElementType();
1235  BEGIN_OBJECT_FRAME2(eFrameArrayElement, elementType);
1236 
1237  const CPointerTypeInfo* pointerType =
1238  dynamic_cast<const CPointerTypeInfo*>(elementType);
1239  do {
1240  TConstObjectPtr elementPtr = cType->GetElementPtr(i);
1241  if ( pointerType &&
1242  !pointerType->GetObjectPointer(elementPtr) ) {
1243  if ( GetVerifyData() == eSerialVerifyData_Yes ) {
1245  "NULL element while writing container "+
1246  cType->GetName());
1247  }
1248  continue;
1249  }
1250 
1251  WriteObject(elementPtr, elementType);
1252 
1253  } while ( cType->NextElement(i) );
1254 
1255  END_OBJECT_FRAME();
1256  }
1257 
1258 #if USE_OLD_TAGS
1260 #else
1261  if (need_eoc) {
1263  }
1264  END_OBJECT_FRAME();
1265 #endif
1266 }
1267 
1269  CObjectStreamCopier& copier)
1270 {
1271 #if USE_OLD_TAGS
1272  BEGIN_OBJECT_FRAME_OF2(copier.In(), eFrameArray, cType);
1273  copier.In().BeginContainer(cType);
1276 #else
1277  BEGIN_OBJECT_2FRAMES_OF2(copier, eFrameArray, cType);
1278  copier.In().BeginContainer(cType);
1280 #endif
1281 
1282  TTypeInfo elementType = cType->GetElementType();
1283  BEGIN_OBJECT_2FRAMES_OF2(copier, eFrameArrayElement, elementType);
1284 
1285  while ( copier.In().BeginContainerElement(elementType) ) {
1286 
1287  CopyObject(elementType, copier);
1288 
1289  copier.In().EndContainerElement();
1290  }
1291 
1292  END_OBJECT_2FRAMES_OF(copier);
1293 
1294 #if USE_OLD_TAGS
1296  copier.In().EndContainer();
1297  END_OBJECT_FRAME_OF(copier.In());
1298 #else
1300  copier.In().EndContainer();
1301  END_OBJECT_2FRAMES_OF(copier);
1302 #endif
1303 
1304 }
1305 
1306 #endif
1307 
1309 {
1310 #if USE_OLD_TAGS
1313 #else
1314  _ASSERT(classType->HasTag());
1315  _ASSERT(classType->IsTagConstructed());
1316 #if USE_VERIFY_TAGGING
1318 #endif
1319  bool need_eoc = !m_SkipNextTag;
1320  if (!m_SkipNextTag) {
1321  WriteTag(classType->GetTagClass(), eConstructed, classType->GetTag());
1323  }
1324 #if USE_VERIFY_TAGGING
1325  else if (m_AutomaticTagging) {
1326  ThrowError(fInvalidData, "ASN TAGGING ERROR. Report immediately!");
1327  }
1328 #endif
1329  m_SkipNextTag = classType->IsTagImplicit();
1330  TopFrame().SetNoEOC(!need_eoc);
1331 #endif
1332 }
1333 
1335 {
1336 #if USE_OLD_TAGS
1338 #else
1339  m_SkipNextTag = false;
1340  if (!TopFrame().GetNoEOC()) {
1342  }
1343 #endif
1344 }
1345 
1347 {
1348 #if USE_OLD_TAGS
1349  WriteTag(eContextSpecific, eConstructed, id.GetTag());
1351 #else
1352  if (id.HasTag()) {
1353  WriteTag(id.GetTagClass(), id.GetTagConstructed(), id.GetTag());
1354  if (id.IsTagConstructed()) {
1356  }
1357  }
1358 #if USE_VERIFY_TAGGING
1359  else if (m_AutomaticTagging) {
1360  ThrowError(fInvalidData, "ASN TAGGING ERROR. Report immediately!");
1361  }
1362 #endif
1363  m_SkipNextTag = id.HasTag() && id.IsTagImplicit();
1364 #endif
1365 }
1366 
1368 {
1369 #if USE_OLD_TAGS
1371 #else
1372  m_SkipNextTag = false;
1373  const CMemberId& id = TopFrame().GetMemberId();
1374  if (id.HasTag() && id.IsTagConstructed()) {
1376  }
1377 #endif
1378 }
1379 
1380 #ifdef VIRTUAL_MID_LEVEL_IO
1382  TConstObjectPtr classPtr)
1383 {
1384 #if USE_OLD_TAGS
1387 #else
1388  BEGIN_OBJECT_FRAME2(eFrameClass, classType);
1389  _ASSERT(classType->HasTag());
1390  _ASSERT(classType->IsTagConstructed());
1391 #if USE_VERIFY_TAGGING
1393 #endif
1394  bool need_eoc = !m_SkipNextTag;
1395  if (!m_SkipNextTag) {
1396  WriteTag(classType->GetTagClass(), eConstructed, classType->GetTag());
1398  }
1399 #if USE_VERIFY_TAGGING
1400  else if (m_AutomaticTagging) {
1401  ThrowError(fInvalidData, "ASN TAGGING ERROR. Report immediately!");
1402  }
1403 #endif
1404  m_SkipNextTag = classType->IsTagImplicit();
1405 #endif
1406 
1407  for ( CClassTypeInfo::CIterator i(classType); i.Valid(); ++i ) {
1408  classType->GetMemberInfo(i)->WriteMember(*this, classPtr);
1409  }
1410 
1411 #if USE_OLD_TAGS
1413 #else
1414  if (need_eoc) {
1416  }
1417  END_OBJECT_FRAME();
1418 #endif
1419 }
1420 
1422  TTypeInfo memberType,
1423  TConstObjectPtr memberPtr)
1424 {
1425  BEGIN_OBJECT_FRAME2(eFrameClassMember, memberId);
1426 #if USE_OLD_TAGS
1429 #else
1430  bool need_eoc = false;
1431  if (memberId.HasTag()) {
1432  WriteTag(memberId.GetTagClass(), memberId.GetTagConstructed(), memberId.GetTag());
1433  need_eoc = memberId.IsTagConstructed();
1434  if (need_eoc) {
1436  }
1437  }
1438 #if USE_VERIFY_TAGGING
1439  else if (m_AutomaticTagging) {
1440  ThrowError(fInvalidData, "ASN TAGGING ERROR. Report immediately!");
1441  }
1442 #endif
1443  m_SkipNextTag = memberId.HasTag() && memberId.IsTagImplicit();
1444 #endif
1445 
1446  WriteObject(memberPtr, memberType);
1447 
1448 #if USE_OLD_TAGS
1450 #else
1451  if (need_eoc) {
1453  }
1454 #endif
1455  END_OBJECT_FRAME();
1456 }
1457 
1459  const CDelayBuffer& buffer)
1460 {
1461  if ( !buffer.HaveFormat(eSerial_AsnBinary) )
1462  return false;
1463 
1464  BEGIN_OBJECT_FRAME2(eFrameClassMember, memberId);
1465 #if USE_OLD_TAGS
1468 #else
1469  bool need_eoc = false;
1470  if (memberId.HasTag()) {
1471  WriteTag(memberId.GetTagClass(), memberId.GetTagConstructed(), memberId.GetTag());
1472  need_eoc = memberId.IsTagConstructed();
1473  if (need_eoc) {
1475  }
1476  }
1477 #if USE_VERIFY_TAGGING
1478  else if (m_AutomaticTagging) {
1479  ThrowError(fInvalidData, "ASN TAGGING ERROR. Report immediately!");
1480  }
1481 #endif
1482  m_SkipNextTag = memberId.HasTag() && memberId.IsTagImplicit();
1483 #endif
1484 
1485  Write(buffer.GetSource());
1486 
1487 #if USE_OLD_TAGS
1489 #else
1490  if (need_eoc) {
1492  }
1493 #endif
1494  END_OBJECT_FRAME();
1495 
1496  return true;
1497 }
1498 
1500  CObjectStreamCopier& copier)
1501 {
1502 #if USE_OLD_TAGS
1503  BEGIN_OBJECT_FRAME_OF2(copier.In(), eFrameClass, classType);
1504  copier.In().BeginClass(classType);
1507 #else
1508  BEGIN_OBJECT_2FRAMES_OF2(copier, eFrameClass, classType);
1509  copier.In().BeginClass(classType);
1511 #endif
1512 
1513  vector<Uint1> read(classType->GetMembers().LastIndex() + 1);
1514 
1515  BEGIN_OBJECT_2FRAMES_OF(copier, eFrameClassMember);
1516 
1517  TMemberIndex index;
1518  while ( (index = copier.In().BeginClassMember(classType)) !=
1519  kInvalidMember ) {
1520  const CMemberInfo* memberInfo = classType->GetMemberInfo(index);
1521  copier.In().SetTopMemberId(memberInfo->GetId());
1522  SetTopMemberId(memberInfo->GetId());
1523  copier.SetPathHooks(*this, true);
1524 
1525  if ( read[index] ) {
1526  copier.DuplicatedMember(memberInfo);
1527  }
1528  else {
1529  read[index] = true;
1530 
1531 #if USE_OLD_TAGS
1533  eConstructed,
1534  memberInfo->GetId().GetTag());
1536 #else
1538 #endif
1539 
1540  memberInfo->CopyMember(copier);
1541 
1542 #if USE_OLD_TAGS
1544 #else
1546 #endif
1547  }
1548 
1549  copier.SetPathHooks(*this, false);
1550  copier.In().EndClassMember();
1551  }
1552 
1553  END_OBJECT_2FRAMES_OF(copier);
1554 
1555  // init all absent members
1556  for ( CClassTypeInfo::CIterator i(classType); i.Valid(); ++i ) {
1557  if ( !read[*i] ) {
1558  classType->GetMemberInfo(i)->CopyMissingMember(copier);
1559  }
1560  }
1561 
1562 #if USE_OLD_TAGS
1564  copier.In().EndClass();
1565  END_OBJECT_FRAME_OF(copier.In());
1566 #else
1568  copier.In().EndClass();
1569  END_OBJECT_2FRAMES_OF(copier);
1570 #endif
1571 }
1572 
1574  CObjectStreamCopier& copier)
1575 {
1576 #if USE_OLD_TAGS
1577  BEGIN_OBJECT_FRAME_OF2(copier.In(), eFrameClass, classType);
1578  copier.In().BeginClass(classType);
1581 #else
1582  BEGIN_OBJECT_2FRAMES_OF2(copier, eFrameClass, classType);
1583  copier.In().BeginClass(classType);
1585 #endif
1586 
1587  CClassTypeInfo::CIterator pos(classType);
1588  BEGIN_OBJECT_2FRAMES_OF(copier, eFrameClassMember);
1589 
1590  TMemberIndex index;
1591  while ( (index = copier.In().BeginClassMember(classType, *pos)) !=
1592  kInvalidMember ) {
1593  const CMemberInfo* memberInfo = classType->GetMemberInfo(index);
1594  copier.In().SetTopMemberId(memberInfo->GetId());
1595  SetTopMemberId(memberInfo->GetId());
1596 
1597  for ( TMemberIndex i = *pos; i < index; ++i ) {
1598  // init missing member
1599  classType->GetMemberInfo(i)->CopyMissingMember(copier);
1600  }
1601  copier.SetPathHooks(*this, true);
1602 
1603 #if USE_OLD_TAGS
1604  WriteTag(eContextSpecific, eConstructed, memberInfo->GetId().GetTag());
1606 #else
1608 #endif
1609 
1610  memberInfo->CopyMember(copier);
1611 
1612 #if USE_OLD_TAGS
1614 #else
1616 #endif
1617 
1618  pos.SetIndex(index + 1);
1619 
1620  copier.SetPathHooks(*this, false);
1621  copier.In().EndClassMember();
1622  }
1623 
1624  END_OBJECT_2FRAMES_OF(copier);
1625 
1626  // init all absent members
1627  for ( ; pos.Valid(); ++pos ) {
1628  classType->GetMemberInfo(pos)->CopyMissingMember(copier);
1629  }
1630 
1631 #if USE_OLD_TAGS
1633  copier.In().EndClass();
1634  END_OBJECT_FRAME_OF(copier.In());
1635 #else
1637  copier.In().EndClass();
1638  END_OBJECT_2FRAMES_OF(copier);
1639 #endif
1640 }
1641 #endif
1642 
1644 {
1645  if (choiceType->GetVariantInfo(kFirstMemberIndex)->GetId().IsAttlist()) {
1646  TopFrame().SetNotag();
1649  }
1650 }
1651 
1653 {
1654  if (TopFrame().GetNotag()) {
1656  }
1657 }
1658 
1660  const CMemberId& id)
1661 {
1662  if (FetchFrameFromTop(1).GetNotag()) {
1665  WriteTag(eContextSpecific, eConstructed, id.GetTag()-1);
1667  } else {
1668 #if USE_OLD_TAGS
1669  WriteTag(eContextSpecific, eConstructed, id.GetTag());
1671 #else
1672  if (id.HasTag()) {
1673  WriteTag(id.GetTagClass(), id.GetTagConstructed(), id.GetTag());
1674  if (id.IsTagConstructed()) {
1676  }
1677  }
1678 #if USE_VERIFY_TAGGING
1679  else if (m_AutomaticTagging) {
1680  ThrowError(fInvalidData, "ASN TAGGING ERROR. Report immediately!");
1681  }
1682 #endif
1683  m_SkipNextTag = id.HasTag() && id.IsTagImplicit();
1684 #endif
1685  }
1686 }
1687 
1689 {
1690  m_SkipNextTag = false;
1691  if (FetchFrameFromTop(1).GetNotag()) {
1693  }
1694 #if USE_OLD_TAGS
1696 #else
1697  const CMemberId& id = TopFrame().GetMemberId();
1698  if (id.HasTag() && id.IsTagConstructed()) {
1700  }
1701 #endif
1702 }
1703 
1705 {
1707  WriteLength(block.GetLength());
1708 }
1709 
1711  const char* bytes, size_t length)
1712 {
1713  WriteBytes(bytes, length);
1714 }
1715 
1717 {
1718  if ( block.GetLength() == 0 ) {
1719  WriteSysTag(eNull);
1720  WriteShortLength(0);
1721  return;
1722  }
1724  WriteLength(block.GetLength());
1725 }
1726 
1727 
1729  const char* str, size_t length)
1730 {
1731  if ( x_FixCharsMethod() != eFNP_Allow ) {
1732  CTempString original(str, length);
1733  size_t done = 0, fixed = 0;
1734  for ( size_t i = 0; i < length; ++i ) {
1735  char c = str[i];
1736  if ( !GoodVisibleChar(c) ) {
1737 #if SERIAL_ALLOW_UTF8_IN_VISIBLESTRING_ON_WRITING
1738  size_t valid = CUtf8::EvaluateSymbolLength(CTempString(str+i,length-done-i));
1739  if (valid != 0) {
1740  i += valid-1;
1741  continue;
1742  }
1743 #endif
1744  if ( i > done ) {
1745  WriteBytes(str + done, i - done);
1746  }
1747  c = ReplaceVisibleChar(c, x_FixCharsMethod(), this, original, x_FixCharsSubst());
1748  if (c != 0) {
1749  WriteByte(c);
1750  } else {
1751  ++fixed;
1752  }
1753  done = i + 1;
1754  }
1755  }
1756  if ( done < length ) {
1757  WriteBytes(str + done, length - done);
1758  }
1759  while (fixed--) {
1760  WriteByte(0);
1761  }
1762  }
1763  else {
1764  WriteBytes(str, length);
1765  }
1766 }
1767 
1768 
ncbi::TMaskedQueryRegions mask
Serializable object that stores any combination of parsable data.
Definition: serialbase.hpp:264
CDelayBuffer.
Definition: delaybuf.hpp:58
CObjectIStreamAsnBinary –.
Definition: objistrasnb.hpp:59
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStreamAsnBinary –.
Definition: objostrasnb.hpp:58
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CSafeStatic<>::
T & Get(void)
Create the variable if not created yet, return the reference.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Definition: svg.hpp:69
Definition: svg.hpp:50
size_type size() const noexcept
Returns bvector's capacity (number of bits it can store)
Definition: bm.h:1300
friend class enumerator
Definition: bm.h:793
bvector_size_type size_type
Definition: bm.h:121
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
Definition: bm.h:1871
enumerator end() const
Returns enumerator pointing on the next bit after the last.
Definition: bm.h:1877
void calc_stat(struct bm::bvector< Alloc >::statistics *st) const noexcept
Calculates bitvector statistics.
Definition: bm.h:3978
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define T(s)
Definition: common.h:230
std::ofstream out("events_result.xml")
main entry point for tests
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:51
static char precision
Definition: genparams.c:28
static const char * str(char *buf, int n)
Definition: stats.c:84
char data[12]
Definition: iconv.c:80
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
@ eNoOwnership
No ownership is assumed.
Definition: ncbi_types.h:135
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#define isnan
Definition: ncbifloat.h:89
#define finite
Define value of finite (Is Finite).
Definition: ncbifloat.h:109
const string & FindName(TEnumValueType value, bool allowBadValue) const
Find name of the enum by its numeric value.
Definition: enumerated.cpp:146
CAsnBinaryDefs::ETagClass GetTagClass(void) const
const CMemberId & GetId(void) const
bool IsAttlist(void) const
void WriteMember(CObjectOStream &out, TConstObjectPtr classPtr) const
void CopyMissingMember(CObjectStreamCopier &copier) const
bool IsTagImplicit(void) const
void CopyMember(CObjectStreamCopier &copier) const
bool IsTagConstructed(void) const
TTag GetTag(void) const
bool HasTag(void) const
TMemberIndex LastIndex(void) const
Definition: memberlist.hpp:82
bool IsInteger(void) const
Check whether the type is defined as INTEGER in ASN.1 spec.
Definition: enumvalues.hpp:75
CAsnBinaryDefs::ETagConstructed GetTagConstructed(void) const
EFixNonPrint
How to process non-printing character in the ASN VisibleString.
Definition: serialdef.hpp:173
int TEnumValueType
Definition: serialdef.hpp:232
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
const TMemberIndex kFirstMemberIndex
Start if member indexing.
Definition: serialdef.hpp:235
const TMemberIndex kInvalidMember
Special value returned from FindMember.
Definition: serialdef.hpp:237
const void * TConstObjectPtr
Definition: serialdef.hpp:59
EStringType
String type.
Definition: serialdef.hpp:185
static const TObjectType * SafeCast(TTypeInfo type)
Definition: serialutil.hpp:76
@ eFNP_Allow
pass through unchanged, post no error message
Definition: serialdef.hpp:175
@ eFNP_Skip
skip, post no error message
Definition: serialdef.hpp:174
@ eSerialVerifyData_Yes
do verify
Definition: serialdef.hpp:111
@ eStringTypeUTF8
UTF8-encoded string.
Definition: serialdef.hpp:187
@ eStringTypeVisible
VisibleString (in ASN.1 sense)
Definition: serialdef.hpp:186
@ eSerial_AsnBinary
ASN.1 binary.
Definition: serialdef.hpp:74
virtual void WriteBitString(const CBitString &obj) override
static ETagValue GetTagValue(TByte byte)
static ETagConstructed GetTagConstructed(TByte byte)
void WriteLongLength(size_t length)
char ReplaceVisibleChar(char c, EFixNonPrint fix_method, const CObjectStack *io, const CTempString &str, char subst)
Definition: objistr.cpp:1855
virtual void WriteString(const string &s, EStringType type=eStringTypeVisible) override
virtual void WriteInt4(Int4 data) override
bool m_FastWriteDouble
Definition: objostr.hpp:806
virtual void WriteNullPointer(void) override
virtual void EndClassMember(void)
Definition: objistr.cpp:1372
void WriteClassMember(const CConstObjectInfoMI &member)
Definition: objostr.cpp:571
EFixNonPrint x_FixCharsMethod(void) const
Definition: objostr.cpp:287
virtual void WriteObjectReference(TObjectIndex index) override
virtual void WriteDouble(double data) override
virtual void WriteOther(TConstObjectPtr object, TTypeInfo typeInfo) override
virtual void WriteBool(bool data) override
static ETagClass GetTagClass(TByte byte)
#define END_OBJECT_2FRAMES_OF(Stream)
Definition: objstack.hpp:234
void WriteByte(Uint1 byte)
virtual void EndContainerElement(void)
Definition: objistr.cpp:1314
void WriteIndefiniteLength(void)
bool GoodVisibleChar(char c)
void WriteShortTag(ETagClass tag_class, ETagConstructed tag_constructed, ETagValue tag_value)
virtual void CopyStringStore(CObjectIStream &in) override
void CopyStringValue(CObjectIStreamAsnBinary &in, bool checkVisible=false)
void CopyObject(TTypeInfo objectType, CObjectStreamCopier &copier)
void WriteNumberValue(Int4 data)
virtual void BeginBytes(const ByteBlock &block) override
#define ThrowError(flag, mess)
Definition: objstack.hpp:113
static bool IsTagConstructed(TByte byte)
virtual void EndContainer(void)=0
virtual void WriteUint4(Uint4 data) override
void WriteLongTag(ETagClass tag_class, ETagConstructed tag_constructed, TLongTag tag_value)
void DuplicatedMember(const CMemberInfo *memberInfo)
virtual void WriteNull(void) override
virtual TMemberIndex BeginClassMember(const CClassTypeInfo *classType)=0
bool IsCompressed(void) const
Definition: objstack.cpp:193
virtual void BeginChoiceVariant(const CChoiceTypeInfo *choiceType, const CMemberId &id) override
#define BEGIN_OBJECT_FRAME2(Type, Arg)
Definition: objstack.hpp:225
size_t GetLength(void) const
static CObjectOStream * OpenObjectOStreamAsnBinary(CNcbiOstream &out, EOwnership deleteOut)
Definition: objostrasnb.cpp:66
void WriteClassTag(TTypeInfo typeInfo)
virtual void WriteOtherBegin(TTypeInfo typeInfo) override
virtual void WriteStringStore(const string &s) override
void ExpectSysTag(ETagClass tag_class, ETagConstructed tag_constructed, ETagValue tag_value)
MLIOVIR void WriteContainer(const CContainerTypeInfo *containerType, TConstObjectPtr containerPtr)
Definition: objostr.cpp:810
virtual void BeginNamedType(TTypeInfo namedTypeInfo)
Definition: objistr.cpp:1276
virtual void CopyString(CObjectIStream &in, EStringType type=eStringTypeVisible) override
static TByte MakeUTF8StringTag(void)
void SetNotag(bool set=true)
void SetPathHooks(CObjectStack &stk, bool set)
Definition: objcopy.cpp:249
virtual void EndClass(void) override
void WriteDouble2(double data, unsigned digits)
virtual void WriteUint8(Uint8 data) override
TFrame & FetchFrameFromTop(size_t index)
virtual void EndNamedType(void)
Definition: objistr.cpp:1280
void WriteObject(const CConstObjectInfo &object)
Definition: objostr.cpp:566
virtual void BeginClass(const CClassTypeInfo *classInfo) override
virtual void EndChoiceVariant(void) override
#define BEGIN_OBJECT_2FRAMES_OF(Stream, Type)
Definition: objstack.hpp:247
CObjectOStreamAsnBinary(CNcbiOstream &out, EFixNonPrint how=eFNP_Default)
Constructor.
Definition: objostrasnb.cpp:72
void Write(const CConstObjectInfo &object)
Definition: objostr.cpp:593
virtual void BeginContainer(const CContainerTypeInfo *containerType)=0
virtual void WriteCString(const char *str) override
virtual void WriteOtherEnd(TTypeInfo typeInfo) override
virtual void WriteChar(char data) override
virtual void CopyAnyContentObject(CObjectIStream &in) override
#define END_OBJECT_FRAME()
Definition: objstack.hpp:227
#define BEGIN_OBJECT_FRAME_OF2(Stream, Type, Arg)
Definition: objstack.hpp:219
CObjectIStream & In(void) const
size_t TObjectIndex
Definition: objostr.hpp:775
virtual void BeginClassMember(const CMemberId &id) override
void SetNoEOC(bool set=true)
virtual void CopyBitString(CObjectIStream &in) override
void WriteBytes(const char *bytes, size_t size)
ESpecialCaseWrite m_SpecialCaseWrite
Definition: objostr.hpp:803
const TFrame & TopFrame(void) const
size_t GetLength(void) const
virtual void WriteInt8(Int8 data) override
char x_FixCharsSubst(void) const
Definition: objostr.hpp:790
MLIOVIR void CopyNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, CObjectStreamCopier &copier)
Definition: objostr.cpp:761
MLIOVIR void WriteClass(const CClassTypeInfo *objectType, TConstObjectPtr objectPtr)
Definition: objostr.cpp:892
static TByte MakeContainerTagByte(bool random_order)
virtual void CopyEnum(const CEnumeratedTypeValues &values, CObjectIStream &in) override
virtual void BeginContainer(const CContainerTypeInfo *containerType) override
virtual void WriteFloat(float data) override
virtual void EndContainer(void) override
virtual ~CObjectOStreamAsnBinary(void)
Destructor.
COStreamBuffer m_Output
Definition: objostr.hpp:796
virtual void WriteChars(const CharBlock &block, const char *chars, size_t length) override
void SetTopMemberId(const CMemberId &memberId)
MLIOVIR void CopyClassRandom(const CClassTypeInfo *objectType, CObjectStreamCopier &copier)
Definition: objostr.cpp:935
const CMemberId & GetMemberId(void) const
void WriteSysTag(ETagValue tag)
#define BEGIN_OBJECT_2FRAMES_OF2(Stream, Type, Arg)
Definition: objstack.hpp:249
void WriteBytesOf(const T &value, size_t count)
virtual bool BeginContainerElement(TTypeInfo elementType)=0
virtual void WriteAnyContentObject(const CAnyContentObject &obj) override
void ExpectStringTag(EStringType type)
virtual void BeginChars(const CharBlock &block) override
virtual void BeginChoice(const CChoiceTypeInfo *choiceType) override
virtual void EndNamedType(void) override
void WriteTag(ETagClass tag_class, ETagConstructed tag_constructed, TLongTag tag_value)
virtual void EndChoice(void) override
EFixNonPrint FixNonPrint(EFixNonPrint how)
Definition: objostr.hpp:203
virtual void BeginNamedType(TTypeInfo namedTypeInfo) override
MLIOVIR void WriteNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, TConstObjectPtr object)
Definition: objostr.cpp:742
MLIOVIR void CopyContainer(const CContainerTypeInfo *containerType, CObjectStreamCopier &copier)
Definition: objostr.cpp:858
static TByte MakeTagByte(ETagClass tag_class, ETagConstructed tag_constructed, ETagValue tag_value)
void WriteShortLength(size_t length)
virtual void EndClass(void)
Definition: objistr.cpp:1368
virtual void BeginClass(const CClassTypeInfo *classInfo)=0
virtual void EndClassMember(void) override
TTypeInfo GetRecentTypeInfo(void) const
#define END_OBJECT_FRAME_OF(Stream)
Definition: objstack.hpp:201
virtual void WriteEnum(const CEnumeratedTypeValues &values, TEnumValueType value) override
static TByte GetUTF8StringTag(void)
ESerialVerifyData GetVerifyData(void) const
Get output data verification parameter.
void WriteStringTag(EStringType type)
void WriteLength(size_t length)
MLIOVIR void CopyClassSequential(const CClassTypeInfo *objectType, CObjectStreamCopier &copier)
Definition: objostr.cpp:984
@ fIllegalCall
Illegal in a given context function call.
Definition: objostr.hpp:324
@ fInvalidData
Output data is incorrect.
Definition: objostr.hpp:322
@ fNotImplemented
Method is not implemented.
Definition: objostr.hpp:330
@ fUnassigned
Mandatory object member is unassigned Normally this results in throwing CUnassignedMember exception.
Definition: objostr.hpp:333
@ fOverflow
Internal buffer overflow.
Definition: objostr.hpp:320
#define NCBI_PARAM_TYPE(section, name)
Generate typename for a parameter from its {section, name} attributes.
Definition: ncbi_param.hpp:149
@ eParam_NoThread
Do not use per-thread values.
Definition: ncbi_param.hpp:418
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void PutChar(char c)
void PutString(const char *str, size_t length)
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
static SIZE_TYPE DoubleToStringPosix(double value, unsigned int precision, char *buf, SIZE_TYPE buf_size)
Convert double to string with specified precision and put the result into a character buffer,...
Definition: ncbistr.cpp:2662
static SIZE_TYPE EvaluateSymbolLength(const CTempString &src)
Check buffer for presence of UTF-8 byte sequence and return length of first symbol.
Definition: ncbistr.cpp:7111
const string & GetName(void) const
Get name of this type.
Definition: typeinfo.cpp:249
CAsnBinaryDefs::ETagClass GetTagClass(void) const
Definition: typeinfo.hpp:262
CAsnBinaryDefs::ETagConstructed GetTagConstructed(void) const
Definition: typeinfo.hpp:265
bool HasTag(void) const
Definition: typeinfo.hpp:259
bool RandomElementsOrder(void) const
CAsnBinaryDefs::ETagType GetTagType(void) const
Definition: typeinfo.hpp:247
bool RandomOrder(void) const
const CMemberInfo * GetMemberInfo(TMemberIndex index) const
const CVariantInfo * GetVariantInfo(TMemberIndex index) const
CAsnBinaryDefs::TLongTag GetTag(void) const
Definition: typeinfo.hpp:256
bool IsTagConstructed(void) const
Definition: typeinfo.hpp:268
TConstObjectPtr GetElementPtr(const CConstIterator &it) const
bool InitIterator(CConstIterator &it, TConstObjectPtr containerPtr) const
bool IsTagImplicit(void) const
Definition: typeinfo.hpp:250
bool NextElement(CConstIterator &it) const
TConstObjectPtr GetObjectPointer(TConstObjectPtr object) const
const CItemsInfo & GetMembers(void) const
TTypeInfo GetElementType(void) const
enum ENcbiOwnership EOwnership
Ownership relations between objects.
size_t serialize(const BV &bv, unsigned char *buf, bm::word_t *temp_block=0, unsigned serialization_flags=0)
Saves bitvector into memory.
Definition: bmserial.h:3071
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
Definition of all error codes used in serial libraries (xser.lib, xcser.lib).
char * buf
int i
int len
static void byte(MDB_val *v)
Definition: mdb_dump.c:81
unsigned int word_t
Definition: bmconst.h:39
void aligned_free(void *ptr) BMNOEXCEPT
Aligned free.
Definition: bmalloc.h:464
void * aligned_new_malloc(size_t size)
Aligned malloc (unlike classic malloc it throws bad_alloc exception)
Definition: bmalloc.h:436
const unsigned set_block_alloc_size
Definition: bmconst.h:61
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const char * tag
#define NCBI_CONST_INT8(v)
64-bit integers
Definition: ncbi_std.h:195
#define NCBI_CONST_UINT8(v)
Definition: ncbi_std.h:196
T min(T x_, T y_)
std::istream & in(std::istream &in_, double &x_)
NCBI_PARAM_DEF_EX(bool, SERIAL, WRITE_UTF8STRING_TAG, false, eParam_NoThread, SERIAL_WRITE_UTF8STRING_TAG)
static const size_t kMaxDoubleLength
static bool s_IsOldStyleInt8(const CObjectOStreamAsnBinary *os)
NCBI_PARAM_DECL(bool, SERIAL, WRITE_UTF8STRING_TAG)
static pcre_uint8 * buffer
Definition: pcretest.c:1051
Definition: inftrees.h:24
Definition: type.c:6
#define _ASSERT
done
Definition: token1.c:1
void free(voidpf ptr)
voidp malloc(uInt size)
Modified on Fri Apr 12 17:14:53 2024 by modify_doxy.py rev. 669887