public virtual bool Verify(DeserializeStatus status, TCalculatorResultType receivedValue, TCalculatorResultType computedValue) { bool success = receivedValue.Equals(computedValue); if (!success) { AddFailedMessage(status, receivedValue, computedValue); } return(success); }
public override bool Verify(DeserializeStatus status, byte[] receivedValue, byte[] computedValue) { bool returnValue; if (receivedValue == null && computedValue == null) { returnValue = true; } else if (receivedValue == null || computedValue == null) { returnValue = false; } else { returnValue = receivedValue.SequenceEqual(computedValue); } if (!returnValue) { AddFailedMessage(status, receivedValue, computedValue); } return(returnValue); }
public override byte[] Deserialize(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status) { byte[] deserializedValue = ArrayOps.GetSubArray(bytes, currentArrayIndex, length); currentArrayIndex += length; return(deserializedValue); }
public override TListType DeserializeList <TListType>(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status) { // If the list type is just a byte array we only need to do the regular byte array if (typeof(TListType) == typeof(byte[])) { return((TListType)(object)Deserialize(bytes, ref currentArrayIndex, length, ref status)); } return(base.DeserializeList <TListType>(bytes, ref currentArrayIndex, length, ref status)); }
public override string Deserialize(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status) { // TODO: In SerializerClassGeneration need to figure out the fieldLengthExpression if (length == -1) { length = GetLength(); } string returnValue = GetStringFromByteArray(bytes, currentArrayIndex, length); currentArrayIndex += length; return(returnValue); }
public virtual TListType DeserializeList <TListType>(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status) where TListType : IList, IEnumerable <T>, new() { TListType returnList = new TListType(); for (int endIndexSomeList = (currentArrayIndex + length); (currentArrayIndex < endIndexSomeList);) { // Note that we don't really have any idea of the length to pass into deserialize for the individual elements // so they have to be able to figure it out for themselves T element = Deserialize(bytes, ref currentArrayIndex, -1, ref status); returnList.Add(element); } return(returnList); }
public abstract T Deserialize(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status);
public override TEnumType Deserialize(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status) { if (length == -1) { length = GetLength(); } TEnumType returnValue = ArrayOps.GetEnum <TEnumType>(bytes, currentArrayIndex, length, _propertyInfo.MessagePropertyAttribute.Endianness); currentArrayIndex += length; return(returnValue); }
public override TNumericType Deserialize(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status) { if (length == -1) { length = GetLength(); } TNumericType returnValue = (TNumericType)Convert.ChangeType(GetValueFromBcdArray(bytes, currentArrayIndex, length), typeof(TNumericType)); currentArrayIndex += length; return(returnValue); }
public override DateTime Deserialize(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status) { // TODO: Should the length parameter be checked against GetOutputLength? int outputLength = GetOutputLength(); DateTime returnValue = DateTime.ParseExact(ArrayOps.GetHexStringFromArray(bytes, currentArrayIndex, outputLength), _propertyInfo.MessagePropertyAttribute.Format, null); currentArrayIndex += outputLength; return(returnValue); }
protected virtual void AddFailedMessage(DeserializeStatus status, TCalculatorResultType receivedValue, TCalculatorResultType computedValue) { status.Messages.Add($"Verify failed on calculated field {_calculatedFieldInfo.CalculatorResultPropertyInfo.PropertyInfo.Name} of type {_name} using calculator {GetType().Name} with received value {ToString(receivedValue)} and computed value {ToString(computedValue)}"); }
public virtual bool Verify(DeserializeStatus status, TCalculatorResultType receivedValue, params byte[][] arrays) { TCalculatorResultType computedValue = Calculate(arrays); return(Verify(status, receivedValue, computedValue)); }
public abstract object Deserialize(byte[] bytes, ref int currentArrayIndex, DeserializeStatus status);
// Called by the generated class when verifying a calculated field protected virtual TListType DeserializeList <TListType, TResultType>(TypeSerializerBase <TResultType> serializer, byte[] bytes, ref int currentArrayIndex, int length, DeserializeStatus status, params List <byte[]>[] arrays) where TListType : IList, IEnumerable <TResultType>, new() { int startArrayIndex = currentArrayIndex; TListType result = serializer.DeserializeList <TListType>(bytes, ref currentArrayIndex, length, ref status); int endArrayIndex = currentArrayIndex; byte[] array = ArrayOps.GetSubArray(bytes, startArrayIndex, endArrayIndex - startArrayIndex); foreach (List <byte[]> currentArray in arrays) { currentArray.Add(array); } return(result); }