コード例 #1
0
        public override DecodedObject <object> decodeSequence(DecodedObject <object> decodedTag, Type objectClass, ElementInfo elementInfo, Stream stream)
        {
            BitArrayInputStream bitStream = (BitArrayInputStream)stream;
            int preambleLen        = getSequencePreambleBitLen(objectClass, elementInfo);
            int preamble           = bitStream.readBits(preambleLen);
            int preambleCurrentBit = 32 - preambleLen;

            skipAlignedBits(stream);
            object sequence = createInstanceForElement(objectClass, elementInfo);

            initDefaultValues(sequence);
            ElementInfo info = new ElementInfo();
            int         idx  = 0;

            PropertyInfo[] fields = null;

            if (!CoderUtils.isSequenceSet(elementInfo) || elementInfo.hasPreparedInfo())
            {
                fields = elementInfo.getProperties(objectClass);
            }
            else
            {
                SortedList <int, PropertyInfo> fieldOrder = CoderUtils.getSetOrder(sequence.GetType());
                fields = new PropertyInfo[fieldOrder.Values.Count];
                fieldOrder.Values.CopyTo(fields, 0);
            }

            foreach (PropertyInfo field in fields)
            {
                if (elementInfo.hasPreparedInfo())
                {
                    info.PreparedInfo = elementInfo.PreparedInfo.getPropertyMetadata(idx);
                }
                if (CoderUtils.isOptionalField(field, info))
                {
                    if ((preamble & (0x80000000 >> preambleCurrentBit)) != 0)
                    {
                        decodeSequenceField(null, sequence, idx, field, stream, elementInfo, true);
                    }
                    preambleCurrentBit++;
                }
                else
                {
                    decodeSequenceField(null, sequence, idx, field, stream, elementInfo, true);
                }
                idx++;
            }
            return(new DecodedObject <object>(sequence));

            /*            }
             *          else
             *              return decodeSet(decodedTag, objectClass, elementInfo, stream);*/
        }
コード例 #2
0
        protected virtual int getSequencePreambleBitLen(Type objectClass, ElementInfo elementInfo)
        {
            int         preambleLen = 0;
            ElementInfo info        = new ElementInfo();
            int         fieldIdx    = 0;

            foreach (PropertyInfo field in elementInfo.getProperties(objectClass))
            {
                if (elementInfo.hasPreparedInfo())
                {
                    info.PreparedInfo = elementInfo.PreparedInfo.getPropertyMetadata(fieldIdx);
                }

                if (CoderUtils.isOptionalField(field, info))
                {
                    preambleLen++;
                }
                fieldIdx++;
            }

            return(preambleLen);
        }
コード例 #3
0
        public virtual int encodeSequencePreamble(object obj, PropertyInfo[] fields, System.IO.Stream stream, ElementInfo elementInfo)
        {
            int         resultBitSize = 0;
            ElementInfo info          = new ElementInfo();
            int         fieldIdx      = 0;

            foreach (PropertyInfo field in fields)
            {
                if (elementInfo.hasPreparedInfo())
                {
                    info.PreparedInfo = elementInfo.PreparedInfo.getPropertyMetadata(fieldIdx);
                }

                if (CoderUtils.isOptionalField(field, info))
                {
                    object invokeObjResult = invokeGetterMethodForField(field, obj, info);
                    if (invokeObjResult == null)
                    {
                        ((BitArrayOutputStream)stream).writeBit(false);
                    }
                    else if (CoderUtils.isDefaultField(field, info))
                    {
                        object newSequenceInstance = Activator.CreateInstance(obj.GetType());
                        CoderUtils.initDefaultValues(newSequenceInstance);
                        object defaultFieldValue = invokeGetterMethodForField(field, newSequenceInstance, info);
                        ((BitArrayOutputStream)stream).writeBit(!CoderUtils.AreEqual(defaultFieldValue, invokeObjResult));
                    }
                    else
                    {
                        ((BitArrayOutputStream)stream).writeBit(true);
                    }
                    resultBitSize += 1;
                }
                fieldIdx++;
            }
            doAlign(stream);
            return((resultBitSize / 8) + (resultBitSize % 8 > 0?1:0));
        }
コード例 #4
0
        public virtual int encodeSequencePreamble(object obj, PropertyInfo[] fields, Stream stream, ElementInfo elementInfo)
        {
            int         resultBitSize = 0;
            ElementInfo info          = new ElementInfo();
            int         fieldIdx      = 0;

            foreach (PropertyInfo field in fields) // obj.GetType().GetProperties()
            {
                if (elementInfo.hasPreparedInfo())
                {
                    info.PreparedInfo = elementInfo.PreparedInfo.getPropertyMetadata(fieldIdx);
                }
                if (CoderUtils.isOptionalField(field, info))
                {
                    object invokeObjResult = invokeGetterMethodForField(field, obj, info);
                    ((BitArrayOutputStream)stream).writeBit(invokeObjResult != null);
                    resultBitSize += 1;
                }
                fieldIdx++;
            }
            doAlign(stream);
            return((resultBitSize / 8) + (resultBitSize % 8 > 0 ? 1 : 0));
        }