public byte[] ToByteArray(DynamicContractDescription dynamicMessageDescription) { DynamicMessageDescription = dynamicMessageDescription; Protocol.Buffer.BitArray buffer = new Protocol.Buffer.BitArray(); PushContractData(Data, DynamicMessageDescription, buffer); return(buffer.ToByteArray()); }
public static DynamicMemberDescription CreateDynamicMemberDescription(string name, DynamicContractDescription contractDescription) { return(new DynamicMemberDescription() { Name = name, ContractDescription = contractDescription, Condition = null }); }
public static DynamicMemberDescription CreateDynamicMemberDescription(string name, DynamicContractDescription contractDescription, string arrayLength) { return(new DynamicMemberDescription() { Name = name, ContractDescription = contractDescription, ArrayLength = arrayLength }); }
public static DynamicMemberDescription CreateDynamicMemberDescription(string name, int lengthInBits, TypeCode typeCode, object defaultValue, string arrayLength = null, DynamicMemberCondition condition = null, DynamicContractDescription contractDescription = null) { return(new DynamicMemberDescription() { Name = name, LengthInBits = lengthInBits, ArrayLength = arrayLength, TypeCode = typeCode, Default = defaultValue, Condition = condition, ContractDescription = contractDescription }); }
public DynamicContractValue(DynamicContractDescription dynamicMessageDescription) { _dynamicMessageDescription = dynamicMessageDescription; CreateDefaultValues(); }
//todo:this should be deep copy public DynamicContractValue(DynamicContractValue from) { _dynamicMessageDescription = from._dynamicMessageDescription; _data = from._data; }
public void PushContractData(Dictionary <string, IDynamicValue> data, DynamicContractDescription contractDescription, Protocol.Buffer.BitArray buffer) { foreach (var memberDescription in contractDescription.Members) { if (memberDescription.Value.IsConditional) { if (!memberDescription.Value.Condition.Evaluate(data)) { continue; } } if (memberDescription.Value.IsContract) { if (memberDescription.Value.IsArray) { var value = data[memberDescription.Value.Name] as IDynamicMemberValue; var arrayValue = value.Value as System.Collections.IEnumerable; int i = 0; foreach (var item in arrayValue) { i++; //array of contract PushContractData(((DynamicContractValue)item).Data, memberDescription.Value.ContractDescription, buffer); } } else { //contract PushContractData(((DynamicContractValue)data[memberDescription.Value.Name]).Data, memberDescription.Value.ContractDescription, buffer); } } else { var value = data[memberDescription.Value.Name] as IDynamicMemberValue; value.Description = memberDescription.Value; var val = value.ToByteArray(data); if (memberDescription.Value.IsArray) { int length = 0; var arrayLength = value.Description.ArrayLength; if (!Int32.TryParse(arrayLength, out length)) { //is reference value length = Convert.ToInt32(data[arrayLength].Value); } //array of simple type buffer.Push(val, memberDescription.Value.LengthInBits * length); } else { //simple type buffer.Push(val, memberDescription.Value.LengthInBits); } } } }
public void AddProperty(DynamicContractDescription description) { _dynamicMessageDescriptions[description.Type] = description; }