tables.ms

来自「ftam等标准协议服务器和客户端的源代码。」· MS 代码 · 共 354 行 · 第 1/2 页

MS
354
字号
.NS 2The structure and meaning of the tables generated from the ASN.1 grammar.XSThe structure and meaning of the tables generated from the ASN.1 grammar.XE.PPEach collection of \fBASN.1\fR grammar is called a module.(See .[ASN.1.])Each \fBASN.1\fR module is completely specified in the program by asingle \fBC\fR structure of type \fBmodtyp\fR and the data which it references.See the \fIpepdefs.h\fR file in the \fIpepsy\fR directory.For each \fBASN.1\fR modulethere are three tables that are generated from\fBASN.1\fR grammar.These initialised arrays which we call tables arecalled the encoding, decoding and printing tables.Each of these tables is referenced through a different pointerof the \fBmodtyp\fR structure..PPEach of these pointers references an array of pointers,one pointer for each \fBASN.1\fR type defined in the module.The position of one of these pointers is the unique type number we give toits corresponding type.The pointer references an array of type \fBtpe\fR or \fBptpe\fR, dependingwhether it is an entry in the decoding/encoding tables or printing tablesrespectively.See \fIpep.h\fR in the \fIpepsy\fR directory.This array actually contains the necessary information to encode/decode/printthat \fBASN.1\fR type.So given the \fBmodtyp\fR structure of an \fBASN.1\fR module and itstype number you can call a routine to encode, decode or print that type..PPThe rest of this document assumes a good knowledge of \fBASN.1\fR notationso go read a copy if you haven't already.From here on I shall mention only \fBtpe\fR and this means \fBtpe\fR in thecase of encoding or decoding and \fBptpe\fR in the case of printing, unlessotherwise stated.Each type is represented by an array of \fBtpe\fR (or \fBptpe\fR for printing).The basic element consists of four integer fields,the printing table is the same with an addition \fBchar\fR pointer field whichcontains the name corresponding to that entry in the \fBASN.1\fR grammar.The first specifies the type of the entry and determines how therest are interpreted.The possible types are listed in \fIpepsy/pep.h\fR.Each type is an array which starts with an entry of type \fBPE_START\fRand ends with one of type \fBPE_END\fR.Each primitive type requires one entry to specify it,apart from possible \fBPE_START\fR and \fBPE_END\fR used to specify the startand end of the type.Constructed types are represented by a list of entries terminated by anentry of type \fBPE_END\fR.As \fBASN.1\fR types can be nested inside so will therepresentation in \fBtpe\fR entries be nested.For example the \fBASN.1\fR type definition:.nf           Example1 ::=                   SEQUENCE {                       seq1 SEQUENCE {                                an-i INTEGER,                                an-ostring OCTET STRING                            },                       a-bool IMPLICIT [0] BOOLEAN                   }.fi.ce 1Will generate an encoding array:.nfstatic tpe et_Example1Test[] = {	{ PE_START, 0, 0, 0 },	{ SEQ_START, 0, 16, FL_UNIVERSAL },	{ SEQ_START, OFFSET(struct type_Test_Example1, seq1), 16, FL_UNIVERSAL },	{ INTEGER, OFFSET(struct element_Test_0, an__i), 2, FL_UNIVERSAL },	{ OCTETSTRING, OFFSET(struct element_Test_0, an__ostring), 4, FL_UNIVERSAL },	{ PE_END, 0, 0, 0 },	{ BOOLEAN, OFFSET(struct type_Test_Example1, a__bool), 0, FL_CONTEXT },	{ PE_END, 0, 0, 0 },	{ PE_END, 0, 0, 0 }	};.fi.PPHere the second last \fBPE_END\fR matches and closes off thefirst \fBSEQ_START\fR.The entries which correspond to the other primative types are prettyobvious, with the INTEGER entry corresponding to the primative INTEGER.For fields that generate data the general interpretation of the other threefields is offset, tag and flags/class fields respectively..IP offsetThe second field gives the offset in a \fBC\fR data structureneeded to reference the data that corresponds to this table entry.Each \fBASN.1\fR type has \fBC\fR structure types generated as described inthe .[ISODE.]manuals, volume 4 "The applications Cookbook" Section 5.2,"POSY Environment".As this offset may have to be determined in a compiler dependent mannera \fBC\fR preprocessor macro is used hide the actual details..IP tagThis is the tag associated with the \fBASN.1\fR type for that entry.Notice that in the example the [0] IMPLICIT which changes the tagassociated with the BOOLEAN entry actually has the correct tag of 0 in thetable.Likewise SEQUENCE has the correct tag of 16 in its \fBSEQ_START\fR entryand so on for the others..IP flags/classThis contains the \fBASN.1\fR class associated with the entry's type.That is UNIVERSAL for all except the BOOLEAN type which is CONTEXT class.This fourth can also contain flags that specify if the type is OPTIONALor DEFAULT.There is plenty of room here as there is only four possibly classes..PPNow that you have some idea of how these arrays are arranged for a typedefinition I will proceed to go through the possible type ofentries and describe what they do and how they work.These values are defined in \fIpepsy/pep.h\fR.Those entries with a value below \fBTYPE_DATA\fR are entries thatdon't correspond to data to be encoded/decoded and are for other book keepingtype purposes..IP "PE_START and PE_END"As explained above \fBPE_START\fR starts the beginning of a \fBASN.1\fR type'sarray.It probably isn't necessary but the size of the tables is so small it isn'tmuch of an over head to keep around for cosmetic reasons.The entry type \fBPE_END\fR is necessary to mark the end of somecompound type as well as the end of \fBASN.1\fR data type..IP "XOBJECT and UCODE"These are obsolete types and probably should be removed.They were to allow \fBC\fR code written directly by the user to be incorporatedinto the encoding/decoding but it was found unnecessary.Prehaps some brave soul would like to use them in an attempt to implementa similar system based on \fIpepy\fR which is what we first attempted todo until we found this to be much easier..IP MALLOCThis field only occurs in the decoding tables.It specifies how much space to malloc out for the current \fBC\fR structureit is just inside of.For instance in the example above the decoding table has the following entry:.DS C{ MALLOC, 0, sizeof (struct type_Test_Example1), 0 },.DEjust after the first \fBSEQ_START\fR entry.It tells it to \fBmalloc\fR out a \fBstruct type_Test_Example1\fR structureto hold the data from the sequence when it is decoded..IP SCTRLThis entry is used in handling the \fBASN.1\fR CHOICE type.The \fBC\fR type generated for \fBASN.1\fR CHOICE type is a structure withan offset field in it and aunion of all the \fBC\fR types present in the CHOICE.Each \fBASN.1\fR type in the CHOICE of types has a \fBC\fR type definitiongenerated for it.The union is of all these types, which is quite a logical way to implementa CHOICE type.The offset field specifies which possibility of interpreting the unionshould be used (which \fImember\fR should selected).As such it needs to be read by the encoding routineswhen encoding the data from the \fBC\fR data structuresand to be set by the decoding routines when it is decoding the data intothe \fBC\fR data structures.There is one such entry for each \fBCHOICE\fR type to specify where theoffset field is..IP CH_ACTAnother redundant entry type.I think this was also used in code to handle \fBC\fR statements oractions specified by the user.It probably should be removed..IP OPTLThis is used to handle the optionals field that is generated by\fBposy\fR when optional types that are \fInot\fR implemented by pointersare present in the \fBASN.1\fR type.For example if an \fBASN.1\fR type has an optional integer field howdoes the encoding routine determine if the integer is to bepresent or not?

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?