示例#1
0
        public static void PrintCDecode(SequenceOrSetType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string varName, int lev)
        {
            string varName2 = varName;
            if (!varName.Contains("->"))
                varName2 += "->";
            else
                varName2 += ".";

            int nBitMaskLength = (int)Math.Ceiling(pThis.GetNumberOfOptionalOrDefaultFields() / 8.0);
            //c.P(lev); c.WriteLine("{"); lev++;
            c.P(lev);
            if (nBitMaskLength > 0)
            {
                //c.WriteLine("byte bitMask[{0}];", nBitMaskLength);
                //c.P(lev);
                c.WriteLine("if (!BitStream_ReadBits(pBitStrm, bitMask, {0})) {{", pThis.GetNumberOfOptionalOrDefaultFields());
                c.P(lev + 1);
                c.WriteLine("*pErrCode = ERR_INSUFFICIENT_DATA;");
                c.P(lev + 1);
                c.WriteLine("return FALSE;");
                c.P(lev);
                c.WriteLine("}");
            }

            int currentByte = 0;
            int currentBit = 0;
            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                c.P(lev); c.WriteLine("/*Decode {0} ({1})*/", ch.m_childVarName, ch.m_type.Name);
                if (ch.m_optional || ch.m_default)
                {
                    byte cb = 0x80;
                    c.P(lev);
                    c.WriteLine("{0}exist.{1} = 0;", varName2, C.ID(ch.m_childVarName));

                    c.P(lev);
                    c.WriteLine("if ((bitMask[{0}] & 0x{1:X2}) != 0 ) {{", currentByte, (cb >> currentBit));

                    c.P(lev + 1);
                    c.WriteLine("{0}exist.{1} = 1;", varName2, C.ID(ch.m_childVarName));

                    ((ISCCType)ch.m_type).PrintCDecode(ch.m_type.PEREffectiveConstraint, c, varName2 + C.ID(ch.m_childVarName), lev + 1);
                    c.P(lev); c.WriteLine("}");
                    if (ch.m_defaultValue != null)
                    {
                        c.P(lev); c.WriteLine("else");
                        c.P(lev); c.WriteLine("{");

                        c.P(lev + 1);
                        c.WriteLine("{0}exist.{1} = 1;", varName2, C.ID(ch.m_childVarName));

                        ((ISCCType)ch.m_type).PrintCInitialize(ch.m_type.PEREffectiveConstraint, ch.m_defaultValue, c, "", varName2 + C.ID(ch.m_childVarName), lev + 1, CLocalVariable.GetArrayIndex(varName) + 1);
                        c.P(lev); c.WriteLine("}");
                    }

                    currentBit++;
                    if (currentBit == 8)
                    {
                        currentBit = 0;
                        currentByte++;
                    }
                }
                else
                {
                    ((ISCCType)ch.m_type).PrintCDecode(ch.m_type.PEREffectiveConstraint, c, varName2 + C.ID(ch.m_childVarName), lev);
                }
            }
            //lev--; c.P(lev); c.WriteLine("}");
        }
示例#2
0
        public static void PrintHTypeDeclaration(SequenceOrSetType pThis, PEREffectiveConstraint cns, StreamWriterLevel h, string typeName, string varName, int lev)
        {
            h.WriteLine("struct {");
            //            h.WriteLine("struct {0} {{", typeName);
            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                h.WriteComment(ch.m_comments, lev + 1);
                h.P(lev + 1);
                ((ISCCType)ch.m_type).PrintHTypeDeclaration(ch.m_type.PEREffectiveConstraint, h,
                    typeName + "_" + C.ID(ch.m_childVarName), C.ID(ch.m_childVarName), lev + 1);
                if (!(ch.m_type is IA5StringType))
                    h.WriteLine(" {0};", C.ID(ch.m_childVarName));
            }
            if (pThis.GetNumberOfOptionalOrDefaultFields() != 0)
            {
                h.P(lev + 1);
                h.WriteLine("struct {");
                foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
                {
                    if (ch.m_optional || ch.m_defaultValue != null)
                    {
                        h.P(lev + 2);
                        h.WriteLine("unsigned int {0}:1;", C.ID(ch.m_childVarName));
                    }
                }
                h.P(lev + 1);
                h.WriteLine("} exist;");

            }
            h.P(lev);
            h.Write("}");
        }
示例#3
0
        public static void VarsNeededForDecode(SequenceOrSetType pThis, PEREffectiveConstraint cns, int arrayDepth, OrderedDictionary<string, CLocalVariable> existingVars)
        {
            int nBitMaskLength = (int)Math.Ceiling(pThis.GetNumberOfOptionalOrDefaultFields() / 8.0);
            if (nBitMaskLength > 0)
            {
                if (!existingVars.ContainsKey("bitMask"))
                    existingVars.Add("bitMask", new CLocalVariable("bitMask", "byte", nBitMaskLength, ""));
                else
                {
                    CLocalVariable lv = existingVars["bitMask"];
                    if (lv.arrayLen < nBitMaskLength)
                        lv.arrayLen = nBitMaskLength;
                }
            }

            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                ((ISCCType)ch.m_type).VarsNeededForDecode(ch.m_type.PEREffectiveConstraint, arrayDepth, existingVars);
            }
        }
示例#4
0
        public static void PrintCEncode(SequenceOrSetType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string varName, int lev)
        {
            string varName2 = varName;
            if (!varName.Contains("->"))
                varName2 += "->";
            else
                varName2 += ".";
            if (pThis.GetNumberOfOptionalOrDefaultFields() > 0)
            {
                c.P(lev);
                c.WriteLine("/* Encode Bit Mask for optional and default fields*/");
            }

            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                if (ch.m_optional || ch.m_default)
                {
                    c.P(lev);
                    c.WriteLine("BitStream_AppendBit(pBitStrm, {0});", varName2 + "exist." + C.ID(ch.m_childVarName));
                }
            }
            c.WriteLine();
            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                c.P(lev); c.WriteLine("/*Encode {0} ({1})*/", ch.m_childVarName, ch.m_type.Name);
                if (ch.m_optional || ch.m_default)
                {
                    c.P(lev);
                    c.WriteLine("if ( {0}exist.{1} ) {{", varName2, C.ID(ch.m_childVarName));
                    ((ISCCType)ch.m_type).PrintCEncode(ch.m_type.PEREffectiveConstraint, c, errorCode + "_" + C.ID(ch.m_childVarName), varName2 + C.ID(ch.m_childVarName), lev + 1);
                    c.P(lev); c.WriteLine("}");

                }
                else
                    ((ISCCType)ch.m_type).PrintCEncode(ch.m_type.PEREffectiveConstraint, c, errorCode + "_" + C.ID(ch.m_childVarName), varName2 + C.ID(ch.m_childVarName), lev);
                c.WriteLine();
            }
        }