//   NOTE: this is a machine generated file--editing not recommended
//
// rfc1157-snmp.C - class member functions for ASN.1 module RFC1157-SNMP
//
//   This file was generated by snacc on Mon May 25 16:21:56 1998
//   UBC snacc written by Mike Sample
//   A couple of enhancements made by IBM European Networking Center

#include <typeinfo> 

#include "asn-incl.h"
#include "rfc1155-smi.h"
#include "rfc1157-snmp.h"
#include "rfc1213-mib2.h"

//------------------------------------------------------------------------------
// value defs


//------------------------------------------------------------------------------
// class member definitions:

VarBind::VarBind()
{
#if TCL
  value = new ObjectSyntax;
#else
  value = NULL; // incomplete initialization of mandatory element!
#endif // TCL
}

VarBind::VarBind (const VarBind &)
{
  Asn1Error << "use of incompletely defined VarBind::VarBind (const VarBind &)" << endl;
  abort();
}

VarBind::~VarBind()
{
  delete value;
}

AsnType *VarBind::Clone() const
{
  return new VarBind;
}

#if SNACC_DEEP_COPY
VarBind &VarBind::operator = (const VarBind &that)
#else // SNACC_DEEP_COPY
VarBind &VarBind::operator = (const VarBind &)
#endif // SNACC_DEEP_COPY
{
#if SNACC_DEEP_COPY
  if (this != &that)
  {
    name = that.name;
    if (that.value)
    {
      if (!value)
        value = new ObjectSyntax;
      *value = *that.value;
    }
    else
    {
      delete value;
      value = NULL;
    }
  }

  return *this;
#else // SNACC_DEEP_COPY
  Asn1Error << "use of incompletely defined VarBind &VarBind::operator = (const VarBind &)" << endl;
  abort();
  // if your compiler complains here, check the -novolat option
#endif // SNACC_DEEP_COPY
}

AsnLen
VarBind::BEncContent (BUF_TYPE b)
{
  AsnLen totalLen = 0;
  AsnLen l;

    l = value->BEncContent (b);
    totalLen += l;

    l = name.BEncContent (b);
    l += BEncDefLen (b, l);

    l += BEncTag1 (b, UNIV, PRIM, OID_TAG_CODE);
    totalLen += l;

  return totalLen;
} // VarBind::BEncContent


void VarBind::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
{
  AsnTag tag1;
  AsnLen seqBytesDecoded = 0;
  AsnLen elmtLen1;
  tag1 = BDecTag (b, seqBytesDecoded, env);

  if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    name.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
    tag1 = BDecTag (b, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -100);
  }

  if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
    || (tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
    || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE))
    || (tag1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE))
    || (tag1 == MAKE_TAG_ID (UNIV, PRIM, NULLTYPE_TAG_CODE))
    || (tag1 == MAKE_TAG_ID (APPL, PRIM, 0))
    || (tag1 == MAKE_TAG_ID (APPL, CONS, 0))
    || (tag1 == MAKE_TAG_ID (APPL, PRIM, 1))
    || (tag1 == MAKE_TAG_ID (APPL, PRIM, 2))
    || (tag1 == MAKE_TAG_ID (APPL, PRIM, 3))
    || (tag1 == MAKE_TAG_ID (APPL, PRIM, 4))
    || (tag1 == MAKE_TAG_ID (APPL, CONS, 4)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    value = new ObjectSyntax;
    value->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -101);
  }

  bytesDecoded += seqBytesDecoded;
  if (elmtLen0 == INDEFINITE_LEN)
  {
    BDecEoc (b, bytesDecoded, env);
    return;
  }
  else if (seqBytesDecoded != elmtLen0)
  {
    Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
    longjmp (env, -102);
  }
  else
    return;
} // VarBind::BDecContent

AsnLen VarBind::BEnc (BUF_TYPE b)
{
  AsnLen l;
  l = BEncContent (b);
  l += BEncConsLen (b, l);
  l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
  return l;
}

void VarBind::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
{
  AsnTag tag;
  AsnLen elmtLen1;

  if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
  {
    Asn1Error << "VarBind::BDec: ERROR - wrong tag" << endl;
    longjmp (env, -103);
  }
  elmtLen1 = BDecLen (b, bytesDecoded, env);
  BDecContent (b, tag, elmtLen1, bytesDecoded, env);
}

int VarBind::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
{
    bytesEncoded = BEnc (b);
    return !b.WriteError();
}

int VarBind::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
{
    ENV_TYPE env;
    int val;

    bytesDecoded = 0;
    if ((val = setjmp (env)) == 0)
    {
         BDec (b, bytesDecoded, env);
         return !b.ReadError();
    }
    else
        return false;
}

void VarBind::Print (ostream &os) const
{
  os << "{ -- SEQUENCE --" << endl;
  indentG += stdIndentG;

  {
    Indent (os, indentG);
    os << "name ";
    os << name;
    os << "," << endl;
  }

  if (NOT_NULL (value))
  {
    Indent (os, indentG);
    os << "value ";
    os << *value;
  }
  else
  {
    Indent (os, indentG);
    os << "value ";
    os << "-- void --";
    os << endl;
  }

  os << endl;
  indentG -= stdIndentG;
  Indent (os, indentG);
  os << "}";
} // VarBind::Print


AsnType *VarBindList::Clone() const
{
  return new VarBindList;
}

AsnLen VarBindList::BEnc (BUF_TYPE b)
{
  AsnLen l;
  l = BEncContent (b);
  l += BEncConsLen (b, l);
  l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
  return l;
}

void VarBindList::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
{
  AsnTag tag;
  AsnLen elmtLen1;

  if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
  {
    Asn1Error << "VarBindList::BDec: ERROR - wrong tag" << endl;
    longjmp (env, -104);
  }
  elmtLen1 = BDecLen (b, bytesDecoded, env);
  BDecContent (b, tag, elmtLen1, bytesDecoded, env);
}

VarBindList::VarBindList (const VarBindList &)
{
  Asn1Error << "use of incompletely defined VarBindList::VarBindList (const VarBindList &)" << endl;
  abort();
}

VarBindList::~VarBindList()
{
  SetCurrToFirst();
  for (; Curr() != NULL; RemoveCurrFromList())
    ;
} // end of destructor

#if SNACC_DEEP_COPY
VarBindList &VarBindList::operator = (const VarBindList &that)
#else // SNACC_DEEP_COPY
VarBindList &VarBindList::operator = (const VarBindList &)
#endif // SNACC_DEEP_COPY
{
#if SNACC_DEEP_COPY
  if (this != &that)
  {
    SetCurrToFirst();
    for (; Curr(); RemoveCurrFromList())
      ;

    //that.SetCurrToFirst();
    //for (; that.Curr(); that.GoNext())
    //  AppendCopy (*that.Curr());
    for (const AsnListElmt *run=that.first; run; run=run->next)
      AppendCopy (*run->elmt);
  }

  return *this;
#else // SNACC_DEEP_COPY
  Asn1Error << "use of incompletely defined VarBindList &VarBindList::operator = (const VarBindList &)" << endl;
  abort();
  // if your compiler complains here, check the -novolat option
#endif // SNACC_DEEP_COPY
}

void VarBindList::Print (ostream &os) const
{
    os << "{ -- SEQUENCE/SET OF -- " << endl;
    indentG += stdIndentG;
    //SetCurrToFirst();
    //for (; Curr() != NULL; GoNext())
    for (const AsnListElmt *run=first; run; run=run->next)
    {
        Indent (os, indentG);
        //os << *Curr();
        os << *run->elmt;
        //if (Curr() != Last())
        if (run != last)
            os << ",";
        os << endl;
    }
    indentG -= stdIndentG;
    Indent (os, indentG);
    os << "}\n";
} // Print


void  VarBindList::SetCurrElmt (unsigned long int index)
{
  unsigned long int i;
  curr = first;
  if (count)
    for (i = 0; (i < (count-1)) && (i < index); i++)
      curr = curr->next;
} // VarBindList::SetCurrElmt


unsigned long int  VarBindList::GetCurrElmtIndex()
{
    unsigned long int i;
    AsnListElmt *tmp;
    if (curr != NULL)
    {
        for (i = 0, tmp = first; tmp != NULL; i++)
        {
            if (tmp == curr)
                return i;
            else
                tmp = tmp->next;
        }
    }
    return count;
} // VarBindList::GetCurrElmtIndex


// alloc new list elmt, put at end of list
//  and return the component type
VarBind *VarBindList::Append()
{
    AsnListElmt *newElmt;
    newElmt  = new AsnListElmt;
    newElmt->elmt  = new VarBind;
    newElmt->next = NULL;
    if (last == NULL)
    {
        newElmt->prev = NULL;
        first = last  = newElmt;
    }
    else
    {
        newElmt->prev = last;
        last->next    = newElmt;
        last          = newElmt;
    }
    count++;
    return (curr = newElmt)->elmt;
} // VarBindList::Append


// alloc new list elmt, put at begining of list
//  and return the component type
VarBind  *VarBindList::Prepend()
{
    AsnListElmt *newElmt;
    newElmt  = new AsnListElmt;
    newElmt->elmt = new VarBind;
    newElmt->prev = NULL;
    if (first == NULL)
    {
        newElmt->next = NULL;
        first = last  = newElmt;
    }
    else
    {
        newElmt->next = first;
        first->prev   = newElmt;
        first         = newElmt;
    }
    count++;
    return (curr = newElmt)->elmt;
} // VarBindList::Prepend


// alloc new list elmt, insert it before the
// current element and return the component type
// if the current element is null, the new element
// is placed at the beginning of the list.
VarBind  *VarBindList::InsertBefore()
{
    AsnListElmt *newElmt;
    newElmt  = new AsnListElmt;
    newElmt->elmt = new VarBind;
    if (curr == NULL)
    {
        newElmt->next = first;
        newElmt->prev = NULL;
        first = newElmt;
        if (last == NULL)
            last = newElmt;
    }
    else
    {
        newElmt->next = curr;
        newElmt->prev = curr->prev;
        curr->prev = newElmt;
        if (curr == first)
            first = newElmt;
        else
            newElmt->prev->next = newElmt;
    }
    count++;
    return (curr = newElmt)->elmt;
} // VarBindList::InsertBefore


// alloc new list elmt, insert it after the
// current element and return the component type
// if the current element is null, the new element
// is placed at the end of the list.
VarBind *VarBindList::InsertAfter()
{
    AsnListElmt *newElmt;
    newElmt  = new AsnListElmt;
    newElmt->elmt = new VarBind;
    if (curr == NULL)
    {
        newElmt->prev = last;
        newElmt->next = NULL;
        last = newElmt;
        if (first == NULL)
            first = newElmt;
    }
    else
    {
        newElmt->prev = curr;
        newElmt->next = curr->next;
        curr->next = newElmt;
        if (curr == last)
            last = newElmt;
        else
            newElmt->next->prev = newElmt;
    }
    count++;
    return (curr = newElmt)->elmt;
} // VarBindList::InsertAfter


VarBindList  &VarBindList::AppendCopy (VarBind &elmt)
{
    AsnListElmt *newElmt;
    newElmt  = new AsnListElmt;
    newElmt->elmt = new VarBind;
    *newElmt->elmt = elmt;
    newElmt->next = NULL;
    if (last == NULL)
    {
        newElmt->prev = NULL;
        first = last  = newElmt;
    }
    else
    {
        newElmt->prev = last;
        last->next    = newElmt;
        last          = newElmt;
    }
    count++;
    return *this;
} // AppendCopy


VarBindList  &VarBindList::PrependCopy (VarBind &elmt)
{
    AsnListElmt *newElmt;
    newElmt  = new AsnListElmt;
    newElmt->elmt = new VarBind;
    *newElmt->elmt = elmt;
    newElmt->prev = NULL;
    if (first == NULL)
    {
        newElmt->next = NULL;
        first = last  = newElmt;
    }
    else
    {
        newElmt->next = first;
        first->prev   = newElmt;
        first         = newElmt;
    }
    count++;
    return *this;
} // VarBindList::PrependCopy


// alloc new list elmt, insert it before the
// current element, copy the given elmt into the new elmt
// and return the component type.
// if the current element is null, the new element
// is placed at the beginning of the list.
VarBindList &VarBindList::InsertBeforeAndCopy (VarBind &elmt)
{
    AsnListElmt *newElmt;

    newElmt  = new AsnListElmt;
    newElmt->elmt = new VarBind;
    *newElmt->elmt = elmt;

    if (curr == NULL)
    {
        newElmt->next = first;
        newElmt->prev = NULL;
        first = newElmt;
        if (last == NULL)
            last = newElmt;
    }
    else
    {
        newElmt->next = curr;
        newElmt->prev = curr->prev;
        curr->prev = newElmt;
        if (curr == first)
            first = newElmt;
        else
            newElmt->prev->next = newElmt;
    }
    count++;
    return *this;
} // VarBindList::InsertBeforeAndCopy


// alloc new list elmt, insert it after the
// current element, copy given elmt in to new elmt
//  and return the component type
// if the current element is null, the new element
// is placed at the end of the list.
VarBindList  &VarBindList::InsertAfterAndCopy (VarBind &elmt)
{
    AsnListElmt *newElmt;

    newElmt  = new AsnListElmt;
    newElmt->elmt = new VarBind;
    *newElmt->elmt = elmt;
    if (curr == NULL)
    {
        newElmt->prev = last;
        newElmt->next = NULL;
        last = newElmt;
        if (first == NULL)
            first = newElmt;
    }
    else
    {
        newElmt->prev = curr;
        newElmt->next = curr->next;
        curr->next = newElmt;
        if (curr == last)
            last = newElmt;
        else
            newElmt->next->prev = newElmt;
    }
    count++;
    return *this;
} // VarBindList::InsertAfterAndCopy


// remove current element from list if current element is not NULL 
// The new current element will be the next element.
// If the current element is the last element in the list
// the second but last element will become the new current element.
void VarBindList::RemoveCurrFromList()
{
    AsnListElmt *del_elmt;

    if (curr != NULL)
    {
        del_elmt = curr;
        count--;

        if (count == 0)
            first = last = curr = NULL;
        else if (curr == first)
        {
            curr = first= first->next;
            first->prev = NULL;
        }
        else if (curr == last)
        {
            curr = last = last->prev;
            last->next = NULL;
        }
        else
        {
            curr->prev->next = curr->next;
            curr->next->prev = curr->prev;
        }

        delete del_elmt->elmt;
        delete del_elmt;
    }
}


AsnLen VarBindList::BEncContent (BUF_TYPE b)
{
    AsnListElmt *currElmt;
    AsnLen elmtLen;
    AsnLen totalLen = 0;
    for (currElmt = last; currElmt != NULL; currElmt = currElmt->prev)
    {
      BEncEocIfNec (b);
        elmtLen = currElmt->elmt->BEncContent (b);
    elmtLen += BEncConsLen (b, elmtLen);

    elmtLen += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
        totalLen += elmtLen;
    }
    return totalLen;
} // VarBindList::BEncContent


void  VarBindList::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0,
                                  AsnLen &bytesDecoded, ENV_TYPE env)
{
    VarBind *listElmt;
    AsnTag tag1;
    AsnLen listBytesDecoded = 0;
    AsnLen elmtLen1;

    while ((listBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN))
    {
        tag1 = BDecTag (b, listBytesDecoded, env);
        if ((tag1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
        {
            BDEC_2ND_EOC_OCTET (b, listBytesDecoded, env);
            break;
        }
        if ((tag1 != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
        {
            Asn1Error << "Unexpected Tag" << endl;
            longjmp (env, -105);
        }

        elmtLen1 = BDecLen (b, listBytesDecoded, env);
        listElmt = Append();
        listElmt->BDecContent (b, tag1, elmtLen1, listBytesDecoded, env);
    }

    bytesDecoded += listBytesDecoded;
} // VarBindList::BDecContent


PDU::PDU()
{
}

PDU::PDU (const PDU &)
{
  Asn1Error << "use of incompletely defined PDU::PDU (const PDU &)" << endl;
  abort();
}

PDU::~PDU()
{
}

AsnType *PDU::Clone() const
{
  return new PDU;
}

#if SNACC_DEEP_COPY
PDU &PDU::operator = (const PDU &that)
#else // SNACC_DEEP_COPY
PDU &PDU::operator = (const PDU &)
#endif // SNACC_DEEP_COPY
{
#if SNACC_DEEP_COPY
  if (this != &that)
  {
    request_id = that.request_id;
    error_status = that.error_status;
    error_index = that.error_index;
    variable_bindings = that.variable_bindings;
  }

  return *this;
#else // SNACC_DEEP_COPY
  Asn1Error << "use of incompletely defined PDU &PDU::operator = (const PDU &)" << endl;
  abort();
  // if your compiler complains here, check the -novolat option
#endif // SNACC_DEEP_COPY
}

AsnLen
PDU::BEncContent (BUF_TYPE b)
{
  AsnLen totalLen = 0;
  AsnLen l;

      BEncEocIfNec (b);
    l = variable_bindings.BEncContent (b);
    l += BEncConsLen (b, l);

    l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
    totalLen += l;

    l = error_index.BEncContent (b);
    BEncDefLenTo127 (b, l);
    l++;

    l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
    totalLen += l;

    l = error_status.BEncContent (b);
    BEncDefLenTo127 (b, l);
    l++;

    l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
    totalLen += l;

    l = request_id.BEncContent (b);
    BEncDefLenTo127 (b, l);
    l++;

    l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
    totalLen += l;

  return totalLen;
} // PDU::BEncContent


void PDU::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
{
  AsnTag tag1;
  AsnLen seqBytesDecoded = 0;
  AsnLen elmtLen1;
  tag1 = BDecTag (b, seqBytesDecoded, env);

  if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    request_id.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
    tag1 = BDecTag (b, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -106);
  }

  if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    error_status.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
    tag1 = BDecTag (b, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -107);
  }

  if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    error_index.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
    tag1 = BDecTag (b, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -108);
  }

  if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    variable_bindings.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -109);
  }

  bytesDecoded += seqBytesDecoded;
  if (elmtLen0 == INDEFINITE_LEN)
  {
    BDecEoc (b, bytesDecoded, env);
    return;
  }
  else if (seqBytesDecoded != elmtLen0)
  {
    Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
    longjmp (env, -110);
  }
  else
    return;
} // PDU::BDecContent

AsnLen PDU::BEnc (BUF_TYPE b)
{
  AsnLen l;
  l = BEncContent (b);
  l += BEncConsLen (b, l);
  l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
  return l;
}

void PDU::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
{
  AsnTag tag;
  AsnLen elmtLen1;

  if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
  {
    Asn1Error << "PDU::BDec: ERROR - wrong tag" << endl;
    longjmp (env, -111);
  }
  elmtLen1 = BDecLen (b, bytesDecoded, env);
  BDecContent (b, tag, elmtLen1, bytesDecoded, env);
}

int PDU::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
{
    bytesEncoded = BEnc (b);
    return !b.WriteError();
}

int PDU::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
{
    ENV_TYPE env;
    int val;

    bytesDecoded = 0;
    if ((val = setjmp (env)) == 0)
    {
         BDec (b, bytesDecoded, env);
         return !b.ReadError();
    }
    else
        return false;
}

void PDU::Print (ostream &os) const
{
  os << "{ -- SEQUENCE --" << endl;
  indentG += stdIndentG;

  {
    Indent (os, indentG);
    os << "request-id ";
    os << request_id;
    os << "," << endl;
  }

  {
    Indent (os, indentG);
    os << "error-status ";
    os << error_status;
    os << "," << endl;
  }

  {
    Indent (os, indentG);
    os << "error-index ";
    os << error_index;
    os << "," << endl;
  }

  {
    Indent (os, indentG);
    os << "variable-bindings ";
    os << variable_bindings;
  }

  os << endl;
  indentG -= stdIndentG;
  Indent (os, indentG);
  os << "}";
} // PDU::Print


Trap_PDU::Trap_PDU()
{
#if TCL
  agent_addr = new NetworkAddress;
#else
  agent_addr = NULL; // incomplete initialization of mandatory element!
#endif // TCL
}

Trap_PDU::Trap_PDU (const Trap_PDU &)
{
  Asn1Error << "use of incompletely defined Trap_PDU::Trap_PDU (const Trap_PDU &)" << endl;
  abort();
}

Trap_PDU::~Trap_PDU()
{
  delete agent_addr;
}

AsnType *Trap_PDU::Clone() const
{
  return new Trap_PDU;
}

#if SNACC_DEEP_COPY
Trap_PDU &Trap_PDU::operator = (const Trap_PDU &that)
#else // SNACC_DEEP_COPY
Trap_PDU &Trap_PDU::operator = (const Trap_PDU &)
#endif // SNACC_DEEP_COPY
{
#if SNACC_DEEP_COPY
  if (this != &that)
  {
    enterprise = that.enterprise;
    if (that.agent_addr)
    {
      if (!agent_addr)
        agent_addr = new NetworkAddress;
      *agent_addr = *that.agent_addr;
    }
    else
    {
      delete agent_addr;
      agent_addr = NULL;
    }
    generic_trap = that.generic_trap;
    specific_trap = that.specific_trap;
    time_stamp = that.time_stamp;
    variable_bindings = that.variable_bindings;
  }

  return *this;
#else // SNACC_DEEP_COPY
  Asn1Error << "use of incompletely defined Trap_PDU &Trap_PDU::operator = (const Trap_PDU &)" << endl;
  abort();
  // if your compiler complains here, check the -novolat option
#endif // SNACC_DEEP_COPY
}

AsnLen
Trap_PDU::BEncContent (BUF_TYPE b)
{
  AsnLen totalLen = 0;
  AsnLen l;

      BEncEocIfNec (b);
    l = variable_bindings.BEncContent (b);
    l += BEncConsLen (b, l);

    l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
    totalLen += l;

    l = time_stamp.BEncContent (b);
    BEncDefLenTo127 (b, l);
    l++;

    l += BEncTag1 (b, APPL, PRIM, 3);
    totalLen += l;

    l = specific_trap.BEncContent (b);
    BEncDefLenTo127 (b, l);
    l++;

    l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
    totalLen += l;

    l = generic_trap.BEncContent (b);
    BEncDefLenTo127 (b, l);
    l++;

    l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
    totalLen += l;

    l = agent_addr->BEncContent (b);
    totalLen += l;

    l = enterprise.BEncContent (b);
    l += BEncDefLen (b, l);

    l += BEncTag1 (b, UNIV, PRIM, OID_TAG_CODE);
    totalLen += l;

  return totalLen;
} // Trap_PDU::BEncContent


void Trap_PDU::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
{
  AsnTag tag1;
  AsnLen seqBytesDecoded = 0;
  AsnLen elmtLen1;
  tag1 = BDecTag (b, seqBytesDecoded, env);

  if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    enterprise.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
    tag1 = BDecTag (b, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -112);
  }

  if ((tag1 == MAKE_TAG_ID (APPL, PRIM, 0))
    || (tag1 == MAKE_TAG_ID (APPL, CONS, 0)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    agent_addr = new NetworkAddress;
    agent_addr->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
    tag1 = BDecTag (b, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -113);
  }

  if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    generic_trap.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
    tag1 = BDecTag (b, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -114);
  }

  if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    specific_trap.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
    tag1 = BDecTag (b, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -115);
  }

  if ((tag1 == MAKE_TAG_ID (APPL, PRIM, 3)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    time_stamp.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
    tag1 = BDecTag (b, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -116);
  }

  if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    variable_bindings.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -117);
  }

  bytesDecoded += seqBytesDecoded;
  if (elmtLen0 == INDEFINITE_LEN)
  {
    BDecEoc (b, bytesDecoded, env);
    return;
  }
  else if (seqBytesDecoded != elmtLen0)
  {
    Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
    longjmp (env, -118);
  }
  else
    return;
} // Trap_PDU::BDecContent

AsnLen Trap_PDU::BEnc (BUF_TYPE b)
{
  AsnLen l;
  l = BEncContent (b);
  l += BEncConsLen (b, l);
  l += BEncTag1 (b, CNTX, CONS, 4);
  return l;
}

void Trap_PDU::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
{
  AsnTag tag;
  AsnLen elmtLen1;

  if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (CNTX, CONS, 4))
  {
    Asn1Error << "Trap_PDU::BDec: ERROR - wrong tag" << endl;
    longjmp (env, -119);
  }
  elmtLen1 = BDecLen (b, bytesDecoded, env);
  BDecContent (b, tag, elmtLen1, bytesDecoded, env);
}

int Trap_PDU::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
{
    bytesEncoded = BEnc (b);
    return !b.WriteError();
}

int Trap_PDU::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
{
    ENV_TYPE env;
    int val;

    bytesDecoded = 0;
    if ((val = setjmp (env)) == 0)
    {
         BDec (b, bytesDecoded, env);
         return !b.ReadError();
    }
    else
        return false;
}

void Trap_PDU::Print (ostream &os) const
{
  os << "{ -- SEQUENCE --" << endl;
  indentG += stdIndentG;

  {
    Indent (os, indentG);
    os << "enterprise ";
    os << enterprise;
    os << "," << endl;
  }

  if (NOT_NULL (agent_addr))
  {
    Indent (os, indentG);
    os << "agent-addr ";
    os << *agent_addr;
  }
  else
  {
    Indent (os, indentG);
    os << "agent-addr ";
    os << "-- void --";
    os << "," << endl;
  }

  {
    Indent (os, indentG);
    os << "generic-trap ";
    os << generic_trap;
    os << "," << endl;
  }

  {
    Indent (os, indentG);
    os << "specific-trap ";
    os << specific_trap;
    os << "," << endl;
  }

  {
    Indent (os, indentG);
    os << "time-stamp ";
    os << time_stamp;
    os << "," << endl;
  }

  {
    Indent (os, indentG);
    os << "variable-bindings ";
    os << variable_bindings;
  }

  os << endl;
  indentG -= stdIndentG;
  Indent (os, indentG);
  os << "}";
} // Trap_PDU::Print


AsnType *GetRequest_PDU::Clone() const
{
  return new GetRequest_PDU;
}

AsnLen GetRequest_PDU::BEnc (BUF_TYPE b)
{
    AsnLen l;
      BEncEocIfNec (b);
    l = BEncContent (b);
    l += BEncConsLen (b, l);

    l += BEncTag1 (b, CNTX, CONS, 0);
    return l;
}

void GetRequest_PDU::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
{
    AsnTag tag;
    AsnLen elmtLen1;

    if (((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (CNTX, CONS, 0)))
    {
        Asn1Error << "GetRequest_PDU::BDec: ERROR - wrong tag" << endl;
        longjmp (env, -120);
    }
    elmtLen1 = BDecLen (b, bytesDecoded, env);
    BDecContent (b, tag, elmtLen1, bytesDecoded, env);
}

int GetRequest_PDU::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
{
    bytesEncoded = BEnc (b);
    return !b.WriteError();
}

int GetRequest_PDU::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
{
    ENV_TYPE env;
    int val;

    bytesDecoded = 0;
    if ((val = setjmp (env)) == 0)
    {
         BDec (b, bytesDecoded, env);
         return !b.ReadError();
    }
    else
        return false;
}

AsnType *GetNextRequest_PDU::Clone() const
{
  return new GetNextRequest_PDU;
}

AsnLen GetNextRequest_PDU::BEnc (BUF_TYPE b)
{
    AsnLen l;
      BEncEocIfNec (b);
    l = BEncContent (b);
    l += BEncConsLen (b, l);

    l += BEncTag1 (b, CNTX, CONS, 1);
    return l;
}

void GetNextRequest_PDU::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
{
    AsnTag tag;
    AsnLen elmtLen1;

    if (((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (CNTX, CONS, 1)))
    {
        Asn1Error << "GetNextRequest_PDU::BDec: ERROR - wrong tag" << endl;
        longjmp (env, -121);
    }
    elmtLen1 = BDecLen (b, bytesDecoded, env);
    BDecContent (b, tag, elmtLen1, bytesDecoded, env);
}

int GetNextRequest_PDU::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
{
    bytesEncoded = BEnc (b);
    return !b.WriteError();
}

int GetNextRequest_PDU::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
{
    ENV_TYPE env;
    int val;

    bytesDecoded = 0;
    if ((val = setjmp (env)) == 0)
    {
         BDec (b, bytesDecoded, env);
         return !b.ReadError();
    }
    else
        return false;
}

AsnType *GetResponse_PDU::Clone() const
{
  return new GetResponse_PDU;
}

AsnLen GetResponse_PDU::BEnc (BUF_TYPE b)
{
    AsnLen l;
      BEncEocIfNec (b);
    l = BEncContent (b);
    l += BEncConsLen (b, l);

    l += BEncTag1 (b, CNTX, CONS, 2);
    return l;
}

void GetResponse_PDU::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
{
    AsnTag tag;
    AsnLen elmtLen1;

    if (((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (CNTX, CONS, 2)))
    {
        Asn1Error << "GetResponse_PDU::BDec: ERROR - wrong tag" << endl;
        longjmp (env, -122);
    }
    elmtLen1 = BDecLen (b, bytesDecoded, env);
    BDecContent (b, tag, elmtLen1, bytesDecoded, env);
}

int GetResponse_PDU::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
{
    bytesEncoded = BEnc (b);
    return !b.WriteError();
}

int GetResponse_PDU::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
{
    ENV_TYPE env;
    int val;

    bytesDecoded = 0;
    if ((val = setjmp (env)) == 0)
    {
         BDec (b, bytesDecoded, env);
         return !b.ReadError();
    }
    else
        return false;
}

AsnType *SetRequest_PDU::Clone() const
{
  return new SetRequest_PDU;
}

AsnLen SetRequest_PDU::BEnc (BUF_TYPE b)
{
    AsnLen l;
      BEncEocIfNec (b);
    l = BEncContent (b);
    l += BEncConsLen (b, l);

    l += BEncTag1 (b, CNTX, CONS, 3);
    return l;
}

void SetRequest_PDU::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
{
    AsnTag tag;
    AsnLen elmtLen1;

    if (((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (CNTX, CONS, 3)))
    {
        Asn1Error << "SetRequest_PDU::BDec: ERROR - wrong tag" << endl;
        longjmp (env, -123);
    }
    elmtLen1 = BDecLen (b, bytesDecoded, env);
    BDecContent (b, tag, elmtLen1, bytesDecoded, env);
}

int SetRequest_PDU::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
{
    bytesEncoded = BEnc (b);
    return !b.WriteError();
}

int SetRequest_PDU::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
{
    ENV_TYPE env;
    int val;

    bytesDecoded = 0;
    if ((val = setjmp (env)) == 0)
    {
         BDec (b, bytesDecoded, env);
         return !b.ReadError();
    }
    else
        return false;
}

PDUs::PDUs()
{
  choiceId = get_requestCid;
#if TCL
  get_request = new GetRequest_PDU;
#else
  get_request = NULL; // incomplete initialization of mandatory element!
#endif // TCL
}

PDUs::PDUs (const PDUs &)
{
  Asn1Error << "use of incompletely defined PDUs::PDUs (const PDUs &)" << endl;
  abort();
}

PDUs::~PDUs()
{
  switch (choiceId)
  {
    case get_requestCid:
      delete get_request;
      break;
    case get_next_requestCid:
      delete get_next_request;
      break;
    case get_responseCid:
      delete get_response;
      break;
    case set_requestCid:
      delete set_request;
      break;
    case trapCid:
      delete trap;
      break;
  } // end of switch
} // end of destructor

AsnType *PDUs::Clone() const
{
  return new PDUs;
}

#if SNACC_DEEP_COPY
PDUs &PDUs::operator = (const PDUs &that)
#else // SNACC_DEEP_COPY
PDUs &PDUs::operator = (const PDUs &)
#endif // SNACC_DEEP_COPY
{
#if SNACC_DEEP_COPY
  if (this != &that)
  {
    switch (choiceId)
    {
      case get_requestCid:
        delete get_request;
        break;
      case get_next_requestCid:
        delete get_next_request;
        break;
      case get_responseCid:
        delete get_response;
        break;
      case set_requestCid:
        delete set_request;
        break;
      case trapCid:
        delete trap;
        break;
    }
    switch (choiceId = that.choiceId)
    {
      case get_requestCid:
        get_request = new GetRequest_PDU;
        *get_request = *that.get_request;
        break;
      case get_next_requestCid:
        get_next_request = new GetNextRequest_PDU;
        *get_next_request = *that.get_next_request;
        break;
      case get_responseCid:
        get_response = new GetResponse_PDU;
        *get_response = *that.get_response;
        break;
      case set_requestCid:
        set_request = new SetRequest_PDU;
        *set_request = *that.set_request;
        break;
      case trapCid:
        trap = new Trap_PDU;
        *trap = *that.trap;
        break;
    }
  }

  return *this;
#else // SNACC_DEEP_COPY
  Asn1Error << "use of incompletely defined PDUs &PDUs::operator = (const PDUs &)" << endl;
  abort();
  // if your compiler complains here, check the -novolat option
#endif // SNACC_DEEP_COPY
}

AsnLen
PDUs::BEncContent (BUF_TYPE b)
{
  AsnLen l;
  switch (choiceId)
  {
    case get_requestCid:
      BEncEocIfNec (b);
      l = get_request->BEncContent (b);
    l += BEncConsLen (b, l);

    l += BEncTag1 (b, CNTX, CONS, 0);
      break;

    case get_next_requestCid:
      BEncEocIfNec (b);
      l = get_next_request->BEncContent (b);
    l += BEncConsLen (b, l);

    l += BEncTag1 (b, CNTX, CONS, 1);
      break;

    case get_responseCid:
      BEncEocIfNec (b);
      l = get_response->BEncContent (b);
    l += BEncConsLen (b, l);

    l += BEncTag1 (b, CNTX, CONS, 2);
      break;

    case set_requestCid:
      BEncEocIfNec (b);
      l = set_request->BEncContent (b);
    l += BEncConsLen (b, l);

    l += BEncTag1 (b, CNTX, CONS, 3);
      break;

    case trapCid:
      BEncEocIfNec (b);
      l = trap->BEncContent (b);
    l += BEncConsLen (b, l);

    l += BEncTag1 (b, CNTX, CONS, 4);
      break;

  } // end switch
  return l;
} // PDUs::BEncContent


void PDUs::BDecContent (BUF_TYPE b, AsnTag tag, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
{
  switch (tag)
  {
    case MAKE_TAG_ID (CNTX, CONS, 0):
      choiceId = get_requestCid;
      get_request = new GetRequest_PDU;
        get_request->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
      break;

    case MAKE_TAG_ID (CNTX, CONS, 1):
      choiceId = get_next_requestCid;
      get_next_request = new GetNextRequest_PDU;
        get_next_request->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
      break;

    case MAKE_TAG_ID (CNTX, CONS, 2):
      choiceId = get_responseCid;
      get_response = new GetResponse_PDU;
        get_response->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
      break;

    case MAKE_TAG_ID (CNTX, CONS, 3):
      choiceId = set_requestCid;
      set_request = new SetRequest_PDU;
        set_request->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
      break;

    case MAKE_TAG_ID (CNTX, CONS, 4):
      choiceId = trapCid;
      trap = new Trap_PDU;
        trap->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
      break;

    default:
      Asn1Error << "ERROR - unexpected tag in CHOICE" << endl;
      longjmp (env, -124);
      break;
  } // end switch
} // PDUs::BDecContent


AsnLen PDUs::BEnc (BUF_TYPE b)
{
    AsnLen l;
    l = BEncContent (b);
    return l;
}

void PDUs::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
{
    AsnLen elmtLen;
    AsnTag tag;

    /*  CHOICEs are a special case - grab identifying tag */
    /*  this allows easier handling of nested CHOICEs */
    tag = BDecTag (b, bytesDecoded, env);
    elmtLen = BDecLen (b, bytesDecoded, env);
    BDecContent (b, tag, elmtLen, bytesDecoded, env);
}

int PDUs::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
{
    bytesEncoded = BEnc (b);
    return !b.WriteError();
}

int PDUs::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
{
    ENV_TYPE env;
    int val;

    bytesDecoded = 0;
    if ((val = setjmp (env)) == 0)
    {
         BDec (b, bytesDecoded, env);
         return !b.ReadError();
    }
    else
        return false;
}

void PDUs::Print (ostream &os) const
{
  switch (choiceId)
  {
    case get_requestCid:
      os << "get-request ";
      if (get_request)
        os << *get_request;
      else
        os << "-- void3 --\n";
      break;

    case get_next_requestCid:
      os << "get-next-request ";
      if (get_next_request)
        os << *get_next_request;
      else
        os << "-- void3 --\n";
      break;

    case get_responseCid:
      os << "get-response ";
      if (get_response)
        os << *get_response;
      else
        os << "-- void3 --\n";
      break;

    case set_requestCid:
      os << "set-request ";
      if (set_request)
        os << *set_request;
      else
        os << "-- void3 --\n";
      break;

    case trapCid:
      os << "trap ";
      if (trap)
        os << *trap;
      else
        os << "-- void3 --\n";
      break;

  } // end of switch
} // PDUs::Print

Message::Message()
{
#if TCL
  data = new PDUs;
#else
  data = NULL; // incomplete initialization of mandatory element!
#endif // TCL
}

Message::Message (const Message &)
{
  Asn1Error << "use of incompletely defined Message::Message (const Message &)" << endl;
  abort();
}

Message::~Message()
{
  delete data;
}

AsnType *Message::Clone() const
{
  return new Message;
}

#if SNACC_DEEP_COPY
Message &Message::operator = (const Message &that)
#else // SNACC_DEEP_COPY
Message &Message::operator = (const Message &)
#endif // SNACC_DEEP_COPY
{
#if SNACC_DEEP_COPY
  if (this != &that)
  {
    version = that.version;
    community = that.community;
    if (that.data)
    {
      if (!data)
        data = new PDUs;
      *data = *that.data;
    }
    else
    {
      delete data;
      data = NULL;
    }
  }

  return *this;
#else // SNACC_DEEP_COPY
  Asn1Error << "use of incompletely defined Message &Message::operator = (const Message &)" << endl;
  abort();
  // if your compiler complains here, check the -novolat option
#endif // SNACC_DEEP_COPY
}

AsnLen
Message::BEncContent (BUF_TYPE b)
{
  AsnLen totalLen = 0;
  AsnLen l;

    l = data->BEncContent (b);
    totalLen += l;

    l = community.BEncContent (b);
    l += BEncDefLen (b, l);

    l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
    totalLen += l;

    l = version.BEncContent (b);
    BEncDefLenTo127 (b, l);
    l++;

    l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
    totalLen += l;

  return totalLen;
} // Message::BEncContent


void Message::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
{
  AsnTag tag1;
  AsnLen seqBytesDecoded = 0;
  AsnLen elmtLen1;
  tag1 = BDecTag (b, seqBytesDecoded, env);

  if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
    tag1 = BDecTag (b, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -125);
  }

  if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
    || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    community.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
    tag1 = BDecTag (b, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -126);
  }

  if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 0))
    || (tag1 == MAKE_TAG_ID (CNTX, CONS, 1))
    || (tag1 == MAKE_TAG_ID (CNTX, CONS, 2))
    || (tag1 == MAKE_TAG_ID (CNTX, CONS, 3))
    || (tag1 == MAKE_TAG_ID (CNTX, CONS, 4)))
  {
    elmtLen1 = BDecLen (b, seqBytesDecoded, env);
    data = new PDUs;
    data->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
  }
  else
  {
    Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
    longjmp (env, -127);
  }

  bytesDecoded += seqBytesDecoded;
  if (elmtLen0 == INDEFINITE_LEN)
  {
    BDecEoc (b, bytesDecoded, env);
    return;
  }
  else if (seqBytesDecoded != elmtLen0)
  {
    Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
    longjmp (env, -128);
  }
  else
    return;
} // Message::BDecContent

AsnLen Message::BEnc (BUF_TYPE b)
{
  AsnLen l;
  l = BEncContent (b);
  l += BEncConsLen (b, l);
  l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
  return l;
}

void Message::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
{
  AsnTag tag;
  AsnLen elmtLen1;

  if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
  {
    Asn1Error << "Message::BDec: ERROR - wrong tag" << endl;
    longjmp (env, -129);
  }
  elmtLen1 = BDecLen (b, bytesDecoded, env);
  BDecContent (b, tag, elmtLen1, bytesDecoded, env);
}

int Message::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
{
    bytesEncoded = BEnc (b);
    return !b.WriteError();
}

int Message::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
{
    ENV_TYPE env;
    int val;

    bytesDecoded = 0;
    if ((val = setjmp (env)) == 0)
    {
         BDec (b, bytesDecoded, env);
         return !b.ReadError();
    }
    else
        return false;
}

void Message::Print (ostream &os) const
{
  os << "{ -- SEQUENCE --" << endl;
  indentG += stdIndentG;

  {
    Indent (os, indentG);
    os << "version ";
    os << version;
    os << "," << endl;
  }

  {
    Indent (os, indentG);
    os << "community ";
    os << community;
    os << "," << endl;
  }

  if (NOT_NULL (data))
  {
    Indent (os, indentG);
    os << "data ";
    os << *data;
  }
  else
  {
    Indent (os, indentG);
    os << "data ";
    os << "-- void --";
    os << endl;
  }

  os << endl;
  indentG -= stdIndentG;
  Indent (os, indentG);
  os << "}";
} // Message::Print


