📄 gen-enc.c
字号:
switch (ctri->cTypeId) { case C_ANYDEFINEDBY: /* get type of 'defining' field (int/enum/oid)*/ idNamedType = e->type->basicType->a.anyDefinedBy->link; tmpTypeId = GetBuiltinType (idNamedType->type); if (tmpTypeId == BASICTYPE_OID) { MakeVarPtrRef (genEncCRulesG, td, parent, idNamedType->type, varName, idVarRef); fprintf (src, " SetAnyTypeByOid (%s, %s);\n", elmtVarRef, idVarRef); } else { /* want to ref int by value not ptr */ MakeVarValueRef (genEncCRulesG, td, parent, idNamedType->type, varName, idVarRef); fprintf (src, " SetAnyTypeByInt (%s, %s);\n", elmtVarRef, idVarRef); } /* ANY's enc's do tag and len so zap the Content suffix */ fprintf (src, " %s = B%s (b, %s);\n", itemLenNameG, ctri->encodeRoutineName, elmtVarRef); break; case C_TYPEREF: tmpType = GetType (e->type); /* NOTE: ANY DEFINED BY must be directly in the parent (not ref)*/ if (tmpType->cTypeRefInfo->cTypeId != C_ANY) { fprintf (src, " %s = B%sContent (b, %s);\n", itemLenNameG, ctri->encodeRoutineName, elmtVarRef); break; } else /* fall through */ case C_ANY: /* ANY's enc's do tag and len so zap the Content suffix */ fprintf (src," /* ANY - Fix Me! */\n"); fprintf (src, " SetAnyTypeBy???(%s, ???);\n", elmtVarRef); fprintf (src, " %s = B%s (b, %s);\n", itemLenNameG, ctri->encodeRoutineName, elmtVarRef); break; case C_LIB: fprintf (src, " %s = B%sContent (b, %s);\n", itemLenNameG, ctri->encodeRoutineName, elmtVarRef); break; case C_CHOICE: PrintCBerChoiceEncodeCode (src, td, e->type, level+1, elmtVarRef); break; case C_STRUCT: PrintCBerElmtsEncodeCode (src, td, e->type, e->type->basicType->a.set, level+1, elmtVarRef); break; case C_LIST: PrintCBerListEncoderCode (src, td, e->type, level+1, elmtVarRef); fprintf (src, " %s = %s;\n", itemLenNameG, listLenNameG); fprintf (src,"\n\n"); break; case C_NO_TYPE: break; default: fprintf (stderr,"PrintCBerElmtEncodeCode: ERROR - unknown c type id\n"); break; } if (ctri->cTypeId != C_ANY) /* ANY's do their own tag/lens */ { PrintCTagAndLenEncodingCode (src, td, e->type); fprintf (src,"\n %s += %s;\n", encodedLenVarNameG, itemLenNameG); } if (e->type->optional || (e->type->defaultVal != NULL)) fprintf (src, " }\n"); fprintf (src,"\n");} /* PrintCBerElmtEncodeCode *//* * Generates code for internally defined lists * eg: * TypeX = SET { foo INTEGER, bar SEQUENCE OF INTEGER } --> * BerEncodeTypeX (b, v) * { * ... * listLen = 0; * FOR_EACH_LIST_ELMT (component, v->bar) * { * itemLen = BerEncodeInteger (b, (int*) component); * itemLen+= EncodeLen (b, itemLen) * itemLen += ENCODE_TAG (b, INTEGER_TAG); * listLen += itemLen; * } * ... * } */static voidPrintCBerListEncoderCode PARAMS ((src, td, t, level, varName), FILE *src _AND_ TypeDef *td _AND_ Type *t _AND_ int level _AND_ char *varName){ CTRI *ctri; char *elmtVarRef = "component"; Type *tmpType; enum BasicTypeChoiceId tmpTypeId; TypeDef *idNamedType; ctri = t->basicType->a.setOf->cTypeRefInfo; if (ctri == NULL) return; fprintf (src, " listLen = 0;\n"); fprintf (src, " FOR_EACH_LIST_ELMT_RVS (component, %s)\n", varName); fprintf (src, " {\n"); PrintEocEncoders (src, td, t->basicType->a.setOf); /* * need extra case here for SET OF typedef not just SET OF typeref */ switch (ctri->cTypeId) { case C_TYPEREF: tmpType = GetType (t->basicType->a.setOf); /* NOTE: ANY DEFINED BY must be directly in the parent (not ref)*/ if (tmpType->cTypeRefInfo->cTypeId != C_ANY) { fprintf (src, " %s = B%sContent (b, %s);\n", itemLenNameG, ctri->encodeRoutineName, elmtVarRef); break; } else /* fall through */ case C_ANY: /* ANY's enc's do tag and len so zap the Content suffix */ fprintf (src," /* ANY - Fix Me! */\n"); fprintf (src, " SetAnyTypeBy???(%s, ???);\n", elmtVarRef); fprintf (src, " %s = B%s (b, %s);\n", itemLenNameG, ctri->encodeRoutineName, elmtVarRef); break; default: fprintf (src, " %s = B%sContent (b, (%s*) %s);\n", itemLenNameG, ctri->encodeRoutineName, ctri->cTypeName, elmtVarRef); break; } PrintCTagAndLenEncodingCode (src, td, t->basicType->a.setOf); fprintf (src,"\n"); fprintf (src, " %s += %s;\n", listLenNameG, itemLenNameG); fprintf (src, " }\n");} /* PrintCBerListEncoderCode */static voidPrintCBerChoiceEncodeCode PARAMS ((src, td, t, level, varName), FILE *src _AND_ TypeDef *td _AND_ Type *t _AND_ int level _AND_ char *varName){ NamedType *e; CTRI *ctri; void *tmp; ctri = t->cTypeRefInfo; fprintf (src," switch (%s->%s)\n {\n", varName, ctri->choiceIdEnumFieldName); FOR_EACH_LIST_ELMT (e, t->basicType->a.choice) { tmp = (void*)CURR_LIST_NODE (t->basicType->a.choice); if (e->type == NULL) continue; ctri = e->type->cTypeRefInfo; if (ctri != NULL) fprintf (src, " case %s:\n", ctri->choiceIdSymbol); else fprintf (src, " case ????:\n"); PrintCBerElmtEncodeCode (src, td, t, e, level+1, varName); fprintf (src," break;\n\n"); SET_CURR_LIST_NODE (t->basicType->a.choice, tmp); } fprintf (src, " }\n");} /* PrintCBerChoiceEncodeCode *//* * prints DecodeBerEocIfNec (b) for each constructed len * assoc with given type */static voidPrintEocEncoders PARAMS ((src, td, t), FILE *src _AND_ TypeDef *td _AND_ Type *t){ TagList *tl; Tag *tag; int consTagCount; int stoleChoiceTags; /* * get all the tags on this type */ tl = (TagList*) GetTags (t, &stoleChoiceTags); /* * leave choice elmt tag enc to encoding routine */ if (!stoleChoiceTags) { FOR_EACH_LIST_ELMT (tag, tl) { if (tag->form == CONS) fprintf (src," BEncEocIfNec (b);\n"); } }/* consTagCount = 0; if (!stoleChoiceTags) { FOR_EACH_LIST_ELMT (tag, tl) consTagCount++; } if (IsPrimitiveByDefOrRef (t)) consTagCount--; for (; consTagCount > 0; consTagCount--) fprintf (src," BEncEocIfNec (b);\n");*/ FreeTags (tl);} /* PrintEocEncoders *//* * Recursively walks throught type refs printing lower lvl tags * first (since encoding is done backwards). * */static voidPrintCTagAndLenEncodingCode PARAMS ((src, td, t), FILE *src _AND_ TypeDef *td _AND_ Type *t){ TagList *tl; int stoleChoiceTags; /* * get all the tags on this type */ tl = (TagList*) GetTags (t, &stoleChoiceTags); /* * leave choice elmt tag enc to encoding routine */ if (!stoleChoiceTags) PrintCTagAndLenList (src, t, tl); FreeTags (tl);} /* PrintCTagAndLenEncodingCode *//* * prints last tag's encoding code first */static voidPrintCTagAndLenList PARAMS ((src, t, tagList), FILE *src _AND_ Type *t _AND_ TagList *tagList){ char *classStr; char *formStr; char *codeStr; Tag *tg; Tag *last; int tagLen; enum BasicTypeChoiceId typesType; int isShort; if ((tagList == NULL) || LIST_EMPTY (tagList)) return; /* * efficiency hack - use simple length (1 byte) * encoded for type (almost) guaranteed to have * encoded lengths of 0 <= len <= 127 */ typesType = GetBuiltinType (t); if ((typesType == BASICTYPE_BOOLEAN) || (typesType == BASICTYPE_INTEGER) || (typesType == BASICTYPE_NULL) || (typesType == BASICTYPE_REAL) || (typesType == BASICTYPE_ENUMERATED)) isShort = 1; else isShort = 0; /* * since encoding backward encode tags backwards */ last = (Tag*)LAST_LIST_ELMT (tagList); FOR_EACH_LIST_ELMT_RVS (tg, tagList) { classStr = Class2ClassStr (tg->tclass); if (tg->form == CONS) { formStr = Form2FormStr (CONS); PrintCLenEncodingCode (src, TRUE, isShort); } else /* PRIM or ANY_FORM */ { formStr = Form2FormStr (PRIM); PrintCLenEncodingCode (src, FALSE, isShort); }/* GetTags sets the form bit correctly now if (IsPrimitiveByDefOrRef (t) && (tg == last)) { formStr = Form2FormStr (PRIM); PrintCLenEncodingCode (src, FALSE, isShort); } else { formStr = Form2FormStr (CONS); PrintCLenEncodingCode (src, TRUE, isShort); } */ fprintf (src,"\n"); if (tg->code < 31) tagLen = 1; else if (tg->code < 128) tagLen = 2; else if (tg->code < 16384) tagLen = 3; else if (tg->code < 2097152) tagLen = 4; else tagLen = 5; fprintf (src," %s += BEncTag%d (b, %s, %s, %d);\n", itemLenNameG, tagLen, classStr, formStr, tg->code); }} /* PrintCTagAndLenList *//* * prints length encoding code. Primitives always use * definite length and constructors get "ConsLen" * which can be configured at compile to to be indefinite * or definite. Primitives can also be "short" (isShort is true) * in which case a fast macro is used to write the length. * Types for which isShort apply are: boolean, null and * (almost always) integer and reals */static voidPrintCLenEncodingCode PARAMS ((f, isCons, isShort), FILE *f _AND_ int isCons _AND_ int isShort){ /* fprintf (f, " BER_ENCODE_DEF_LEN (b, itemLen, itemLen);"); */ if (isCons) fprintf (f, " itemLen += BEncConsLen (b, itemLen);"); else { if (isShort) { fprintf (f, " BEncDefLenTo127 (b, itemLen);\n"); fprintf (f, " itemLen++;"); } else fprintf (f, " itemLen += BEncDefLen (b, itemLen);"); }} /* PrintCLenEncodingCode */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -