示例#1
0
            public static object GetObject(CollectionItemType itemType, ComplianceSerializer.CollectionItem item)
            {
                switch (itemType)
                {
                case CollectionItemType.Short:
                    return(ComplianceSerializer.ReadShortFromBlob(item.ItemBlob, 0));

                case CollectionItemType.Int:
                    return(ComplianceSerializer.ReadIntFromBlob(item.ItemBlob, 0));

                case CollectionItemType.Long:
                    return(ComplianceSerializer.ReadLongFromBlob(item.ItemBlob, 0));

                case CollectionItemType.Double:
                    return(ComplianceSerializer.ReadDoubleFromBlob(item.ItemBlob, 0));

                case CollectionItemType.Guid:
                    return(ComplianceSerializer.ReadGuidFromBlob(item.ItemBlob, 0));

                case CollectionItemType.String:
                    return(Encoding.UTF8.GetString(item.ItemBlob));

                case CollectionItemType.Blob:
                    return(item.ItemBlob);

                default:
                    return(null);
                }
            }
示例#2
0
        private static bool TryWriteVariableWidthMembersToObject <T>(ref ComplianceSerializationDescription <T> description, ref T parsedObject, byte[] blob, int startIndex, int totalLength, ComplianceSerializer.VariableWidthType widthType, bool continueDeserialization, out int index, ref StringBuilder errorBuilder) where T : class, new()
        {
            if (!continueDeserialization)
            {
                index = startIndex;
                return(continueDeserialization);
            }
            index = startIndex;
            if (startIndex >= totalLength)
            {
                errorBuilder.AppendFormat("StartIndex:{0} is bigger than blob length:{1}", startIndex, totalLength);
                return(false);
            }
            byte b = blob[index++];

            if (b > 0)
            {
                List <int> list = new List <int>();
                for (byte b2 = 0; b2 < b; b2 += 1)
                {
                    if (index + 4 > totalLength)
                    {
                        errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the field-width from index:{1}.", totalLength, index);
                        return(false);
                    }
                    int item = ComplianceSerializer.ReadIntFromBlob(blob, index);
                    list.Add(item);
                    index += 4;
                }
                byte b3 = 0;
                foreach (int num in list)
                {
                    if (num > 0)
                    {
                        if (index + num > totalLength)
                        {
                            errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the field of size:{1} from index:{2}.", totalLength, num, index);
                            return(false);
                        }
                        if (widthType == ComplianceSerializer.VariableWidthType.String)
                        {
                            string @string = Encoding.UTF8.GetString(blob, index, num);
                            description.TrySetStringProperty(parsedObject, b3, @string);
                            index += num;
                        }
                        else
                        {
                            byte[] array = new byte[num];
                            Array.Copy(blob, index, array, 0, num);
                            description.TrySetBlobProperty(parsedObject, b3, array);
                            index += num;
                        }
                    }
                    b3 += 1;
                }
                return(true);
            }
            return(true);
        }
示例#3
0
            public static bool TryGetCollectionItemFromBlob(CollectionItemType itemType, byte[] blob, int index, int totalLength, out ComplianceSerializer.CollectionItem item, ref StringBuilder errorBuilder)
            {
                item = new ComplianceSerializer.CollectionItem();
                int num  = 0;
                int num2 = 0;

                switch (itemType)
                {
                case CollectionItemType.Short:
                    item.IsFixedWidth = true;
                    num = 2;
                    break;

                case CollectionItemType.Int:
                    item.IsFixedWidth = true;
                    num = 4;
                    break;

                case CollectionItemType.Long:
                    item.IsFixedWidth = true;
                    num = 8;
                    break;

                case CollectionItemType.Double:
                    item.IsFixedWidth = true;
                    num = 8;
                    break;

                case CollectionItemType.Guid:
                    item.IsFixedWidth = true;
                    num = 16;
                    break;

                case CollectionItemType.String:
                case CollectionItemType.Blob:
                    item.IsFixedWidth = false;
                    num2 = 4;
                    if (index + num2 > totalLength)
                    {
                        errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the collection item width at index:{1}", totalLength, index);
                        return(false);
                    }
                    num = ComplianceSerializer.ReadIntFromBlob(blob, index);
                    break;
                }
                item.ItemBlob = new byte[num];
                if (index + num2 + num > totalLength)
                {
                    errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the collection item at index:{1}", totalLength, index + num2);
                    return(false);
                }
                Array.Copy(blob, index + num2, item.ItemBlob, 0, num);
                return(true);
            }
示例#4
0
        private static bool TryWriteCollectionsToObject <T>(ref ComplianceSerializationDescription <T> description, ref T parsedObject, byte[] blob, int startIndex, int totalLength, out int index, ref StringBuilder errorBuilder) where T : class, new()
        {
            index = startIndex;
            if (startIndex >= totalLength)
            {
                errorBuilder.AppendFormat("StartIndex:{0} is bigger than blob length:{1}", startIndex, totalLength);
                return(false);
            }
            byte b = blob[index++];

            for (byte b2 = 0; b2 < b; b2 += 1)
            {
                Type typeFromHandle = typeof(CollectionItemType);
                CollectionItemType collectionItemType = (CollectionItemType)Enum.ToObject(typeFromHandle, blob[index++]);
                if (!Enum.IsDefined(typeFromHandle, collectionItemType))
                {
                    errorBuilder.AppendFormat("Byte value:{0} at index:{1} does not represent a valid CollectionItemType", collectionItemType, index - 1);
                    return(false);
                }
                if (index + 4 > totalLength)
                {
                    errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the field count:{1} at index:{2}.", totalLength, b, index);
                    return(false);
                }
                int num = ComplianceSerializer.ReadIntFromBlob(blob, index);
                index += 4;
                List <object> list = new List <object>();
                for (int i = 0; i < num; i++)
                {
                    ComplianceSerializer.CollectionItem collectionItem = null;
                    if (!ComplianceSerializer.CollectionItem.TryGetCollectionItemFromBlob(collectionItemType, blob, index, totalLength, out collectionItem, ref errorBuilder))
                    {
                        return(false);
                    }
                    list.Add(ComplianceSerializer.CollectionItem.GetObject(collectionItemType, collectionItem));
                    index += collectionItem.GetSerializedSize();
                }
                description.TrySetCollectionItems(parsedObject, b2, list);
            }
            return(true);
        }
示例#5
0
        private static bool TryWriteFixedWidthFieldsToObject <T>(ref ComplianceSerializationDescription <T> description, ref T parsedObject, byte[] blob, int startIndex, int width, ComplianceSerializer.FixedWidthType widthType, int totalLength, bool continueDeserialization, out int index, ref StringBuilder errorBuilder) where T : class, new()
        {
            if (!continueDeserialization)
            {
                index = startIndex;
                return(continueDeserialization);
            }
            index = startIndex;
            if (startIndex >= totalLength)
            {
                errorBuilder.AppendFormat("StartIndex:{0} is bigger than blob length:{1}", startIndex, totalLength);
                return(false);
            }
            byte b = blob[startIndex];

            index++;
            for (byte b2 = 0; b2 < b; b2 += 1)
            {
                if (index + width > totalLength)
                {
                    errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the field from index:{1}.", totalLength, index);
                    return(false);
                }
                switch (widthType)
                {
                case ComplianceSerializer.FixedWidthType.Byte:
                    description.TrySetByteProperty(parsedObject, b2, blob[index]);
                    break;

                case ComplianceSerializer.FixedWidthType.Short:
                {
                    short value = ComplianceSerializer.ReadShortFromBlob(blob, index);
                    description.TrySetShortProperty(parsedObject, b2, value);
                    break;
                }

                case ComplianceSerializer.FixedWidthType.Int:
                {
                    int value2 = ComplianceSerializer.ReadIntFromBlob(blob, index);
                    description.TrySetIntegerProperty(parsedObject, b2, value2);
                    break;
                }

                case ComplianceSerializer.FixedWidthType.Long:
                {
                    long value3 = ComplianceSerializer.ReadLongFromBlob(blob, index);
                    description.TrySetLongProperty(parsedObject, b2, value3);
                    break;
                }

                case ComplianceSerializer.FixedWidthType.Double:
                {
                    double value4 = ComplianceSerializer.ReadDoubleFromBlob(blob, index);
                    description.TrySetDoubleProperty(parsedObject, b2, value4);
                    break;
                }

                case ComplianceSerializer.FixedWidthType.Guid:
                {
                    Guid value5 = ComplianceSerializer.ReadGuidFromBlob(blob, index);
                    description.TrySetGuidProperty(parsedObject, b2, value5);
                    break;
                }

                default:
                    throw new ArgumentException("widthType");
                }
                index += width;
            }
            return(true);
        }