public bool TryParseDynamicPropertyValue(Protocol.Buffer.IBitArray buffer, IDynamicContractValue msg, out IDynamicMemberValue value) { value = null; if (buffer.Length < this.LengthInBits) { return(false); } var res = new DynamicMemberValue(this, null); res.Description = this; if (this.IsArray) { long length = 0; var arrayLength = this.ArrayLength; if (!Int64.TryParse(arrayLength, out length)) { length = Convert.ToInt32(msg.Data[arrayLength].Value); } object[] array = new object[length]; if (buffer.Length < this.LengthInBits * length) { return(false); } for (int i = 0; i < length; i++) { array[i] = buffer.PopSingleValue(res.Description.LengthInBits, this.TypeCode); } var tmp = new byte[length]; for (int i = 0; i < length; i++) { tmp[i] = Convert.ToByte(array[i]); } res.Value = array; } else { res.Value = buffer.PopSingleValue(res.Description.LengthInBits, this.TypeCode); } value = res; return(true); }
public bool TryParseContract(Protocol.Buffer.IBitArray buffer, out IDynamicContractValue msg) { msg = new DynamicContractValue(this); foreach (var property in this.Members) { if (property.Value.IsConditional) { if (!property.Value.Condition.Evaluate(msg.Data)) { if (msg.Data.ContainsKey(property.Value.Name)) { msg.Data.Remove(property.Value.Name); } continue; } } if (property.Value.IsContract) { if (property.Value.IsArray) { int length = 0; var arrayLength = property.Value.ArrayLength; if (!Int32.TryParse(arrayLength, out length)) { //is reference value length = (int)msg.Data[arrayLength].Value; } object[] temp = new object[length]; IDynamicMemberValue propValue = new DynamicMemberValue(property.Value, null); for (int i = 0; i < length; i++) { IDynamicContractValue value; if (!property.Value.ContractDescription.TryParseContract(buffer, out value)) { return(false); } temp[i] = value; } propValue.Value = temp; msg.Data[property.Value.Name] = propValue; } else { IDynamicContractValue value; if (!property.Value.ContractDescription.TryParseContract(buffer, out value)) { return(false); } msg.Data[property.Value.Name] = value; } } else { IDynamicMemberValue value; if (!property.Value.TryParseDynamicPropertyValue(buffer, msg, out value)) { return(false); } msg.Data[value.Description.Name] = value; } } return(true); }