Beispiel #1
0
        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);
        }
Beispiel #2
0
 public bool TryParseDynamicPropertyValue(byte[] array, IDynamicContractValue msg, out IDynamicMemberValue value)
 {
     Protocol.Buffer.BitArray buffer = new Protocol.Buffer.BitArray(array);
     return(TryParseDynamicPropertyValue(buffer, msg, out value));
 }