8#ifndef INCLUDED_BALBER_BERDECODER
9#define INCLUDED_BALBER_BERDECODER
122#include <balscm_version.h>
152#include <bsl_istream.h>
153#include <bsl_ostream.h>
154#include <bsl_string.h>
155#include <bsl_vector.h>
160class BerDecoder_Node;
161class BerDecoder_NodeVisitor;
162class BerDecoder_UniversalElementVisitor;
182 class MemOutStream :
public bsl::ostream {
187 MemOutStream(
const MemOutStream&);
188 MemOutStream& operator=(
const MemOutStream&);
215 const char *
data()
const;
228#ifndef BDE_OMIT_INTERNAL_DEPRECATED
242 MemOutStream *d_logStream;
249 bsl::streambuf *d_streamBuf;
252 int d_numUnknownElementsSkipped;
273 void logErrorImp(
const char *msg);
280 bsl::ostream& logStream();
302 template <
typename TYPE>
303 int decode(bsl::streambuf *streamBuf, TYPE *variable);
309 template <
typename TYPE>
310 int decode(bsl::istream& stream, TYPE *variable);
365 int d_expectedLength;
366 int d_consumedHeaderBytes;
367 int d_consumedBodyBytes;
368 int d_consumedTailBytes;
369 int d_formattingMode;
370 const char *d_fieldName;
387 template <
typename TYPE>
389 template <
typename TYPE>
391 template <
typename TYPE>
393 template <
typename TYPE>
395 template <
typename TYPE>
397 template <
typename TYPE>
399 template <
typename TYPE>
401 template <
typename TYPE>
406 template <
typename TYPE>
407 int decodeArray(TYPE *variable);
411 template <
typename TYPE>
412 int decodeChoice(TYPE *variable);
418 template <
typename TYPE>
424 template <
typename TYPE>
427 template <
typename TYPE,
typename ANY_CATEGORY>
428 int operator()(TYPE *
object, ANY_CATEGORY category);
430 template <
typename TYPE>
437 int spacePerLevel = 0,
438 const char *prefixText = 0)
const;
538 template <
typename TYPE,
typename INFO>
539 int operator()(TYPE *variable,
const INFO& info);
572 template <
typename TYPE>
593 : d_options_p(options)
615balber::BerDecoder::MemOutStream::MemOutStream(
618, d_sb(
bslma::Default::allocator(basicAllocator))
640 return (
int)d_sb.length();
650BerDecoder::logError(
const char *msg)
660bsl::ostream& BerDecoder::logStream()
662 if (0 == d_logStream) {
663 d_logStream =
new(d_logArea.buffer()) MemOutStream(d_allocator);
668template <
typename TYPE>
670int BerDecoder::decode(bsl::istream& stream, TYPE *variable)
672 if (!stream.good()) {
676 if (0 != this->decode(stream.rdbuf(), variable)) {
677 stream.setstate(bsl::ios_base::failbit);
684template <
typename TYPE>
685int BerDecoder::decode(bsl::streambuf *streamBuf, TYPE *variable)
689 d_streamBuf = streamBuf;
691 d_severity = e_BER_SUCCESS;
692 d_numUnknownElementsSkipped = 0;
694 if (d_logStream != 0) {
695 d_logStream->reset();
709 rc = visitor(variable);
713 rc = visitor(variable);
721void BerDecoder::setNumUnknownElementsSkipped(
int value)
725 d_numUnknownElementsSkipped = value;
752bool BerDecoder::maxDepthExceeded()
const
754 return d_currentDepth > d_options->maxDepth();
758int BerDecoder::numUnknownElementsSkipped()
const
760 return d_numUnknownElementsSkipped;
771, d_parent (d_decoder->d_topNode)
775, d_expectedLength (0)
776, d_consumedHeaderBytes(0)
777, d_consumedBodyBytes (0)
778, d_consumedTailBytes (0)
782 ++d_decoder->d_currentDepth;
784 d_formattingMode = d_parent->d_formattingMode;
786 d_decoder->d_topNode =
this;
793 d_parent->d_consumedBodyBytes += d_consumedHeaderBytes
794 + d_consumedBodyBytes
795 + d_consumedTailBytes;
798 d_decoder->d_topNode = d_parent;
799 --d_decoder->d_currentDepth;
810 return 0 != d_decoder->d_streamBuf->sgetc();
813 return d_expectedLength > d_consumedBodyBytes;
844 return d_formattingMode;
856 return d_expectedLength;
872template <
typename TYPE>
876 BSLS_ASSERT(0 &&
"Should never execute this function");
881template <
typename TYPE,
typename ANY_CATEGORY>
885 return this->decode(
object, category);
888template <
typename TYPE>
893 return this->decode(
object, Tag());
897template <
typename TYPE>
907 return logError(
"Expected CONSTRUCTED tag type for choice");
917 BerDecoder_Node innerNode(d_decoder);
918 rc = innerNode.readTagHeader();
924 return innerNode.logError(
925 "Expected CONTEXT tag class for tagged choice");
929 return innerNode.logError(
930 "Expected CONSTRUCTED tag type for tagged choice");
933 if (innerNode.tagNumber() != 0) {
934 return innerNode.logError(
935 "Expected 0 as a tag number for tagged choice");
938 if (innerNode.hasMore()) {
940 rc = innerNode.decodeChoice(variable);
946 rc = innerNode.readTagTrailer();
951 rc = this->decodeChoice(variable);
957template <
typename TYPE>
967 return logError(
"Expected CONSTRUCTED tag type for nullable");
973 BerDecoder_Node innerNode(d_decoder);
974 rc = innerNode.readTagHeader();
980 return innerNode.logError(
981 "Expected CONTEXT tag class for inner nillable");
984 if (innerNode.tagNumber() != 0) {
985 return innerNode.logError(
986 "Expected 0 as tag number for inner nillable");
997 rc = innerNode.readTagTrailer();
1012template <
typename TYPE>
1019#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
1020#pragma GCC diagnostic push
1021#pragma GCC diagnostic ignored "-Wuninitialized"
1022#ifndef BSLS_PLATFORM_CMP_CLANG
1023#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
1030 int rc = this->decode(&base, BaseTag());
1038 return logError(
"Error converting from base type for customized");
1041#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
1042#pragma GCC diagnostic pop
1048template <
typename TYPE>
1060 return logError(
"Error converting enumeration value");
1066template <
typename TYPE>
1071 return logError(
"Expected PRIMITIVE tag type for simple type");
1077 *d_decoder->d_options) != 0) {
1078 return logError(
"Error reading value for simple type");
1081 d_consumedBodyBytes = d_expectedLength;
1086template <
typename TYPE>
1091 return logError(
"Expected CONSTRUCTED tag type for sequence");
1096 BerDecoder_Node innerNode(d_decoder);
1098 int rc = innerNode.readTagHeader();
1104 return innerNode.logError(
1105 "Expected CONTEXT tag class inside sequence");
1109 innerNode.tagNumber())) {
1111 BerDecoder_NodeVisitor visitor(&innerNode);
1116 innerNode.tagNumber());
1119 rc = innerNode.skipField();
1128 rc = innerNode.readTagTrailer();
1137template <
typename TYPE>
1144 return this->decodeArray(variable);
1147template <
typename TYPE>
1154template <
typename TYPE>
1155int BerDecoder_Node::decodeChoice(TYPE *variable)
1157 BerDecoder_Node innerNode(d_decoder);
1159 int rc = innerNode.readTagHeader();
1165 return innerNode.logError(
1166 "Expected CONTEXT tag class for internal choice");
1170 innerNode.tagNumber())) {
1173 innerNode.tagNumber())) {
1175 return innerNode.logError(
"Unable to make choice selection");
1178 BerDecoder_NodeVisitor visitor(&innerNode);
1183 rc = innerNode.skipField();
1192 return innerNode.readTagTrailer();
1195template <
typename TYPE>
1197BerDecoder_Node::decodeArray(TYPE *variable)
1200 return logError(
"Expected CONSTRUCTED tag class for array");
1210 return logError(
"Array size exceeds the limit");
1215 BerDecoder_UniversalElementVisitor visitor(d_decoder);
1218 return logError(
"Error in decoding array element");
1232BerDecoder_NodeVisitor::
1239template <
typename TYPE,
typename INFO>
1246 return d_node->operator()(variable);
1255BerDecoder_UniversalElementVisitor::
1256BerDecoder_UniversalElementVisitor(
BerDecoder *decoder)
1262template <
typename TYPE>
1265 int alternateTag = -1;
1277 return d_node.
logError(
"Expected UNIVERSAL tag class");
1280 if (d_node.
tagNumber() !=
static_cast<int>(expectedTagNumber)) {
1281 if (-1 == alternateTag || d_node.
tagNumber() != alternateTag) {
1282 return d_node.
logError(
"Unexpected tag number");
1286 rc = d_node(variable);
Definition balber_berdecoderoptions.h:76
const int & maxSequenceSize() const
Definition balber_berdecoderoptions.h:737
Definition balber_berdecoder.h:521
~BerDecoder_NodeVisitor()=default
int operator()(TYPE *variable, const INFO &info)
Definition balber_berdecoder.h:1241
Definition balber_berdecoder.h:355
BerDecoder_Node(BerDecoder *decoder, const TYPE *variable)
BerConstants::TagType tagType() const
Return the BER tag type for this node.
Definition balber_berdecoder.h:830
BerConstants::TagClass tagClass() const
Return the BER tag class for this node.
Definition balber_berdecoder.h:824
void setFieldName(const char *name)
Definition balber_berdecoder.h:867
void print(bsl::ostream &out, int depth, int spacePerLevel=0, const char *prefixText=0) const
int readVectorChar(bsl::vector< char > *variable)
const char * fieldName() const
Return field name for this node.
Definition balber_berdecoder.h:848
BerDecoder_Node * parent() const
Return the address of the parent node.
Definition balber_berdecoder.h:818
int operator()(TYPE *object, bslmf::Nil)
Definition balber_berdecoder.h:874
int logError(const char *msg)
int readVectorUnsignedChar(bsl::vector< unsigned char > *variable)
void setFormattingMode(int formattingMode)
Set formatting mode specified by formattingMode.
Definition balber_berdecoder.h:861
void printStack(bsl::ostream &out) const
int tagNumber() const
Return the BER tag number for this node.
Definition balber_berdecoder.h:836
int length() const
Definition balber_berdecoder.h:854
int formattingMode() const
Return formatting mode for this node.
Definition balber_berdecoder.h:842
int startPos() const
Return the position of node tag from the beginning of input stream.
bool hasMore()
Definition balber_berdecoder.h:805
~BerDecoder_Node()
Definition balber_berdecoder.h:790
Definition balber_berdecoder.h:552
~BerDecoder_UniversalElementVisitor()=default
int operator()(TYPE *variable)
Definition balber_berdecoder.h:1263
Definition balber_berdecoder.h:584
~BerDecoder_Zeroer()
Definition balber_berdecoder.h:597
BerDecoder_Zeroer(const BerDecoderOptions **options)
Definition balber_berdecoder.h:592
Definition balber_berdecoder.h:172
int numUnknownElementsSkipped() const
Definition balber_berdecoder.h:758
bool maxDepthExceeded() const
Definition balber_berdecoder.h:752
int decode(bsl::streambuf *streamBuf, TYPE *variable)
Definition balber_berdecoder.h:685
bslstl::StringRef loggedMessages() const
Definition balber_berdecoder.h:742
void setNumUnknownElementsSkipped(int value)
Definition balber_berdecoder.h:721
ErrorSeverity
Definition balber_berdecoder.h:224
@ BDEM_BER_SUCCESS
Definition balber_berdecoder.h:229
@ e_BER_SUCCESS
Definition balber_berdecoder.h:225
@ e_BER_ERROR
Definition balber_berdecoder.h:226
@ BDEM_BER_ERROR
Definition balber_berdecoder.h:230
BerDecoder(const BerDecoderOptions *options=0, bslma::Allocator *basicAllocator=0)
ErrorSeverity errorSeverity() const
Definition balber_berdecoder.h:736
const BerDecoderOptions * decoderOptions() const
Return the address of the BER decoder options.
Definition balber_berdecoder.h:730
Definition bdlsb_memoutstreambuf.h:212
Definition bslstl_vector.h:1025
Definition bslma_allocator.h:457
Definition bslstl_stringref.h:372
int length() const
Definition balber_berdecoder.h:638
const char * data() const
Definition balber_berdecoder.h:632
void reset()
Reset the internal streambuf to the empty state.
Definition balber_berdecoder.h:625
static int manipulateByCategory(TYPE *object, MANIPULATOR &manipulator)
Definition bdlat_typecategory.h:1404
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
Definition balber_berconstants.h:82
int manipulateElement(TYPE *array, MANIPULATOR &manipulator, int index)
void resize(TYPE *array, int newSize)
bsl::size_t size(const TYPE &array)
Return the number of elements in the specified array.
bool hasSelection(const TYPE &object, const char *selectionName, int selectionNameLength)
int manipulateSelection(TYPE *object, MANIPULATOR &manipulator)
int makeSelection(TYPE *object, int selectionId)
int convertFromBaseType(TYPE *object, const BASE_TYPE &value)
int manipulateValue(TYPE *object, MANIPULATOR &manipulator)
void makeValue(TYPE *object)
int manipulateAttribute(TYPE *object, MANIPULATOR &manipulator, const char *attributeName, int attributeNameLength)
bool hasAttribute(const TYPE &object, const char *attributeName, int attributeNameLength)
void reset(TYPE *object)
Reset the value of the specified object to its default value.
Definition bdlb_printmethods.h:283
Definition balxml_encoderoptions.h:68
StringRefImp< char > StringRef
Definition bslstl_stringref.h:699
Definition balber_berconstants.h:90
TagType
Definition balber_berconstants.h:113
@ e_PRIMITIVE
Definition balber_berconstants.h:116
@ e_CONSTRUCTED
Definition balber_berconstants.h:117
TagClass
Definition balber_berconstants.h:92
@ e_CONTEXT_SPECIFIC
Definition balber_berconstants.h:97
@ e_UNIVERSAL
Definition balber_berconstants.h:95
Value
Definition balber_beruniversaltagnumber.h:194
static Value select(const TYPE &object, int formattingMode, int *alternateTag)
Definition balber_beruniversaltagnumber.h:595
static int getValue(bsl::streambuf *streamBuf, TYPE *value, int length, const BerDecoderOptions &options=BerDecoderOptions())
Definition balber_berutil.h:3920
@ k_INDEFINITE_LENGTH
Definition balber_berutil.h:199
static int fromIntOrFallbackIfEnabled(TYPE *result, int number)
Definition bdlat_enumutil.h:329
TYPE::BaseType Type
Definition bdlat_customizedtypefunctions.h:536
Definition bdlat_typecategory.h:1035
Definition bdlat_typecategory.h:1036
Definition bdlat_typecategory.h:1037
Definition bdlat_typecategory.h:1034
Definition bdlat_typecategory.h:1038
Definition bdlat_typecategory.h:1039
Definition bdlat_typecategory.h:1040
Definition bdlat_typecategory.h:1041
This struct is empty and represents a nil type.
Definition bslmf_nil.h:131
Definition bsls_objectbuffer.h:276