Esempio n. 1
0
            internal void DeserializeEntry(List <string> row)
            {
                int propertyOffset = ParentCollection.CollectionOffset;
                int collectionEnd  = ParentCollection.CollectionWidth + ParentCollection.CollectionOffset;

                foreach (KeyValuePair <string, int> kvp in ParentCollection.PropertyToWidthMap)
                {
                    string            propertyName  = kvp.Key;
                    int               propertyWidth = kvp.Value;
                    ListSpan <string> propertyVals  = row.GetSpan(propertyOffset, propertyOffset + propertyWidth);
                    DeserializeProperty(propertyName, propertyVals);
                    propertyOffset += propertyWidth;
                }
            }
Esempio n. 2
0
        public static byte[] DecodeBytes(IReadOnlyList <int> vals, int numBase, out int skipCount, int numOfdigitsToEncodeLength = 2)
        {
            int digitsPerByte = (int)Math.Ceiling(Math.Log(256, numBase));
            int byteCount     = DecodeInt(vals, numBase, numOfdigitsToEncodeLength);

            byte[] res = new byte[byteCount];
            for (int i = 0; i < byteCount; ++i)
            {
                int beg  = i * digitsPerByte + numOfdigitsToEncodeLength;
                int end  = (i + 1) * digitsPerByte + numOfdigitsToEncodeLength;
                var span = new ListSpan <int>(vals, beg, end);
                res[i] = (byte)DecodeInt(span, numBase, digitsPerByte);
            }

            skipCount = numOfdigitsToEncodeLength + digitsPerByte * byteCount;

            return(res);
        }
Esempio n. 3
0
            private void DeserializeProperty(string propertyName, ListSpan <string> propertyVals)
            {
                string firstPropertyVal = propertyVals.First();

                if (firstPropertyVal == null)
                {
                    return; //Empty entry
                }
                //Without an object we can't do much to interpret these
                // there's either raw or strings
                // raw could be strings, but might be numerical types.
                // strings might be strings, or objects
                if (propertyVals.Count == 1)
                {
                    if (firstPropertyVal == null)
                    {
                        return;
                    }
                    this[propertyName] = DeserializeString(firstPropertyVal);
                    return;
                }
                // Collections contain in the first element
                // the number of elements

                int count;

                if (firstPropertyVal == _NullRepresentation)
                {
                    //Null collection
                    this[propertyName] = null;
                    return;
                }
                else if (!int.TryParse(firstPropertyVal, out count))
                {
                    throw new FormatException($"Property '{propertyName}' has more than one value, " +
                                              $"but the first value does not represent a number. Value {firstPropertyVal}");
                }

                this[propertyName] = propertyVals
                                     .Skip(1)
                                     .Take(count)
                                     .Select(DeserializeString)
                                     .ToArray();
            }