예제 #1
0
        public virtual bool Verify(DeserializeStatus status, TCalculatorResultType receivedValue, TCalculatorResultType computedValue)
        {
            bool success = receivedValue.Equals(computedValue);

            if (!success)
            {
                AddFailedMessage(status, receivedValue, computedValue);
            }

            return(success);
        }
예제 #2
0
        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);
        }
예제 #3
0
 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);
 }
예제 #4
0
 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));
 }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
 public abstract T Deserialize(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status);
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
 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)}");
 }
예제 #12
0
        public virtual bool Verify(DeserializeStatus status, TCalculatorResultType receivedValue, params byte[][] arrays)
        {
            TCalculatorResultType computedValue = Calculate(arrays);

            return(Verify(status, receivedValue, computedValue));
        }
예제 #13
0
 public abstract object Deserialize(byte[] bytes, ref int currentArrayIndex, DeserializeStatus status);
예제 #14
0
        // 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);
        }