/* automatically generated by pepy 7.0 #3 (wk87), do not edit! */

#include <isode/psap.h>

static char *pepyid = "pepy 7.0 #3 (wk87) of Fri Jul 26 17:16:06 PDT 1991";

void	advise ();

/* Generated from module SNMP */
# line 5 "gen/SNMP-types.py"

#include <stdio.h>
#include "SNMP-types.h"

#ifndef PEPYPARM
#define PEPYPARM char *
#endif /* PEPYPARM */
extern PEPYPARM NullParm;

/* ARGSUSED */

int	encode_SNMP_Message (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_Message * parm;
{
    PE	p0_z = NULLPE;
    register PE *p0 = &p0_z;

    if (((*pe) = pe_alloc (PE_CLASS_UNIV, PE_FORM_CONS, PE_CONS_SEQ)) == NULLPE) {
        advise (NULLCP, "Message: %s", PEPY_ERR_NOMEM);
        return NOTOK;
    }
    {
# line 19 "gen/SNMP-types.py"

            
    }
    (*p0) = NULLPE;

    {	/* version */
        register integer p1 = parm -> version ;

        if (((*p0) = num2prim (p1, PE_CLASS_UNIV, PE_PRIM_INT)) == NULLPE) {
            advise (NULLCP, "version: %s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
        switch (p1) {
            case 0:	/* version-1 */
                break;
        }

#ifdef DEBUG
        (void) testdebug ((*p0), "version");
#endif

    }

    if ((*p0) != NULLPE)
        if (seq_add ((*pe), (*p0), -1) == NOTOK) {
            advise (NULLCP, "Message %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }
    (*p0) = NULLPE;

    {	/* community */
        register struct qbuf *p2;

        p2 = parm -> community ;
        if (p2 == ((struct qbuf *) 0)) {
            advise (NULLCP, "community %s", PEPY_ERR_INIT_FAILED);
            return NOTOK;
        }
        if (((*p0) = qb2prim (p2, PE_CLASS_UNIV, PE_PRIM_OCTS)) == NULLPE) {
            advise (NULLCP, "community: %s", PEPY_ERR_NOMEM);
            return NOTOK;
        }

#ifdef DEBUG
        (void) testdebug ((*p0), "community");
#endif

    }

    if ((*p0) != NULLPE)
        if (seq_add ((*pe), (*p0), -1) == NOTOK) {
            advise (NULLCP, "Message %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }
    (*p0) = NULLPE;

    {	/* data */
        if (encode_SNMP_PDUs (p0, 0, NULL, NULLCP, parm -> data ) == NOTOK)
            return NOTOK;

#ifdef DEBUG
        (void) testdebug ((*p0), "data");
#endif

    }

    if ((*p0) != NULLPE)
        if (seq_add ((*pe), (*p0), -1) == NOTOK) {
            advise (NULLCP, "Message %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.Message");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_PDUs (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_PDUs * parm;
{
    int	p3;

    switch (p3 = (parm -> offset)) {
        case 1:	/* get-request */
            {
                if (encode_SNMP_GetRequest__PDU (pe, 0, NULL, NULLCP, parm -> un.get__request ) == NOTOK)
                    return NOTOK;

#ifdef DEBUG
                (void) testdebug ((*pe), "get-request");
#endif

            }
            break;
        case 2:	/* get-next-request */
            {
                if (encode_SNMP_GetNextRequest__PDU (pe, 0, NULL, NULLCP, parm -> un.get__next__request ) == NOTOK)
                    return NOTOK;

#ifdef DEBUG
                (void) testdebug ((*pe), "get-next-request");
#endif

            }
            break;
        case 3:	/* get-response */
            {
                if (encode_SNMP_GetResponse__PDU (pe, 0, NULL, NULLCP, parm -> un.get__response ) == NOTOK)
                    return NOTOK;

#ifdef DEBUG
                (void) testdebug ((*pe), "get-response");
#endif

            }
            break;
        case 4:	/* set-request */
            {
                if (encode_SNMP_SetRequest__PDU (pe, 0, NULL, NULLCP, parm -> un.set__request ) == NOTOK)
                    return NOTOK;

#ifdef DEBUG
                (void) testdebug ((*pe), "set-request");
#endif

            }
            break;
        case 5:	/* trap */
            {
                if (encode_SNMP_Trap__PDU (pe, 0, NULL, NULLCP, parm -> un.trap ) == NOTOK)
                    return NOTOK;

#ifdef DEBUG
                (void) testdebug ((*pe), "trap");
#endif

            }
            break;

        default:
            advise (NULLCP, "PDUs %s%d", PEPY_ERR_INVALID_CHOICE, 
                    p3);
            return NOTOK;
    }

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.PDUs");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_GetRequest__PDU (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_GetRequest__PDU * parm;
{
    if (encode_SNMP_PDU (pe, 0, len, buffer, parm ) == NOTOK)
        return NOTOK;
    (*pe) -> pe_class = PE_CLASS_CONT;
    (*pe) -> pe_id = 0;

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.GetRequest-PDU");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_GetNextRequest__PDU (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_GetNextRequest__PDU * parm;
{
    if (encode_SNMP_PDU (pe, 0, len, buffer, parm ) == NOTOK)
        return NOTOK;
    (*pe) -> pe_class = PE_CLASS_CONT;
    (*pe) -> pe_id = 1;

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.GetNextRequest-PDU");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_GetResponse__PDU (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_GetResponse__PDU * parm;
{
    if (encode_SNMP_PDU (pe, 0, len, buffer, parm ) == NOTOK)
        return NOTOK;
    (*pe) -> pe_class = PE_CLASS_CONT;
    (*pe) -> pe_id = 2;

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.GetResponse-PDU");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_SetRequest__PDU (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_SetRequest__PDU * parm;
{
    if (encode_SNMP_PDU (pe, 0, len, buffer, parm ) == NOTOK)
        return NOTOK;
    (*pe) -> pe_class = PE_CLASS_CONT;
    (*pe) -> pe_id = 3;

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.SetRequest-PDU");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_PDU (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_PDU * parm;
{
    PE	p4_z = NULLPE;
    register PE *p4 = &p4_z;

    if (((*pe) = pe_alloc (PE_CLASS_UNIV, PE_FORM_CONS, PE_CONS_SEQ)) == NULLPE) {
        advise (NULLCP, "PDU: %s", PEPY_ERR_NOMEM);
        return NOTOK;
    }
    {
# line 83 "gen/SNMP-types.py"

            
    }
    (*p4) = NULLPE;

    {	/* request-id */
        register integer p5 = parm -> request__id ;

        if (((*p4) = num2prim (p5, PE_CLASS_UNIV, PE_PRIM_INT)) == NULLPE) {
            advise (NULLCP, "request-id: %s", PEPY_ERR_NOMEM);
            return NOTOK;
        }

#ifdef DEBUG
        (void) testdebug ((*p4), "request-id");
#endif

    }

    if ((*p4) != NULLPE)
        if (seq_add ((*pe), (*p4), -1) == NOTOK) {
            advise (NULLCP, "PDU %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }
    (*p4) = NULLPE;

    {	/* error-status */
        register integer p6 = parm -> error__status ;

        if (((*p4) = num2prim (p6, PE_CLASS_UNIV, PE_PRIM_INT)) == NULLPE) {
            advise (NULLCP, "error-status: %s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
        switch (p6) {
            case 0:	/* noError */
                break;
            case 1:	/* tooBig */
                break;
            case 2:	/* noSuchName */
                break;
            case 3:	/* badValue */
                break;
            case 4:	/* readOnly */
                break;
            case 5:	/* genErr */
                break;
        }

#ifdef DEBUG
        (void) testdebug ((*p4), "error-status");
#endif

    }

    if ((*p4) != NULLPE)
        if (seq_add ((*pe), (*p4), -1) == NOTOK) {
            advise (NULLCP, "PDU %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }
    (*p4) = NULLPE;

    {	/* error-index */
        register integer p7 = parm -> error__index ;

        if (((*p4) = num2prim (p7, PE_CLASS_UNIV, PE_PRIM_INT)) == NULLPE) {
            advise (NULLCP, "error-index: %s", PEPY_ERR_NOMEM);
            return NOTOK;
        }

#ifdef DEBUG
        (void) testdebug ((*p4), "error-index");
#endif

    }

    if ((*p4) != NULLPE)
        if (seq_add ((*pe), (*p4), -1) == NOTOK) {
            advise (NULLCP, "PDU %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }
    (*p4) = NULLPE;

    {	/* variable-bindings */
        if (encode_SNMP_VarBindList (p4, 0, NULL, NULLCP, parm -> variable__bindings ) == NOTOK)
            return NOTOK;

#ifdef DEBUG
        (void) testdebug ((*p4), "variable-bindings");
#endif

    }

    if ((*p4) != NULLPE)
        if (seq_add ((*pe), (*p4), -1) == NOTOK) {
            advise (NULLCP, "PDU %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.PDU");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_Trap__PDU (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_Trap__PDU * parm;
{
    PE	p8_z = NULLPE;
    register PE *p8 = &p8_z;

    if (((*pe) = pe_alloc (PE_CLASS_CONT, PE_FORM_CONS, 4)) == NULLPE) {
        advise (NULLCP, "Trap-PDU: %s", PEPY_ERR_NOMEM);
        return NOTOK;
    }
    {
# line 114 "gen/SNMP-types.py"

            
    }
    (*p8) = NULLPE;

    {	/* enterprise */
        register OID p9;

        p9 = parm -> enterprise ;
        if (p9 == NULLOID) {
            advise (NULLCP, "enterprise %s", PEPY_ERR_INIT_FAILED);
            return NOTOK;
        }
        if (((*p8) = obj2prim (p9, PE_CLASS_UNIV, PE_PRIM_OID)) == NULLPE) {
            advise (NULLCP, "enterprise: %s", PEPY_ERR_NOMEM);
            return NOTOK;
        }

#ifdef DEBUG
        (void) testdebug ((*p8), "enterprise");
#endif

    }

    if ((*p8) != NULLPE)
        if (seq_add ((*pe), (*p8), -1) == NOTOK) {
            advise (NULLCP, "Trap-PDU %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }
    (*p8) = NULLPE;

    {	/* agent-addr */
        if (encode_SNMP_NetworkAddress (p8, 0, NULL, NULLCP, parm -> agent__addr ) == NOTOK)
            return NOTOK;

#ifdef DEBUG
        (void) testdebug ((*p8), "agent-addr");
#endif

    }

    if ((*p8) != NULLPE)
        if (seq_add ((*pe), (*p8), -1) == NOTOK) {
            advise (NULLCP, "Trap-PDU %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }
    (*p8) = NULLPE;

    {	/* generic-trap */
        register integer p10 = parm -> generic__trap ;

        if (((*p8) = num2prim (p10, PE_CLASS_UNIV, PE_PRIM_INT)) == NULLPE) {
            advise (NULLCP, "generic-trap: %s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
        switch (p10) {
            case 0:	/* coldStart */
                break;
            case 1:	/* warmStart */
                break;
            case 2:	/* linkDown */
                break;
            case 3:	/* linkUp */
                break;
            case 4:	/* authenticationFailure */
                break;
            case 5:	/* egpNeighborLoss */
                break;
            case 6:	/* enterpriseSpecific */
                break;
        }

#ifdef DEBUG
        (void) testdebug ((*p8), "generic-trap");
#endif

    }

    if ((*p8) != NULLPE)
        if (seq_add ((*pe), (*p8), -1) == NOTOK) {
            advise (NULLCP, "Trap-PDU %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }
    (*p8) = NULLPE;

    {	/* specific-trap */
        register integer p11 = parm -> specific__trap ;

        if (((*p8) = num2prim (p11, PE_CLASS_UNIV, PE_PRIM_INT)) == NULLPE) {
            advise (NULLCP, "specific-trap: %s", PEPY_ERR_NOMEM);
            return NOTOK;
        }

#ifdef DEBUG
        (void) testdebug ((*p8), "specific-trap");
#endif

    }

    if ((*p8) != NULLPE)
        if (seq_add ((*pe), (*p8), -1) == NOTOK) {
            advise (NULLCP, "Trap-PDU %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }
    (*p8) = NULLPE;

    {	/* time-stamp */
        if (encode_SNMP_TimeTicks (p8, 0, NULL, NULLCP, parm -> time__stamp ) == NOTOK)
            return NOTOK;

#ifdef DEBUG
        (void) testdebug ((*p8), "time-stamp");
#endif

    }

    if ((*p8) != NULLPE)
        if (seq_add ((*pe), (*p8), -1) == NOTOK) {
            advise (NULLCP, "Trap-PDU %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }
    (*p8) = NULLPE;

    {	/* variable-bindings */
        if (encode_SNMP_VarBindList (p8, 0, NULL, NULLCP, parm -> variable__bindings ) == NOTOK)
            return NOTOK;

#ifdef DEBUG
        (void) testdebug ((*p8), "variable-bindings");
#endif

    }

    if ((*p8) != NULLPE)
        if (seq_add ((*pe), (*p8), -1) == NOTOK) {
            advise (NULLCP, "Trap-PDU %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.Trap-PDU");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_VarBind (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_VarBind * parm;
{
    PE	p12_z = NULLPE;
    register PE *p12 = &p12_z;

    if (((*pe) = pe_alloc (PE_CLASS_UNIV, PE_FORM_CONS, PE_CONS_SEQ)) == NULLPE) {
        advise (NULLCP, "VarBind: %s", PEPY_ERR_NOMEM);
        return NOTOK;
    }
    {
# line 153 "gen/SNMP-types.py"

            
    }
    (*p12) = NULLPE;

    {	/* name */
        if (encode_SNMP_ObjectName (p12, 0, NULL, NULLCP, parm -> name ) == NOTOK)
            return NOTOK;

#ifdef DEBUG
        (void) testdebug ((*p12), "name");
#endif

    }

    if ((*p12) != NULLPE)
        if (seq_add ((*pe), (*p12), -1) == NOTOK) {
            advise (NULLCP, "VarBind %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }
    (*p12) = NULLPE;

    {	/* value */
        if (encode_SNMP_ObjectSyntax (p12, 0, NULL, NULLCP, parm -> value ) == NOTOK)
            return NOTOK;

#ifdef DEBUG
        (void) testdebug ((*p12), "value");
#endif

    }

    if ((*p12) != NULLPE)
        if (seq_add ((*pe), (*p12), -1) == NOTOK) {
            advise (NULLCP, "VarBind %s%s", PEPY_ERR_BAD_SEQ,
                    pe_error ((*pe) -> pe_errno));
            return NOTOK;
        }

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.VarBind");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_VarBindList (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_VarBindList * parm;
{
    PE	p13 = NULLPE;
    PE	p14_z = NULLPE;
    register PE *p14 = &p14_z;

    if (((*pe) = pe_alloc (PE_CLASS_UNIV, PE_FORM_CONS, PE_CONS_SEQ)) == NULLPE) {
        advise (NULLCP, "VarBindList: %s", PEPY_ERR_NOMEM);
        return NOTOK;
    }
    for (; parm; parm = parm -> next) {
        if (encode_SNMP_VarBind (p14, 0, NULL, NULLCP, parm -> VarBind ) == NOTOK)
            return NOTOK;

#ifdef DEBUG
        (void) testdebug ((*p14), "element");
#endif

        seq_addon ((*pe), p13, (*p14));
        p13 = (*p14);
    }

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.VarBindList");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_ObjectName (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_ObjectName * parm;
{
    register OID p15;

    p15 = parm ;
    if (p15 == NULLOID) {
        advise (NULLCP, "ObjectName %s", PEPY_ERR_INIT_FAILED);
        return NOTOK;
    }
    if (((*pe) = obj2prim (p15, PE_CLASS_UNIV, PE_PRIM_OID)) == NULLPE) {
        advise (NULLCP, "ObjectName: %s", PEPY_ERR_NOMEM);
        return NOTOK;
    }

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.ObjectName");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_ObjectSyntax (pe, explicit, len, buffer, parm)
PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_ObjectSyntax * parm;
{
    PE	p16 = parm ;

    if (p16 == NULLPE) {
        advise (NULLCP, "ObjectSyntax %s", PEPY_ERR_INIT_FAILED);
        return NOTOK;
    }
    ((*pe) = p16) -> pe_refcnt++;

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.ObjectSyntax");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_NetworkAddress (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_NetworkAddress * parm;
{
    int	p17;

    switch (p17 = (1)) {
        case 1:	/* internet */
            {
                if (encode_SNMP_IpAddress (pe, 0, NULL, NULLCP, parm ) == NOTOK)
                    return NOTOK;

#ifdef DEBUG
                (void) testdebug ((*pe), "internet");
#endif

            }
            break;

        default:
            advise (NULLCP, "NetworkAddress %s%d", PEPY_ERR_INVALID_CHOICE, 
                    p17);
            return NOTOK;
    }

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.NetworkAddress");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_IpAddress (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_IpAddress * parm;
{
    register struct qbuf *p18;

    p18 = parm ;
    if (p18 == ((struct qbuf *) 0)) {
        advise (NULLCP, "IpAddress %s", PEPY_ERR_INIT_FAILED);
        return NOTOK;
    }
    if (((*pe) = qb2prim (p18, PE_CLASS_APPL, 0)) == NULLPE) {
        advise (NULLCP, "IpAddress: %s", PEPY_ERR_NOMEM);
        return NOTOK;
    }

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.IpAddress");
#endif


    return OK;
}

/* ARGSUSED */

int	encode_SNMP_TimeTicks (pe, explicit, len, buffer, parm)
register PE     *pe;
int	explicit;
int	len;
char   *buffer;
struct type_SNMP_TimeTicks * parm;
{
    register integer p19 = parm -> parm ;

    if (((*pe) = num2prim (p19, PE_CLASS_APPL, 3)) == NULLPE) {
        advise (NULLCP, "TimeTicks: %s", PEPY_ERR_NOMEM);
        return NOTOK;
    }

#ifdef DEBUG
    (void) testdebug ((*pe), "SNMP.TimeTicks");
#endif


    return OK;
}

/* ARGSUSED */

int	decode_SNMP_Message (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_Message ** parm;
{
    register PE p20;

#ifdef DEBUG
    (void) testdebug (pe, "SNMP.Message");
#endif

    if (explicit) {
        if (pe -> pe_class != PE_CLASS_UNIV
                || pe -> pe_form != PE_FORM_CONS
                || pe -> pe_id != PE_CONS_SEQ) {
            advise (NULLCP, "Message bad class/form/id: %s/%d/0x%x",
                    pe_classlist[pe -> pe_class], pe -> pe_form, pe -> pe_id);
            return NOTOK;
        }
    }
    else
        if (pe -> pe_form != PE_FORM_CONS) {
            advise (NULLCP, "Message bad form: %d", pe -> pe_form);
            return NOTOK;
        }

    {
# line 199 "gen/SNMP-types.py"

        if ((*(parm) = (struct type_SNMP_Message *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_Message *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    
    }
    {
# line 207 "gen/SNMP-types.py"

            
    }
    if ((p20 = prim2seq (pe)) == NULLPE) {
        advise (NULLCP, "Message %s%s", PEPY_ERR_BAD_SEQ,
                pe_error (pe -> pe_errno));
        return NOTOK;
    }
    pe = p20;

    {
        register PE p21;

        if ((p21 = first_member (pe)) != NULLPE) {
            p20 = p21;

            {	/* version */
                register integer p22;

#ifdef DEBUG
                (void) testdebug (p21, "version");
#endif

                if (p21 -> pe_class != PE_CLASS_UNIV
                        || p21 -> pe_form != PE_FORM_PRIM
                        || p21 -> pe_id != PE_PRIM_INT) {
                    advise (NULLCP, "version bad class/form/id: %s/%d/0x%x",
                            pe_classlist[p21 -> pe_class], p21 -> pe_form, p21 -> pe_id);
                    return NOTOK;
                }

                if ((p22 = prim2num (p21)) == NOTOK
                        && p21 -> pe_errno != PE_ERR_NONE) {
                    advise (NULLCP, "version %s%s", PEPY_ERR_BAD_INTEGER,
                            pe_error (p21 -> pe_errno));
                    return NOTOK;
                }
                (*parm) -> version  = p22;
                switch (p22) {
                    case 0:	/* version-1 */
                        break;
                }
            }
        }
        else {
            advise (NULLCP, "Message %sversion element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p23;

        if ((p23 = (pe != p20 ? next_member (pe, p20) : first_member (pe))) != NULLPE) {
            p20 = p23;

            {	/* community */
                register struct qbuf *p24;

#ifdef DEBUG
                (void) testdebug (p23, "community");
#endif

                if (p23 -> pe_class != PE_CLASS_UNIV || p23 -> pe_id != PE_PRIM_OCTS) {
                    advise (NULLCP, "community bad class/form/id: %s/%d/0x%x",
                            pe_classlist[p23 -> pe_class], p23 -> pe_form, p23 -> pe_id);
                    return NOTOK;
                }

                if ((p24 = prim2qb (p23)) == (struct qbuf *)0) {
                    advise (NULLCP, "community %s%s", PEPY_ERR_BAD_OCTET,
                            pe_error (p23 -> pe_errno));
                    return NOTOK;
                }
                (*parm) -> community  = p24;
            }
        }
        else {
            advise (NULLCP, "Message %scommunity element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p25;

        if ((p25 = (pe != p20 ? next_member (pe, p20) : first_member (pe))) != NULLPE) {
            p20 = p25;

            {	/* data */
#ifdef DEBUG
                (void) testdebug (p25, "data");
#endif

                if (decode_SNMP_PDUs (p25, 1, NULLIP, NULLVP, &((*parm) -> data)) == NOTOK)
                    return NOTOK;
            }
        }
        else {
            advise (NULLCP, "Message %sdata element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }


    if (pe -> pe_cardinal > 3) {
        advise (NULLCP, "Message %s(3): %d", PEPY_ERR_TOO_MANY_ELEMENTS,
                pe -> pe_cardinal);
        return NOTOK;
    }

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_PDUs (pe, explicit, len, buffer, parm)
PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_PDUs ** parm;
{
#ifdef DEBUG
    (void) testdebug (pe, "SNMP.PDUs");
#endif

    {
# line 227 "gen/SNMP-types.py"

        if ((*(parm) = (struct type_SNMP_PDUs *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_PDUs *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    
    }
    switch (PE_ID (pe -> pe_class, pe -> pe_id)) {
        case PE_ID (PE_CLASS_CONT, 0):	/* get-request */
            {
#ifdef DEBUG
                (void) testdebug (pe, "get-request");
#endif

                if (decode_SNMP_GetRequest__PDU (pe, 1, NULLIP, NULLVP, &((*parm) -> un.get__request)) == NOTOK)
                    return NOTOK;
                {
# line 239 "gen/SNMP-types.py"
 (*(parm)) -> offset = type_SNMP_PDUs_get__request; 
                }
            }
            break;
        case PE_ID (PE_CLASS_CONT, 1):	/* get-next-request */
            {
#ifdef DEBUG
                (void) testdebug (pe, "get-next-request");
#endif

                if (decode_SNMP_GetNextRequest__PDU (pe, 1, NULLIP, NULLVP, &((*parm) -> un.get__next__request)) == NOTOK)
                    return NOTOK;
                {
# line 244 "gen/SNMP-types.py"
 (*(parm)) -> offset = type_SNMP_PDUs_get__next__request; 
                }
            }
            break;
        case PE_ID (PE_CLASS_CONT, 2):	/* get-response */
            {
#ifdef DEBUG
                (void) testdebug (pe, "get-response");
#endif

                if (decode_SNMP_GetResponse__PDU (pe, 1, NULLIP, NULLVP, &((*parm) -> un.get__response)) == NOTOK)
                    return NOTOK;
                {
# line 249 "gen/SNMP-types.py"
 (*(parm)) -> offset = type_SNMP_PDUs_get__response; 
                }
            }
            break;
        case PE_ID (PE_CLASS_CONT, 3):	/* set-request */
            {
#ifdef DEBUG
                (void) testdebug (pe, "set-request");
#endif

                if (decode_SNMP_SetRequest__PDU (pe, 1, NULLIP, NULLVP, &((*parm) -> un.set__request)) == NOTOK)
                    return NOTOK;
                {
# line 254 "gen/SNMP-types.py"
 (*(parm)) -> offset = type_SNMP_PDUs_set__request; 
                }
            }
            break;
        case PE_ID (PE_CLASS_CONT, 4):	/* trap */
            {
#ifdef DEBUG
                (void) testdebug (pe, "trap");
#endif

                if (decode_SNMP_Trap__PDU (pe, 1, NULLIP, NULLVP, &((*parm) -> un.trap)) == NOTOK)
                    return NOTOK;
                {
# line 259 "gen/SNMP-types.py"
 (*(parm)) -> offset = type_SNMP_PDUs_trap; 
                }
            }
            break;

        default:
            advise (NULLCP, "PDUs %s%s/%d/0x%x", PEPY_ERR_UNKNOWN_CHOICE,
                    pe_classlist[pe -> pe_class], pe -> pe_form, pe -> pe_id);
            return NOTOK;
    }

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_GetRequest__PDU (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_GetRequest__PDU ** parm;
{
#ifdef DEBUG
    (void) testdebug (pe, "SNMP.GetRequest-PDU");
#endif

    if (explicit
            && PE_ID (pe -> pe_class, pe -> pe_id)
                    != PE_ID (PE_CLASS_CONT, 0)) {
        advise (NULLCP, "GetRequest-PDU %s%s/0x%x", PEPY_ERR_BAD_CLASS,
                pe_classlist[pe -> pe_class], pe -> pe_id);
        return NOTOK;
    }
    if (decode_SNMP_PDU (pe, 0, len, buffer, &((*parm))) == NOTOK)
        return NOTOK;

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_GetNextRequest__PDU (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_GetNextRequest__PDU ** parm;
{
#ifdef DEBUG
    (void) testdebug (pe, "SNMP.GetNextRequest-PDU");
#endif

    if (explicit
            && PE_ID (pe -> pe_class, pe -> pe_id)
                    != PE_ID (PE_CLASS_CONT, 1)) {
        advise (NULLCP, "GetNextRequest-PDU %s%s/0x%x", PEPY_ERR_BAD_CLASS,
                pe_classlist[pe -> pe_class], pe -> pe_id);
        return NOTOK;
    }
    if (decode_SNMP_PDU (pe, 0, len, buffer, &((*parm))) == NOTOK)
        return NOTOK;

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_GetResponse__PDU (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_GetResponse__PDU ** parm;
{
#ifdef DEBUG
    (void) testdebug (pe, "SNMP.GetResponse-PDU");
#endif

    if (explicit
            && PE_ID (pe -> pe_class, pe -> pe_id)
                    != PE_ID (PE_CLASS_CONT, 2)) {
        advise (NULLCP, "GetResponse-PDU %s%s/0x%x", PEPY_ERR_BAD_CLASS,
                pe_classlist[pe -> pe_class], pe -> pe_id);
        return NOTOK;
    }
    if (decode_SNMP_PDU (pe, 0, len, buffer, &((*parm))) == NOTOK)
        return NOTOK;

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_SetRequest__PDU (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_SetRequest__PDU ** parm;
{
#ifdef DEBUG
    (void) testdebug (pe, "SNMP.SetRequest-PDU");
#endif

    if (explicit
            && PE_ID (pe -> pe_class, pe -> pe_id)
                    != PE_ID (PE_CLASS_CONT, 3)) {
        advise (NULLCP, "SetRequest-PDU %s%s/0x%x", PEPY_ERR_BAD_CLASS,
                pe_classlist[pe -> pe_class], pe -> pe_id);
        return NOTOK;
    }
    if (decode_SNMP_PDU (pe, 0, len, buffer, &((*parm))) == NOTOK)
        return NOTOK;

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_PDU (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_PDU ** parm;
{
    register PE p26;

#ifdef DEBUG
    (void) testdebug (pe, "SNMP.PDU");
#endif

    if (explicit) {
        if (pe -> pe_class != PE_CLASS_UNIV
                || pe -> pe_form != PE_FORM_CONS
                || pe -> pe_id != PE_CONS_SEQ) {
            advise (NULLCP, "PDU bad class/form/id: %s/%d/0x%x",
                    pe_classlist[pe -> pe_class], pe -> pe_form, pe -> pe_id);
            return NOTOK;
        }
    }
    else
        if (pe -> pe_form != PE_FORM_CONS) {
            advise (NULLCP, "PDU bad form: %d", pe -> pe_form);
            return NOTOK;
        }

    {
# line 283 "gen/SNMP-types.py"

        if ((*(parm) = (struct type_SNMP_PDU *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_PDU *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    
    }
    {
# line 291 "gen/SNMP-types.py"

            
    }
    if ((p26 = prim2seq (pe)) == NULLPE) {
        advise (NULLCP, "PDU %s%s", PEPY_ERR_BAD_SEQ,
                pe_error (pe -> pe_errno));
        return NOTOK;
    }
    pe = p26;

    {
        register PE p27;

        if ((p27 = first_member (pe)) != NULLPE) {
            p26 = p27;

            {	/* request-id */
                register integer p28;

#ifdef DEBUG
                (void) testdebug (p27, "request-id");
#endif

                if (p27 -> pe_class != PE_CLASS_UNIV
                        || p27 -> pe_form != PE_FORM_PRIM
                        || p27 -> pe_id != PE_PRIM_INT) {
                    advise (NULLCP, "request-id bad class/form/id: %s/%d/0x%x",
                            pe_classlist[p27 -> pe_class], p27 -> pe_form, p27 -> pe_id);
                    return NOTOK;
                }

                if ((p28 = prim2num (p27)) == NOTOK
                        && p27 -> pe_errno != PE_ERR_NONE) {
                    advise (NULLCP, "request-id %s%s", PEPY_ERR_BAD_INTEGER,
                            pe_error (p27 -> pe_errno));
                    return NOTOK;
                }
                (*parm) -> request__id  = p28;
            }
        }
        else {
            advise (NULLCP, "PDU %srequest-id element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p29;

        if ((p29 = (pe != p26 ? next_member (pe, p26) : first_member (pe))) != NULLPE) {
            p26 = p29;

            {	/* error-status */
                register integer p30;

#ifdef DEBUG
                (void) testdebug (p29, "error-status");
#endif

                if (p29 -> pe_class != PE_CLASS_UNIV
                        || p29 -> pe_form != PE_FORM_PRIM
                        || p29 -> pe_id != PE_PRIM_INT) {
                    advise (NULLCP, "error-status bad class/form/id: %s/%d/0x%x",
                            pe_classlist[p29 -> pe_class], p29 -> pe_form, p29 -> pe_id);
                    return NOTOK;
                }

                if ((p30 = prim2num (p29)) == NOTOK
                        && p29 -> pe_errno != PE_ERR_NONE) {
                    advise (NULLCP, "error-status %s%s", PEPY_ERR_BAD_INTEGER,
                            pe_error (p29 -> pe_errno));
                    return NOTOK;
                }
                (*parm) -> error__status  = p30;
                switch (p30) {
                    case 0:	/* noError */
                        break;
                    case 1:	/* tooBig */
                        break;
                    case 2:	/* noSuchName */
                        break;
                    case 3:	/* badValue */
                        break;
                    case 4:	/* readOnly */
                        break;
                    case 5:	/* genErr */
                        break;
                }
            }
        }
        else {
            advise (NULLCP, "PDU %serror-status element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p31;

        if ((p31 = (pe != p26 ? next_member (pe, p26) : first_member (pe))) != NULLPE) {
            p26 = p31;

            {	/* error-index */
                register integer p32;

#ifdef DEBUG
                (void) testdebug (p31, "error-index");
#endif

                if (p31 -> pe_class != PE_CLASS_UNIV
                        || p31 -> pe_form != PE_FORM_PRIM
                        || p31 -> pe_id != PE_PRIM_INT) {
                    advise (NULLCP, "error-index bad class/form/id: %s/%d/0x%x",
                            pe_classlist[p31 -> pe_class], p31 -> pe_form, p31 -> pe_id);
                    return NOTOK;
                }

                if ((p32 = prim2num (p31)) == NOTOK
                        && p31 -> pe_errno != PE_ERR_NONE) {
                    advise (NULLCP, "error-index %s%s", PEPY_ERR_BAD_INTEGER,
                            pe_error (p31 -> pe_errno));
                    return NOTOK;
                }
                (*parm) -> error__index  = p32;
            }
        }
        else {
            advise (NULLCP, "PDU %serror-index element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p33;

        if ((p33 = (pe != p26 ? next_member (pe, p26) : first_member (pe))) != NULLPE) {
            p26 = p33;

            {	/* variable-bindings */
#ifdef DEBUG
                (void) testdebug (p33, "variable-bindings");
#endif

                if (decode_SNMP_VarBindList (p33, 1, NULLIP, NULLVP, &((*parm) -> variable__bindings)) == NOTOK)
                    return NOTOK;
            }
        }
        else {
            advise (NULLCP, "PDU %svariable-bindings element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }


    if (pe -> pe_cardinal > 4) {
        advise (NULLCP, "PDU %s(4): %d", PEPY_ERR_TOO_MANY_ELEMENTS,
                pe -> pe_cardinal);
        return NOTOK;
    }

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_Trap__PDU (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_Trap__PDU ** parm;
{
    register PE p34;

#ifdef DEBUG
    (void) testdebug (pe, "SNMP.Trap-PDU");
#endif

    if (explicit
            && PE_ID (pe -> pe_class, pe -> pe_id)
                    != PE_ID (PE_CLASS_CONT, 4)) {
        advise (NULLCP, "Trap-PDU %s%s/0x%x", PEPY_ERR_BAD_CLASS,
                pe_classlist[pe -> pe_class], pe -> pe_id);
        return NOTOK;
    }
    {
# line 320 "gen/SNMP-types.py"

        if ((*(parm) = (struct type_SNMP_Trap__PDU *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_Trap__PDU *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    
    }
    {
# line 329 "gen/SNMP-types.py"

            
    }
    if ((p34 = prim2seq (pe)) == NULLPE) {
        advise (NULLCP, "Trap-PDU %s%s", PEPY_ERR_BAD_SEQ,
                pe_error (pe -> pe_errno));
        return NOTOK;
    }
    pe = p34;

    {
        register PE p35;

        if ((p35 = first_member (pe)) != NULLPE) {
            p34 = p35;

            {	/* enterprise */
                register OID p36;

#ifdef DEBUG
                (void) testdebug (p35, "enterprise");
#endif

                if (p35 -> pe_class != PE_CLASS_UNIV
                        || p35 -> pe_form != PE_FORM_PRIM
                        || p35 -> pe_id != PE_PRIM_OID) {
                    advise (NULLCP, "enterprise bad class/form/id: %s/%d/0x%x",
                            pe_classlist[p35 -> pe_class], p35 -> pe_form, p35 -> pe_id);
                    return NOTOK;
                }

                if ((p36 = prim2oid (p35)) == NULLOID) {
                    advise (NULLCP, "enterprise %s%s", PEPY_ERR_BAD_OID,
                            pe_error (p35 -> pe_errno));
                    return NOTOK;
                }
                (*parm) -> enterprise  = oid_cpy (p36);
            }
        }
        else {
            advise (NULLCP, "Trap-PDU %senterprise element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p37;

        if ((p37 = (pe != p34 ? next_member (pe, p34) : first_member (pe))) != NULLPE) {
            p34 = p37;

            {	/* agent-addr */
#ifdef DEBUG
                (void) testdebug (p37, "agent-addr");
#endif

                if (decode_SNMP_NetworkAddress (p37, 1, NULLIP, NULLVP, &((*parm) -> agent__addr)) == NOTOK)
                    return NOTOK;
            }
        }
        else {
            advise (NULLCP, "Trap-PDU %sagent-addr element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p38;

        if ((p38 = (pe != p34 ? next_member (pe, p34) : first_member (pe))) != NULLPE) {
            p34 = p38;

            {	/* generic-trap */
                register integer p39;

#ifdef DEBUG
                (void) testdebug (p38, "generic-trap");
#endif

                if (p38 -> pe_class != PE_CLASS_UNIV
                        || p38 -> pe_form != PE_FORM_PRIM
                        || p38 -> pe_id != PE_PRIM_INT) {
                    advise (NULLCP, "generic-trap bad class/form/id: %s/%d/0x%x",
                            pe_classlist[p38 -> pe_class], p38 -> pe_form, p38 -> pe_id);
                    return NOTOK;
                }

                if ((p39 = prim2num (p38)) == NOTOK
                        && p38 -> pe_errno != PE_ERR_NONE) {
                    advise (NULLCP, "generic-trap %s%s", PEPY_ERR_BAD_INTEGER,
                            pe_error (p38 -> pe_errno));
                    return NOTOK;
                }
                (*parm) -> generic__trap  = p39;
                switch (p39) {
                    case 0:	/* coldStart */
                        break;
                    case 1:	/* warmStart */
                        break;
                    case 2:	/* linkDown */
                        break;
                    case 3:	/* linkUp */
                        break;
                    case 4:	/* authenticationFailure */
                        break;
                    case 5:	/* egpNeighborLoss */
                        break;
                    case 6:	/* enterpriseSpecific */
                        break;
                }
            }
        }
        else {
            advise (NULLCP, "Trap-PDU %sgeneric-trap element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p40;

        if ((p40 = (pe != p34 ? next_member (pe, p34) : first_member (pe))) != NULLPE) {
            p34 = p40;

            {	/* specific-trap */
                register integer p41;

#ifdef DEBUG
                (void) testdebug (p40, "specific-trap");
#endif

                if (p40 -> pe_class != PE_CLASS_UNIV
                        || p40 -> pe_form != PE_FORM_PRIM
                        || p40 -> pe_id != PE_PRIM_INT) {
                    advise (NULLCP, "specific-trap bad class/form/id: %s/%d/0x%x",
                            pe_classlist[p40 -> pe_class], p40 -> pe_form, p40 -> pe_id);
                    return NOTOK;
                }

                if ((p41 = prim2num (p40)) == NOTOK
                        && p40 -> pe_errno != PE_ERR_NONE) {
                    advise (NULLCP, "specific-trap %s%s", PEPY_ERR_BAD_INTEGER,
                            pe_error (p40 -> pe_errno));
                    return NOTOK;
                }
                (*parm) -> specific__trap  = p41;
            }
        }
        else {
            advise (NULLCP, "Trap-PDU %sspecific-trap element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p42;

        if ((p42 = (pe != p34 ? next_member (pe, p34) : first_member (pe))) != NULLPE) {
            p34 = p42;

            {	/* time-stamp */
#ifdef DEBUG
                (void) testdebug (p42, "time-stamp");
#endif

                if (decode_SNMP_TimeTicks (p42, 1, NULLIP, NULLVP, &((*parm) -> time__stamp)) == NOTOK)
                    return NOTOK;
            }
        }
        else {
            advise (NULLCP, "Trap-PDU %stime-stamp element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p43;

        if ((p43 = (pe != p34 ? next_member (pe, p34) : first_member (pe))) != NULLPE) {
            p34 = p43;

            {	/* variable-bindings */
#ifdef DEBUG
                (void) testdebug (p43, "variable-bindings");
#endif

                if (decode_SNMP_VarBindList (p43, 1, NULLIP, NULLVP, &((*parm) -> variable__bindings)) == NOTOK)
                    return NOTOK;
            }
        }
        else {
            advise (NULLCP, "Trap-PDU %svariable-bindings element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }


    if (pe -> pe_cardinal > 6) {
        advise (NULLCP, "Trap-PDU %s(6): %d", PEPY_ERR_TOO_MANY_ELEMENTS,
                pe -> pe_cardinal);
        return NOTOK;
    }

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_VarBind (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_VarBind ** parm;
{
    register PE p44;

#ifdef DEBUG
    (void) testdebug (pe, "SNMP.VarBind");
#endif

    if (explicit) {
        if (pe -> pe_class != PE_CLASS_UNIV
                || pe -> pe_form != PE_FORM_CONS
                || pe -> pe_id != PE_CONS_SEQ) {
            advise (NULLCP, "VarBind bad class/form/id: %s/%d/0x%x",
                    pe_classlist[pe -> pe_class], pe -> pe_form, pe -> pe_id);
            return NOTOK;
        }
    }
    else
        if (pe -> pe_form != PE_FORM_CONS) {
            advise (NULLCP, "VarBind bad form: %d", pe -> pe_form);
            return NOTOK;
        }

    {
# line 367 "gen/SNMP-types.py"

        if ((*(parm) = (struct type_SNMP_VarBind *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_VarBind *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    
    }
    {
# line 375 "gen/SNMP-types.py"

            
    }
    if ((p44 = prim2seq (pe)) == NULLPE) {
        advise (NULLCP, "VarBind %s%s", PEPY_ERR_BAD_SEQ,
                pe_error (pe -> pe_errno));
        return NOTOK;
    }
    pe = p44;

    {
        register PE p45;

        if ((p45 = first_member (pe)) != NULLPE) {
            p44 = p45;

            {	/* name */
#ifdef DEBUG
                (void) testdebug (p45, "name");
#endif

                if (decode_SNMP_ObjectName (p45, 1, NULLIP, NULLVP, &((*parm) -> name)) == NOTOK)
                    return NOTOK;
            }
        }
        else {
            advise (NULLCP, "VarBind %sname element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p46;

        if ((p46 = (pe != p44 ? next_member (pe, p44) : first_member (pe))) != NULLPE) {
            p44 = p46;

            {	/* value */
#ifdef DEBUG
                (void) testdebug (p46, "value");
#endif

                if (decode_SNMP_ObjectSyntax (p46, 1, NULLIP, NULLVP, &((*parm) -> value)) == NOTOK)
                    return NOTOK;
            }
        }
        else {
            advise (NULLCP, "VarBind %svalue element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }


    if (pe -> pe_cardinal > 2) {
        advise (NULLCP, "VarBind %s(2): %d", PEPY_ERR_TOO_MANY_ELEMENTS,
                pe -> pe_cardinal);
        return NOTOK;
    }

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_VarBindList (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_VarBindList ** parm;
{
    register PE p47;

#ifdef DEBUG
    (void) testdebug (pe, "SNMP.VarBindList");
#endif

    if (explicit) {
        if (pe -> pe_class != PE_CLASS_UNIV
                || pe -> pe_form != PE_FORM_CONS
                || pe -> pe_id != PE_CONS_SEQ) {
            advise (NULLCP, "VarBindList bad class/form/id: %s/%d/0x%x",
                    pe_classlist[pe -> pe_class], pe -> pe_form, pe -> pe_id);
            return NOTOK;
        }
    }
    else
        if (pe -> pe_form != PE_FORM_CONS) {
            advise (NULLCP, "VarBindList bad form: %d", pe -> pe_form);
            return NOTOK;
        }

    if ((p47 = prim2seq (pe)) == NULLPE) {
        advise (NULLCP, "VarBindList %s%s", PEPY_ERR_BAD_SEQ,
                pe_error (pe -> pe_errno));
        return NOTOK;
    }
    pe = p47;

    for (p47 = first_member (pe); p47; p47 = next_member (pe, p47)) {
        {
# line 389 "gen/SNMP-types.py"

                if ((*(parm) = (struct type_SNMP_VarBindList *)
                        calloc (1, sizeof **(parm))) == ((struct type_SNMP_VarBindList *) 0)) {
                    advise (NULLCP, "%s", PEPY_ERR_NOMEM);
                    return NOTOK;
                }
            
        }
        {
#ifdef DEBUG
            (void) testdebug (p47, "element");
#endif

            if (decode_SNMP_VarBind (p47, 1, NULLIP, NULLVP, &((*parm) -> VarBind)) == NOTOK)
                return NOTOK;
            {
# line 398 "gen/SNMP-types.py"
 parm = &((*parm) -> next); 
            }
        }
    }

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_ObjectName (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_ObjectName ** parm;
{
    register OID p48;

#ifdef DEBUG
    (void) testdebug (pe, "SNMP.ObjectName");
#endif

    if (explicit) {
        if (pe -> pe_class != PE_CLASS_UNIV
                || pe -> pe_form != PE_FORM_PRIM
                || pe -> pe_id != PE_PRIM_OID) {
            advise (NULLCP, "ObjectName bad class/form/id: %s/%d/0x%x",
                    pe_classlist[pe -> pe_class], pe -> pe_form, pe -> pe_id);
            return NOTOK;
        }
    }
    else
        if (pe -> pe_form != PE_FORM_PRIM) {
            advise (NULLCP, "ObjectName bad form: %d", pe -> pe_form);
            return NOTOK;
        }

    if ((p48 = prim2oid (pe)) == NULLOID) {
        advise (NULLCP, "ObjectName %s%s", PEPY_ERR_BAD_OID,
                pe_error (pe -> pe_errno));
        return NOTOK;
    }
    if (buffer)
        *buffer = sprintoid (p48);
    (*parm)  = oid_cpy (p48);

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_ObjectSyntax (pe, explicit, len, buffer, parm)
PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_ObjectSyntax ** parm;
{
#ifdef DEBUG
    (void) testdebug (pe, "SNMP.ObjectSyntax");
#endif

    ((*parm)  = pe) -> pe_refcnt++;

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_NetworkAddress (pe, explicit, len, buffer, parm)
PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_NetworkAddress ** parm;
{
#ifdef DEBUG
    (void) testdebug (pe, "SNMP.NetworkAddress");
#endif

    switch (PE_ID (pe -> pe_class, pe -> pe_id)) {
        case PE_ID (PE_CLASS_APPL, 0):	/* internet */
            {
#ifdef DEBUG
                (void) testdebug (pe, "internet");
#endif

                if (decode_SNMP_IpAddress (pe, 1, NULLIP, NULLVP, &((*parm))) == NOTOK)
                    return NOTOK;
            }
            break;

        default:
            advise (NULLCP, "NetworkAddress %s%s/%d/0x%x", PEPY_ERR_UNKNOWN_CHOICE,
                    pe_classlist[pe -> pe_class], pe -> pe_form, pe -> pe_id);
            return NOTOK;
    }

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_IpAddress (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_IpAddress ** parm;
{
    register struct qbuf *p49;

#ifdef DEBUG
    (void) testdebug (pe, "SNMP.IpAddress");
#endif

    if (explicit
            && PE_ID (pe -> pe_class, pe -> pe_id)
                    != PE_ID (PE_CLASS_APPL, 0)) {
        advise (NULLCP, "IpAddress %s%s/0x%x", PEPY_ERR_BAD_CLASS,
                pe_classlist[pe -> pe_class], pe -> pe_id);
        return NOTOK;
    }
    if ((p49 = prim2qb (pe)) == (struct qbuf *)0) {
        advise (NULLCP, "IpAddress %s%s", PEPY_ERR_BAD_OCTET,
                pe_error (pe -> pe_errno));
        return NOTOK;
    }
    (*parm)  = p49;

    return OK;
}

/* ARGSUSED */

int	decode_SNMP_TimeTicks (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
struct type_SNMP_TimeTicks ** parm;
{
    register integer p50;

#ifdef DEBUG
    (void) testdebug (pe, "SNMP.TimeTicks");
#endif

    if (explicit
            && PE_ID (pe -> pe_class, pe -> pe_id)
                    != PE_ID (PE_CLASS_APPL, 3)) {
        advise (NULLCP, "TimeTicks %s%s/0x%x", PEPY_ERR_BAD_CLASS,
                pe_classlist[pe -> pe_class], pe -> pe_id);
        return NOTOK;
    }
    {
# line 422 "gen/SNMP-types.py"

        if ((*(parm) = (struct type_SNMP_TimeTicks *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_TimeTicks *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    
    }
    if ((p50 = prim2num (pe)) == NOTOK
            && pe -> pe_errno != PE_ERR_NONE) {
        advise (NULLCP, "TimeTicks %s%s", PEPY_ERR_BAD_INTEGER,
                pe_error (pe -> pe_errno));
        return NOTOK;
    }
    (*parm) -> parm  = p50;
    if (len)
        *len = p50;

    return OK;
}
# line 435 "gen/SNMP-types.py"


free_SNMP_Message (arg)
struct type_SNMP_Message *arg;
{
    struct type_SNMP_Message *parm = arg;

    if (parm == NULL)
	return;

    if (parm -> community)
        qb_free (parm -> community),
            parm -> community = NULL;
    if (parm -> data)
        free_SNMP_PDUs (parm -> data),
            parm -> data = NULL;

    free ((char *) arg);
}

free_SNMP_PDUs (arg)
struct type_SNMP_PDUs *arg;
{
    struct type_SNMP_PDUs *parm = arg;

    if (parm == NULL)
	return;

    switch (parm -> offset) {
        case type_SNMP_PDUs_get__request:
            if (parm -> un.get__request)
                free_SNMP_GetRequest__PDU (parm -> un.get__request),
                    parm -> un.get__request = NULL;
            break;

        case type_SNMP_PDUs_get__next__request:
            if (parm -> un.get__next__request)
                free_SNMP_GetNextRequest__PDU (parm -> un.get__next__request),
                    parm -> un.get__next__request = NULL;
            break;

        case type_SNMP_PDUs_get__response:
            if (parm -> un.get__response)
                free_SNMP_GetResponse__PDU (parm -> un.get__response),
                    parm -> un.get__response = NULL;
            break;

        case type_SNMP_PDUs_set__request:
            if (parm -> un.set__request)
                free_SNMP_SetRequest__PDU (parm -> un.set__request),
                    parm -> un.set__request = NULL;
            break;

        case type_SNMP_PDUs_trap:
            if (parm -> un.trap)
                free_SNMP_Trap__PDU (parm -> un.trap),
                    parm -> un.trap = NULL;
            break;
    }

    free ((char *) arg);
}

free_SNMP_PDU (arg)
struct type_SNMP_PDU *arg;
{
    struct type_SNMP_PDU *parm = arg;

    if (parm == NULL)
	return;

    if (parm -> variable__bindings)
        free_SNMP_VarBindList (parm -> variable__bindings),
            parm -> variable__bindings = NULL;

    free ((char *) arg);
}

free_SNMP_Trap__PDU (arg)
struct type_SNMP_Trap__PDU *arg;
{
    struct type_SNMP_Trap__PDU *parm = arg;

    if (parm == NULL)
	return;

    if (parm -> enterprise)
        oid_free (parm -> enterprise),
            parm -> enterprise = NULLOID;
    if (parm -> agent__addr)
        free_SNMP_NetworkAddress (parm -> agent__addr),
            parm -> agent__addr = NULL;
    if (parm -> time__stamp)
        free_SNMP_TimeTicks (parm -> time__stamp),
            parm -> time__stamp = NULL;
    if (parm -> variable__bindings)
        free_SNMP_VarBindList (parm -> variable__bindings),
            parm -> variable__bindings = NULL;

    free ((char *) arg);
}

free_SNMP_VarBind (arg)
struct type_SNMP_VarBind *arg;
{
    struct type_SNMP_VarBind *parm = arg;

    if (parm == NULL)
	return;

    if (parm -> name)
        free_SNMP_ObjectName (parm -> name),
            parm -> name = NULL;
    if (parm -> value)
        free_SNMP_ObjectSyntax (parm -> value),
            parm -> value = NULL;

    free ((char *) arg);
}

free_SNMP_VarBindList (arg)
struct type_SNMP_VarBindList *arg;
{
    struct type_SNMP_VarBindList *parm = arg;

    if (parm == NULL)
	return;

    for (parm = parm; parm;) {
        struct type_SNMP_VarBindList *f_parm = parm -> next;

        if (parm -> VarBind)
            free_SNMP_VarBind (parm -> VarBind),
                parm -> VarBind = NULL;

        if (parm)
            free ((char *) parm);
        parm = f_parm;
    }

}

free_SNMP_TimeTicks (arg)
struct type_SNMP_TimeTicks *arg;
{
    struct type_SNMP_TimeTicks *parm = arg;

    if (parm == NULL)
	return;


    free ((char *) arg);
}

