Exemple #1
0
        /// <summary>
        /// Is called after a breaking error occurred and the setting ContinueProcessingOnBreakingError is true (in order to find the beginning of the next item).
        /// </summary>
        protected static bool FindNextValidTypeId(Stream stream)
        {
            long lastPos  = stream.Position;
            int  typeByte = stream.ReadByte();

            while (typeByte >= 0 && !MsgPackMeta.IsValidPackageStartByte((byte)typeByte))
            {
                typeByte = stream.ReadByte();
            }

            bool result = (typeByte >= 0);

            if (result)
            {
                stream.Seek(stream.Position - 1, SeekOrigin.Begin);
            }
            return(result);
        }
Exemple #2
0
        private static void ValidateMap(MsgPackItem item, List <ValidationItem> issues)
        {
            MpMap         map          = (MpMap)item;
            MsgPackTypeId firstKeyType = map.PackedValues[0].Key.TypeId;

            if (!MsgPackMeta.StrTypeFamily.Contains(firstKeyType) && !MsgPackMeta.IntTypeFamily.Contains(firstKeyType) && firstKeyType != MsgPackTypeId.MpNull)
            {
                issues.Add(new ValidationItem(item, ValidationSeverity.Comment, 0, "A key of type ", MsgPackItem.GetOfficialTypeName(firstKeyType),
                                              " is rather unusual in a map. Some implementations might only support string or integer types as keys."));
            }
            for (int t = map.PackedValues.Length - 1; t >= 0; t--)
            {
                if (ReferenceEquals(map.PackedValues[t].Key, null))
                {
                    continue;
                }
                if (map.PackedValues[t].Key.TypeId != firstKeyType && !MsgPackMeta.AreInSameFamily(map.PackedValues[t].Key.TypeId, firstKeyType))
                {
                    issues.Add(new ValidationItem(item, ValidationSeverity.Warning, 0,
                                                  "The types of keys in this map do not appear to be consistent. Item 0 has a key of type ", MsgPackItem.GetOfficialTypeName(firstKeyType),
                                                  " while item ", t, " has a key of type ", MsgPackItem.GetOfficialTypeName(map.PackedValues[t].Key.TypeId),
                                                  ". Allthough the specs do not demand that keys are of the same type, it is likely that many implementations will assume that keys in a map are all of the same family."));
                }
                for (int i = t - 1; i >= 0; i--)
                {
                    if (ReferenceEquals(map.PackedValues[t].Key, null) || ReferenceEquals(map.PackedValues[i].Key, null) || ReferenceEquals(map.PackedValues[t].Key.Value, null))
                    {
                        continue;
                    }
                    if (map.PackedValues[t].Key.Value.Equals(map.PackedValues[i].Key.Value))
                    {
                        issues.Add(new ValidationItem(item, ValidationSeverity.Warning, 0, "This map has multiple entries with identical keys (items ",
                                                      i, "='", map.PackedValues[i].Key.ToString(), "' and ", t, "='", map.PackedValues[t].Key.ToString(), "'). Allthough the specs do not demand unique keys, it is likely that many implementations will assume that keys in a map are unique."));
                    }
                }
            }
        }