public Sequence(Sequence other) : base(other) { _group = (Group) other._group.Clone(); _implicitLength = other._implicitLength; _length = (Scalar) other._length.Clone(); }
public ScalarValue Lookup(Group template, QName key, QName applicationType) { ScalarValue value; if (_dictionary.TryGetValue(Tuple.Create(template.TypeReference, key), out value)) return value; return ScalarValue.Undefined; }
public Group(Group other) : base(other) { _childNamespace = other._childNamespace; _typeReference = other._typeReference; Init(other._fieldDefinitions.CloneArray(), out _fieldDefinitions, out _fields, out _fieldIndexMap, out _fieldNameMap, out _introspectiveFieldMap, out _usesPresenceMapRenamedField, out _staticTemplateReferences); }
public void TestEncodeDecodeNestedSequence() { var nestedSequence = new Sequence("nested", new Field[] { new Scalar("string", FASTType.ASCII, Operator.COPY, ScalarValue.UNDEFINED, false) }, true); var group = new Group("group", new Field[] { nestedSequence }, true); var t = new MessageTemplate("template", new Field[] { group }); var message = new Message(t); FastEncoder encoder = Encoder(t); AssertEquals("11000000 10000001", encoder.Encode(message)); FastDecoder decoder = Decoder("11000000 10000001", t); Assert.AreEqual(message, decoder.ReadMessage()); }
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 void TestDecode() { const string message = "11000000 10000010 10000010"; Stream inp = new MemoryStream(ByteUtil.ConvertBitStringToFastByteArray(message)); var firstname = new Scalar("firstName", FastType.U32, Operator.Copy, ScalarValue.Undefined, true); var lastName = new Scalar("lastName", FastType.U32, Operator.None, ScalarValue.Undefined, false); // MessageInputStream in = new MessageInputStream(new // ByteArrayInputStream(message.getBytes())); var group = new Group("person", new Field[] {firstname, lastName}, false); var groupValue = (GroupValue) group.Decode(inp, _template, _context, BitVectorReader.InfiniteTrue); Assert.AreEqual(1, ((IntegerValue) groupValue.GetValue(0)).Value); Assert.AreEqual(2, ((IntegerValue) groupValue.GetValue(1)).Value); }
public static Message Convert(Group group, Message groupMsg, ConversionContext context) { SetNameAndId(group, groupMsg); if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference)) { var typeRef = new GroupValue( (Group) SessionControlProtocol11 .TypeRef .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace))); SetName(typeRef, group.TypeReference); groupMsg.SetFieldValue("TypeRef", typeRef); } var instructions = new SequenceValue( SessionControlProtocol11.TemplateDefinition.GetSequence("Instructions")); if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference)) { var typeRef = new GroupValue( (Group) SessionControlProtocol11 .TypeRef .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace))); SetName(typeRef, group.TypeReference); groupMsg.SetFieldValue("TypeRef", typeRef); } Field[] fields = group.FieldDefinitions; for (int i = group is MessageTemplate ? 1 : 0; i < fields.Length; i++) { Field field = fields[i]; IFieldInstructionConverter converter = context.GetConverter(field); if (converter == null) throw new InvalidOperationException("No converter found for type " + field.GetType()); IFieldValue v = converter.Convert(field, context); instructions.Add(new[] {v}); } groupMsg.SetFieldValue("Instructions", instructions); return groupMsg; }
public GroupValue(Group group, IFieldValue[] values) { if (group == null) throw new ArgumentNullException("group"); if (values == null) throw new ArgumentNullException("values"); _group = group; _values = values; Field[] flds = group.Fields; for (int i = 0; i < flds.Length; i++) { var scalar = flds[i] as Scalar; if (scalar != null && scalar.Operator.Equals(Operator.Constant) && !scalar.IsOptional) { values[i] = scalar.DefaultValue; } } }
public override FieldValue Decode(System.IO.Stream in_Renamed, Group decodeTemplate, Context context, BitVectorReader presenceMapReader) { var values = new FieldValue[fields.Length]; for (var i = 0; i < fields.Length; i++) { values[i] = fields[i].Decode(in_Renamed, decodeTemplate, context, presenceMapReader); if (i == 0 && values[0] == null) return null; } return valueConverter.Compose(values); }
public override byte[] Encode(IFieldValue value, Group encodeTemplate, Context context, BitVectorBuilder presenceMapBuilder) { if (HasTypeReference) context.CurrentApplicationType = TypeReference; if (value == null) return _length.Encode(null, encodeTemplate, context, presenceMapBuilder); var buffer = new MemoryStream(); var val = (SequenceValue) value; int len = val.Length; try { byte[] tmp = _length.Encode(new IntegerValue(len), encodeTemplate, context, presenceMapBuilder); buffer.Write(tmp, 0, tmp.Length); foreach (GroupValue v in val.Elements) { tmp = _group.Encode(v, encodeTemplate, context); buffer.Write(tmp, 0, tmp.Length); } } catch (IOException e) { Global.ErrorHandler.OnError(e, DynError.IoError, "An IO error occurred while encoding {0}", this); } return buffer.ToArray(); }
public override byte[] Encode(FieldValue value_Renamed, Group encodeTemplate, Context context, BitVectorBuilder presenceMapBuilder) { if (value_Renamed == null) { // Only encode null in the first field. return fields[0].Encode(null, encodeTemplate, context, presenceMapBuilder); } var buffer = new System.IO.MemoryStream(fields.Length * 8); var values = valueConverter.Split(value_Renamed); for (int i = 0; i < fields.Length; i++) { try { var temp_byteArray = fields[i].Encode(values[i], encodeTemplate, context, presenceMapBuilder); buffer.Write(temp_byteArray, 0, temp_byteArray.Length); } catch (System.IO.IOException e) { throw new RuntimeException(e); } } return buffer.ToArray(); }
public ScalarValue Lookup(Group template, QName key, QName applicationType) { ScalarValue value; return _dictionary.TryGetValue(key, out value) ? value : ScalarValue.Undefined; }
public override IFieldValue Decode(Stream inStream, Group decodeTemplate, Context context, BitVectorReader pmapReader) { var sequenceValue = new SequenceValue(this); IFieldValue lengthValue = _length.Decode(inStream, decodeTemplate, context, pmapReader); if ((lengthValue == ScalarValue.Null) || (lengthValue == null)) { return null; } int len = ((IntegerValue) lengthValue).Value; for (int i = 0; i < len; i++) sequenceValue.Add( (GroupValue) _group.Decode(inStream, decodeTemplate, context, BitVectorReader.InfiniteTrue)); return sequenceValue; }
public override FieldValue Decode(System.IO.Stream in_Renamed, Group decodeTemplate, Context context, BitVectorReader pmapReader) { var sequenceValue = new SequenceValue(this); FieldValue lengthValue = length.Decode(in_Renamed, decodeTemplate, context, pmapReader); if ((lengthValue == ScalarValue.NULL) || (lengthValue == null)) { return null; } int len = ((IntegerValue) lengthValue).value_Renamed; for (var i = 0; i < len; i++) sequenceValue.Add((GroupValue) group.Decode(in_Renamed, decodeTemplate, context, BitVectorReader.INFINITE_TRUE)); return sequenceValue; }
public static Operator GetOperator(Group group) { var msgTemplate = group as MessageTemplate; Operator value; if (msgTemplate != null && TemplateOperatorMap.TryGetValue(msgTemplate, out value)) return value; return null; }
public void Store(Group template, QName key, QName applicationType, ScalarValue value) { _dictionary[key] = value; }
protected void SetUp() { _template = new MessageTemplate("", new Field[0]); _context = new Context(); }
public abstract byte[] Encode(FieldValue value_Renamed, Group encodeTemplate, Context context, BitVectorBuilder presenceMapBuilder);
public override FieldValue Decode(System.IO.Stream in_Renamed, Group decodeTemplate, Context context, BitVectorReader presenceMapReader) { try { ScalarValue previousValue = null; if (operator_Renamed.UsesDictionary()) { previousValue = context.Lookup(Dictionary, decodeTemplate, Key); ValidateDictionaryTypeAgainstFieldType(previousValue, type); } ScalarValue value_Renamed; int pmapIndex = presenceMapReader.Index; if (IsPresent(presenceMapReader)) { if (context.TraceEnabled) in_Renamed = new RecordingInputStream(in_Renamed); if (!operatorCodec.ShouldDecodeType()) { return operatorCodec.DecodeValue(null, null, this); } ScalarValue decodedValue = typeCodec.Decode(in_Renamed); value_Renamed = DecodeValue(decodedValue, previousValue); if (context.TraceEnabled) context.DecodeTrace.Field(this, value_Renamed, decodedValue, ((RecordingInputStream) in_Renamed).Buffer, pmapIndex); } else { value_Renamed = Decode(previousValue); } ValidateDecodedValueIsCorrectForType(value_Renamed, type); if (!((Operator == Template.Operator.Operator.DELTA) && (value_Renamed == null))) { context.Store(Dictionary, decodeTemplate, Key, value_Renamed); } return value_Renamed; } catch (FastException e) { throw new FastException("Error occurred while decoding " + this, e.Code, e); } }
public abstract FieldValue Decode(System.IO.Stream in_Renamed, Group decodeTemplate, Context context, BitVectorReader presenceMapReader);
public void Store(Group template, QName key, QName applicationType, ScalarValue value) { _dictionary[Tuple.Create(template.TypeReference, key)] = value; }
public override FieldValue Decode(System.IO.Stream in_Renamed, Group decodeTemplate, Context context, BitVectorReader pmapReader) { return new FastDecoder(context, in_Renamed).ReadMessage(); }
public override IFieldValue Decode(Stream inStream, Group decodeTemplate, Context context, BitVectorReader presenceMapReader) { try { ScalarValue priorValue = null; IDictionary dict = null; QName key = Key; ScalarValue value; int pmapIndex = presenceMapReader.Index; if (IsPresent(presenceMapReader)) { if (context.TraceEnabled) inStream = new RecordingInputStream(inStream); if (!_operatorCodec.ShouldDecodeType) return _operatorCodec.DecodeValue(null, null, this); if (_operatorCodec.DecodeNewValueNeedsPrevious) { dict = context.GetDictionary(Dictionary); priorValue = context.Lookup(dict, decodeTemplate, key); ValidateDictionaryTypeAgainstFieldType(priorValue, _fastType); } ScalarValue decodedValue = _typeCodec.Decode(inStream); value = _operatorCodec.DecodeValue(decodedValue, priorValue, this); if (context.TraceEnabled) context.DecodeTrace.Field(this, value, decodedValue, ((RecordingInputStream) inStream).Buffer, pmapIndex); } else { if (_operatorCodec.DecodeEmptyValueNeedsPrevious) { dict = context.GetDictionary(Dictionary); priorValue = context.Lookup(dict, decodeTemplate, key); ValidateDictionaryTypeAgainstFieldType(priorValue, _fastType); } value = _operatorCodec.DecodeEmptyValue(priorValue, this); } ValidateDecodedValueIsCorrectForType(value, _fastType); #warning TODO: Review if this previous "if" statement is needed. // if (Operator != Template.Operator.Operator.DELTA || value != null) if (value != null && (_operatorCodec.DecodeNewValueNeedsPrevious || _operatorCodec.DecodeEmptyValueNeedsPrevious)) { context.Store(dict ?? context.GetDictionary(Dictionary), decodeTemplate, key, value); } return value; } catch (DynErrorException e) { throw new DynErrorException(e, e.Error, "Error occurred while decoding {0}", this); } }
private static Group Instrument() { if (_instrument == null) { _instrument = new Group("Instrmt", new Field[] { new Scalar("Symbol", FASTType.ASCII, Operator.COPY, ScalarValue.UNDEFINED, false), new Scalar("MMY", FASTType.ASCII, Operator.DELTA, ScalarValue.UNDEFINED, false), }, false); } return _instrument; }
public override byte[] Encode(IFieldValue fieldValue, Group encodeTemplate, Context context, BitVectorBuilder presenceMapBuilder) { IDictionary dict = context.GetDictionary(Dictionary); ScalarValue priorValue = context.Lookup(dict, encodeTemplate, Key); var value = (ScalarValue) fieldValue; if (!_operatorCodec.CanEncode(value, this)) { Global.ErrorHandler.OnError(null, DynError.CantEncodeValue, "The scalar {0} cannot encode the value {1}", this, value); } ScalarValue valueToEncode = _operatorCodec.GetValueToEncode(value, priorValue, this, presenceMapBuilder); if (_operator.ShouldStoreValue(value)) { context.Store(dict, encodeTemplate, Key, value); } if (valueToEncode == null) { return ByteUtil.EmptyByteArray; } byte[] encoding = _typeCodec.Encode(valueToEncode); if (context.TraceEnabled && encoding.Length > 0) { context.EncodeTrace.Field(this, fieldValue, valueToEncode, encoding, presenceMapBuilder.Index); } return encoding; }
public void GroupStart(Group group) { Print(group); MoveDown(); }
public override byte[] Encode(FieldValue value_Renamed, Group encodeTemplate, Context context, BitVectorBuilder presenceMapBuilder) { if (HasTypeReference()) context.CurrentApplicationType = TypeReference; if (value_Renamed == null) { return length.Encode(null, encodeTemplate, context, presenceMapBuilder); } var buffer = new System.IO.MemoryStream(); var val = (SequenceValue) value_Renamed; int len = val.Length; try { var temp_byteArray = length.Encode(new IntegerValue(len), encodeTemplate, context, presenceMapBuilder); buffer.Write(temp_byteArray, 0, temp_byteArray.Length); System.Collections.IEnumerator iter = val.Iterator(); while (iter.MoveNext()) { var temp_byteArray2 = group.Encode((FieldValue) iter.Current, encodeTemplate, context); buffer.Write(temp_byteArray2, 0, temp_byteArray2.Length); } } catch (System.IO.IOException e) { Global.HandleError(Error.FastConstants.IO_ERROR, "An IO error occurred while encoding " + this, e); } return buffer.ToArray(); }
public override byte[] Encode(FieldValue value_Renamed, Group encodeTemplate, Context context, BitVectorBuilder presenceMapBuilder) { var message = (Message) value_Renamed; return message.Template.Encode(message, context); }
public override byte[] Encode(FieldValue fieldValue, Group encodeTemplate, Context context, BitVectorBuilder presenceMapBuilder) { var priorValue = context.Lookup(Dictionary, encodeTemplate, Key); var value_Renamed = (ScalarValue) fieldValue; if (!operatorCodec.CanEncode(value_Renamed, this)) { Global.HandleError(Error.FastConstants.D3_CANT_ENCODE_VALUE, "The scalar " + this + " cannot encode the value " + value_Renamed); } var valueToEncode = operatorCodec.GetValueToEncode(value_Renamed, priorValue, this, presenceMapBuilder); if (operator_Renamed.ShouldStoreValue(value_Renamed)) { context.Store(Dictionary, encodeTemplate, Key, value_Renamed); } if (valueToEncode == null) { return new byte[0]; } byte[] encoding = typeCodec.Encode(valueToEncode); if (context.TraceEnabled && encoding.Length > 0) { context.GetEncodeTrace().Field(this, fieldValue, valueToEncode, encoding, presenceMapBuilder.Index); } return encoding; }
public GroupValue(Group group) : this(group, new IFieldValue[group.FieldCount]) { }