public override bool ShouldConvert(Field field)
 {
     if (!field.GetType().Equals(typeof (Scalar)))
         return false;
     var type = ((Scalar) field).FastType;
     return type.Equals(FastType.ByteVector) || type.Equals(FastType.Unicode);
 }
Ejemplo n.º 2
0
 public Group(QName name, Field[] fields, bool optional)
     : base(name, optional)
 {
     var expandedFields = new List<Field>();
     var references = new List<StaticTemplateReference>();
     for (int i = 0; i < fields.Length; i++)
     {
         if (fields[i] is StaticTemplateReference)
         {
             var currentTemplate = (StaticTemplateReference)fields[i];
             Field[] referenceFields = currentTemplate.Template.Fields;
             for (int j = 1; j < referenceFields.Length; j++)
                 expandedFields.Add(referenceFields[j]);
             references.Add(currentTemplate);
         }
         else
         {
             expandedFields.Add(fields[i]);
         }
     }
     this.fields = expandedFields.ToArray();
     fieldDefinitions = fields;
     fieldIndexMap = ConstructFieldIndexMap(this.fields);
     fieldNameMap = ConstructFieldNameMap(this.fields);
     fieldIdMap = ConstructFieldIdMap(this.fields);
     introspectiveFieldMap = ConstructInstrospectiveFields(this.fields);
     usesPresenceMap_Renamed_Field = DeterminePresenceMapUsage(this.fields);
     staticTemplateReferences = references.ToArray();
 }
        public virtual IFieldInstructionConverter GetConverter(Field field)
        {
            for (int i = _converters.Count - 1; i >= 0; i--)
                if (_converters[i].ShouldConvert(field))
                    return _converters[i];

            throw new ArgumentOutOfRangeException("field", field, "No valid converter found for the field");
        }
Ejemplo n.º 4
0
 public void Field(Field field, IFieldValue value, IFieldValue decodedValue, byte[] encoding, int pmapIndex)
 {
     var scalarDecode = new StringBuilder();
     scalarDecode.Append(field.Name).Append(": ");
     scalarDecode.Append(ByteUtil.ConvertByteArrayToBitString(encoding));
     scalarDecode.Append(" -> ").Append(value).Append('(').Append(decodedValue).Append(')');
     Print(scalarDecode);
 }
Ejemplo n.º 5
0
        public Group(QName name, string childNamespace, Field[] fields, bool optional)
            : base(name, optional)
        {
            _childNamespace = childNamespace;

            Init(fields,
                 out _fieldDefinitions, out _fields, out _fieldIndexMap, out _fieldNameMap,
                 out _introspectiveFieldMap, out _usesPresenceMapRenamedField, out _staticTemplateReferences);
        }
 public override GroupValue Convert(Field field, ConversionContext context)
 {
     var composedScalar = (ComposedScalar) field;
     var message = new Message(SessionControlProtocol11.CompDecimalInstr);
     SetNameAndId(field, message);
     message.SetInteger("Optional", field.IsOptional ? 1 : 0);
     GroupValue exponentDef = CreateComponent(composedScalar.Fields[0], "Exponent");
     GroupValue mantissaDef = CreateComponent(composedScalar.Fields[1], "Mantissa");
     message.SetFieldValue("Exponent", exponentDef);
     message.SetFieldValue("Mantissa", mantissaDef);
     return message;
 }
Ejemplo n.º 7
0
        public Sequence(QName name, Scalar length, Field[] fields, bool optional)
            : base(name, optional)
        {
            _group = new Group(name, fields, optional);

            if (length == null)
            {
                _length = CreateLength(name, optional);
                _implicitLength = true;
            }
            else
                _length = length;
        }
 public override GroupValue Convert(Field field, ConversionContext context)
 {
     var scalar = (Scalar) field;
     GroupValue fieldDef = base.Convert(field, context);
     string value;
     if (scalar.TryGetAttribute(FastConstants.LengthField, out value))
     {
         var lengthDef = new GroupValue(fieldDef.Group.GetGroup("Length"));
         lengthDef.SetString("Name", value);
         fieldDef.SetFieldValue("Length", lengthDef);
     }
     return fieldDef;
 }
 public override bool ShouldConvert(Field field)
 {
     return field.GetType().Equals(typeof (Sequence));
 }
        private MessageTemplate RegisterTemplate(Field field)
        {
            var messageTemplate = new MessageTemplate("", new[] {field});
            _encodingContext.RegisterTemplate(113, messageTemplate);
            _decodingContext.RegisterTemplate(113, messageTemplate);

            return messageTemplate;
        }
 public override bool ShouldConvert(Field field)
 {
     return field.GetType().Equals(typeof (StaticTemplateReference));
 }
 public override GroupValue Convert(Field field, ConversionContext context)
 {
     var strDef = new Message(SessionControlProtocol11.StatTempRefInstr);
     SetNameAndId(field, strDef);
     return strDef;
 }
Ejemplo n.º 13
0
        public static Field[] ParseFieldInstructions(GroupValue groupDef, ITemplateRegistry registry,
                                                     ConversionContext context)
        {
            SequenceValue instructions = groupDef.GetSequence("Instructions");
            var fields = new Field[instructions.Length];
            for (int i = 0; i < fields.Length; i++)
            {
                GroupValue fieldDef = instructions[i].GetGroup(0);
                IFieldInstructionConverter converter = context.GetConverter(fieldDef.Group);
                if (converter == null)
                    throw new SystemException(
                        string.Format("Encountered unknown group {0} while processing field instructions {1}",
                                      fieldDef.Group, groupDef.Group));

                fields[i] = converter.Convert(fieldDef, registry, context);
            }
            return fields;
        }
Ejemplo n.º 14
0
 public Group(string name, Field[] fields, bool optional)
     : this(new QName(name), "", fields, optional)
 {
 }
 public virtual bool ShouldConvert(Field field)
 {
     return field.GetType().Equals(typeof (DynamicTemplateReference));
 }
Ejemplo n.º 16
0
 public Sequence(QName name, Field[] fields, bool optional)
     : this(name, CreateLength(name, optional), fields, optional)
 {
     implicitLength = true;
 }
 public abstract bool ShouldConvert(Field param1);
 public abstract GroupValue Convert(Field param1, ConversionContext param2);
 public static void SetNameAndId(Field field, GroupValue fieldDef)
 {
     SetName(field, fieldDef);
     if (!field.IsIdNull())
         fieldDef.SetString("AuxId", field.Id);
 }
 public static void SetName(Field field, GroupValue fieldDef)
 {
     QName qname = field.QName;
     SetName(fieldDef, qname);
 }
 public override bool ShouldConvert(Field field)
 {
     return field.GetType().Equals(typeof (ComposedScalar));
 }
Ejemplo n.º 22
0
        public override GroupValue Convert(Field field, ConversionContext context)
        {
            var sequence = (Sequence) field;
            Message seqDef = GroupConverter.Convert(
                sequence.Group,
                new Message(SessionControlProtocol11.SequenceInstr),
                context);

            seqDef.SetBool("Optional", sequence.IsOptional);
            if (!sequence.ImplicitLength)
            {
                Group lengthGroup = SessionControlProtocol11.SequenceInstr.GetGroup("Length");
                var lengthDef = new GroupValue(lengthGroup);
                Scalar length = sequence.Length;
                var nameDef = new GroupValue(lengthGroup.GetGroup("Name"));
                SetNameAndId(length, nameDef);
                lengthDef.SetFieldValue("Name", nameDef);
                seqDef.SetFieldValue("Length", lengthDef);

                if (!length.Operator.Equals(Operator.None))
                {
                    var operatorDef = new GroupValue(lengthGroup.GetGroup("Operator"));
                    operatorDef.SetFieldValue(0, CreateOperator(length));
                    lengthDef.SetFieldValue("Operator", operatorDef);
                }

                if (!length.DefaultValue.IsUndefined)
                {
                    lengthDef.SetFieldValue("InitialValue", length.DefaultValue);
                }
            }

            if (sequence.TypeReference != null && !FastConstants.AnyType.Equals(sequence.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group)
                        SessionControlProtocol11.TypeRef.GetField(new QName("TypeRef",
                                                                              SessionControlProtocol11.Namespace)));
                SetName(typeRef, sequence.TypeReference);
                seqDef.SetFieldValue("TypeRef", typeRef);
            }

            return seqDef;
        }
 public virtual GroupValue Convert(Field field, ConversionContext context)
 {
     return SessionControlProtocol11.DynTempRefMessage;
 }
Ejemplo n.º 24
0
 public override GroupValue Convert(Field field, ConversionContext context)
 {
     var group = (Group) field;
     Message groupMsg = Convert(group, new Message(SessionControlProtocol11.GroupInstr), context);
     groupMsg.SetBool("Optional", field.IsOptional);
     return groupMsg;
 }
Ejemplo n.º 25
0
 public void SetString(Field field, string value)
 {
     if (field == null) throw new ArgumentNullException("field", "Field must not be null [value=" + value + "]");
     SetFieldValue(field, field.CreateValue(value));
 }
Ejemplo n.º 26
0
 public Group(QName name, Field[] fields, bool optional)
     : this(name, "", fields, optional)
 {
 }
Ejemplo n.º 27
0
 public IFieldValue GetValue(Field field)
 {
     return _values[_group.GetFieldIndex(field)];
 }
Ejemplo n.º 28
0
        public override GroupValue Convert(Field field, ConversionContext context)
        {
            var scalar = (Scalar) field;
            var scalarTemplate = (MessageTemplate) _typeTemplateMap[scalar.FastType];
            var scalarMsg = new Message(scalarTemplate);
            SetNameAndId(scalar, scalarMsg);
            scalarMsg.SetInteger("Optional", scalar.IsOptional ? 1 : 0);

            if (!scalar.Operator.Equals(Operator.None))
                scalarMsg.SetFieldValue(
                    "Operator",
                    new GroupValue(scalarTemplate.GetGroup("Operator"), new IFieldValue[] {CreateOperator(scalar)}));

            if (!scalar.DefaultValue.IsUndefined)
                scalarMsg.SetFieldValue("InitialValue", scalar.DefaultValue);

            return scalarMsg;
        }
Ejemplo n.º 29
0
 public Sequence(string name, Field[] fields, bool optional)
     : this(new QName(name), fields, optional)
 {
 }
Ejemplo n.º 30
0
 public void SetFieldValue(Field field, IFieldValue value)
 {
     SetFieldValue(_group.GetFieldIndex(field), value);
 }