/// <summary>
        /// Initializes a new instance of the <see cref="ArrayTypeValue"/> class.
        /// Values are decoded from the byte store
        /// </summary>
        /// <param name="theArrayTypeDefinition">The array type definition.</param>
        /// <param name="theBytes">The bytes.</param>
        /// <param name="parent">The parent.</param>
        public ArrayTypeValue(ArrayTypeDefinition theArrayTypeDefinition, ByteStore theBytes, Value parent)
            : base(theArrayTypeDefinition, parent)
        {
            m_ArrayTypeDefinition = theArrayTypeDefinition;

            m_ArrayValues = new ArrayValueContainer(m_ArrayTypeDefinition.UpperBound);

            if (m_ArrayTypeDefinition.Rank > 0)
            {
                // Fixed-size arrays - populate with decoded elements of the base type
                m_ArrayValues.Populate(() => m_ArrayTypeDefinition.ElementType.Decode(theBytes, this));
            }
            else if (!string.IsNullOrEmpty(m_ArrayTypeDefinition.UpperBoundVariable))
            {
                // Variable size array. Locate the discriminator if there is one
                // TODO
            }
            else
            {
                // Variable size array - number of elements limited by the number of bytes available or an end marker being discovered
                bool done = false;

                do
                {
                    Value theValue = m_ArrayTypeDefinition.ElementType.Decode(theBytes, this);
                    m_ArrayValues.Add(theValue);

                    if (theValue.FundamentalType.TypeId == TypeId.StructType)
                    {
                        done = IsEndMarker(theValue as StructureValue);
                    }
                }
                while (!done);
            }
        }
        /// <summary>
        /// Creates a new Value object, deriving the value by decoding the specified bytes.
        /// Each derived class creates its corresponding value type
        /// </summary>
        /// <param name="theBytes">The collection of bytes containing the value to be decoded</param>
        /// <param name="parent">The parent.</param>
        /// <returns>
        /// The decoded value object
        /// </returns>
        public override Value Decode(ByteStore theBytes, Value parent)
        {
            TypeDefinition baseType = DictionaryManager.DereferenceTypeDef(this);
            Value theValue = baseType.Decode(theBytes, parent);
            theValue.OverrideInitialType(this);

            return theValue;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StringValue"/> class.
        /// </summary>
        /// <param name="theBytes">The bytes.</param>
        /// <param name="theStringDefinition">The string definition.</param>
        /// <param name="parent">The parent.</param>
        public StringValue(ByteStore theBytes, StringDefinition theStringDefinition, Value parent)
            : base(theStringDefinition, parent)
        {
            List<Byte> stringBytes = new List<byte>();

            // Read bytes until they run out or we hit null terminator
            Byte theByte = 0xff;
            while (theBytes.ReadPosition < theBytes.PayloadLength && theByte != '\0')
            {
                theByte = theBytes.GetByte();
                stringBytes.Add(theByte);
            }

            m_Value = Encoding.ASCII.GetString(stringBytes.ToArray());
        }
 /// <summary>
 /// Creates a new Value object, deriving the value by decoding the specified bytes.
 /// Each derived class creates its corresponding value type
 /// </summary>
 /// <param name="theBytes">The collection of bytes containing the value to be
 /// decoded</param>
 /// <param name="parent"></param>
 /// <returns>
 /// The decoded value object
 /// </returns>
 public override Value Decode(ByteStore theBytes, Value parent)
 {
     return new EnumValue(this, theBytes, parent);
 }
 /// <summary>
 /// Encodes the value into the list of bytes
 /// </summary>
 /// <param name="theBytes"></param>
 public override void Encode(ByteStore theBytes)
 {
     foreach (var arrayItem in m_ArrayValues)
     {
         arrayItem.Encode(theBytes);
     }
 }
        /// <summary>
        /// Creates a new Value object, deriving the value by decoding the specified bytes.
        /// Each derived class creates its corresponding value type
        /// </summary>
        /// <param name="theBytes">The collection of bytes containing the value to be
        /// decoded</param>
        /// <param name="parent"></param>
        /// <returns>
        /// The decoded value object
        /// </returns>
        public override Value Decode(ByteStore theBytes, Value parent)
        {
            // Find the discriminator for the switch and look up its value
            StructureValue theParentStruct = parent as StructureValue;
            if (theParentStruct == null)
            {
                throw new DataDictionaryException("SwitchDefinition {0}: Parent {1} is not a struct value",
                    Name, parent.FundamentalType.Name);
            }

            SwitchCaseDefinition caseDefinition = GetSwitchCaseDefinition(theParentStruct);

            if (caseDefinition == null)
            {
                throw new DataDictionaryException("SwitchDefinition {0}: case value not found", Name);
            }

            TypeDefinition typeToDecode = caseDefinition.Type;
            return typeToDecode.Decode(theBytes, parent);
        }
 /// <summary>
 /// Encodes the value into the list of bytes
 /// </summary>
 /// <param name="theBytes">The bytes.</param>
 public override void Encode(ByteStore theBytes)
 {
     m_WrappedValue.Encode(theBytes);
 }
        /// <summary>
        /// Encodes the value into the list of bytes
        /// </summary>
        /// <param name="theBytes"></param>
        public override void Encode(ByteStore theBytes)
        {
            ulong tempValue = 0;
            tempValue = m_BaseTypeDefinition.IsSigned ? (ulong)SignedValue : UnsignedValue;

            switch (GetSizeBytes())
            {
                case 0:
                    // 0-size end marker
                    break;
                case 1:
                    theBytes.PutByte((byte)tempValue);
                    break;
                case 2:
                    theBytes.PutUint16((ushort)tempValue);
                    break;
                case 4:
                    theBytes.PutUint32((uint)tempValue);
                    break;
                case 8:
                    theBytes.PutUint64(tempValue);
                    break;
                default:
                    throw new DataDictionaryException(String.Format("{0} Illegal ByteSize {1}",
                        m_BaseTypeDefinition.Name,
                        GetSizeBytes()));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseTypeValue"/> class with
        /// values extracted from the byte store
        /// </summary>
        /// <param name="baseTypeDefinition">The base type definition.</param>
        /// <param name="theBytes">The bytes.</param>
        /// <param name="parent">The parent.</param>
        public BaseTypeValue(BaseTypeDefinition baseTypeDefinition, ByteStore theBytes, Value parent)
            : this(baseTypeDefinition, parent)
        {
            ulong tempValue = 0;
            switch (m_BaseTypeDefinition.FixedSizeBytes.Value)
            {
                case 0:
                    // Special case for end-markers for lists of elements
                    break;
                case 1:
                    tempValue = theBytes.GetByte();
                    break;
                case 2:
                    tempValue = theBytes.GetUint16();
                    break;
                case 4:
                    tempValue = theBytes.GetUint32();
                    break;
                case 8:
                    tempValue = theBytes.GetUint64();
                    break;
                default:
                    throw new DataDictionaryException(String.Format("{0} Illegal ByteSize {1}",
                        m_BaseTypeDefinition.Name,
                        m_BaseTypeDefinition.FixedSizeBytes.Value));
            }

            if (m_BaseTypeDefinition.IsSigned)
            {
                SignedValue = (long)tempValue;
            }
            else
            {
                UnsignedValue = tempValue;
            }
        }
Example #10
0
 /// <summary>
 /// Encodes the value into the list of bytes
 /// </summary>
 /// <param name="theBytes">The bytes.</param>
 public virtual void Encode(ByteStore theBytes)
 {
     throw new NotImplementedException();
 }
Example #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EnumValue"/> class by extracting the
        /// encoded value from the byte store
        /// </summary>
        /// <param name="theEnumDefinition">The enum definition.</param>
        /// <param name="theBytes">The bytes.</param>
        /// <param name="parent">The parent.</param>
        public EnumValue(EnumDefinition theEnumDefinition, ByteStore theBytes, Value parent)
            : this(theEnumDefinition, parent)
        {
            switch (theEnumDefinition.FixedSizeBytes)
            {
                case 1:
                    IntegerValue = (int)theBytes.GetByte();
                    break;
                case 2:
                    IntegerValue = (int)theBytes.GetUint16();
                    break;
                case 4:
                    IntegerValue = (int)theBytes.GetUint32();
                    break;
                default:
                    throw new DataDictionaryException(string.Format("Illegal byte size {0} for enum {1}", theEnumDefinition.FixedSizeBytes, m_EnumDefinition.Name));
            }

            StringValue = m_EnumDefinition.IntegerValueToString(IntegerValue);
        }
Example #12
0
 /// <summary>
 /// Encodes the value into the list of bytes
 /// </summary>
 /// <param name="theBytes"></param>
 public override void Encode(ByteStore theBytes)
 {
     switch (GetSizeBytes())
     {
         case 1:
             theBytes.PutByte((byte) IntegerValue);
             break;
         case 2:
             theBytes.PutUint16((ushort) IntegerValue);
             break;
         case 4:
             theBytes.PutUint32((uint) IntegerValue);
             break;
         default:
             throw new DataDictionaryException(string.Format("Illegal byte size {0} for enum {1}", GetSizeBytes(), m_EnumDefinition.Name));
     }
 }
 /// <summary>
 /// Creates a new Value object, deriving the value by decoding the specified bytes.
 /// Each derived class creates its corresponding value type
 /// </summary>
 /// <param name="theBytes">The collection of bytes containing the value to be decoded</param>
 /// <param name="parent">The parent.</param>
 /// <returns>
 /// The decoded value object
 /// </returns>
 public virtual Value Decode(ByteStore theBytes, Value parent)
 {
     throw new DataDictionaryException("Cannot decode type {0}", Name);
 }