示例#1
0
        private static unsafe bool TryConvertStringValue(string value, out object output)
        {
            output = null;

            fixed(char *str = value)
            {
                var result = LazyStringParser.TryParseDateTime(str, value.Length, out DateTime dt, out DateTimeOffset dto);

                if (result == LazyStringParser.Result.DateTime)
                {
                    output = dt;
                }
                if (result == LazyStringParser.Result.DateTimeOffset)
                {
                    output = dto;
                }

                if (LazyStringParser.TryParseTimeSpan(str, value.Length, out var ts))
                {
                    output = ts;
                }
            }

            return(output != null);
        }
示例#2
0
        private static unsafe object ConvertLazyStringValue(LazyStringValue value)
        {
            var buffer = value.Buffer;
            var size   = value.Size;

            var result = LazyStringParser.TryParseDateTime(buffer, size, out DateTime dt, out DateTimeOffset dto);

            if (result == LazyStringParser.Result.DateTime)
            {
                return(dt);
            }
            if (result == LazyStringParser.Result.DateTimeOffset)
            {
                return(dto);
            }

            if (LazyStringParser.TryParseTimeSpan(buffer, size, out TimeSpan ts))
            {
                return(ts);
            }

            return(value); // ensure that the decompressed lazy string value is returned
        }
示例#3
0
        public static unsafe object ConvertForIndexing(object value)
        {
            if (value == null)
            {
                return(null);
            }

            var blittableJsonObject = value as BlittableJsonReaderObject;

            if (blittableJsonObject != null)
            {
                if (blittableJsonObject.TryGet(TypePropertyName, out string type) == false)
                {
                    return(blittableJsonObject);
                }

                if (type == null)
                {
                    return(blittableJsonObject);
                }

                if (type.StartsWith(TypeList) == false)
                {
                    return(blittableJsonObject);
                }

                if (blittableJsonObject.TryGet(ValuesPropertyName, out BlittableJsonReaderArray values))
                {
                    return(values);
                }

                throw new NotSupportedException($"Detected list type '{type}' but could not extract '{values}'.");
            }

            var lazyString = value as LazyStringValue;

            if (lazyString == null)
            {
                var lazyCompressedStringValue = value as LazyCompressedStringValue;
                if (lazyCompressedStringValue != null)
                {
                    lazyString = lazyCompressedStringValue.ToLazyStringValue();
                }
            }

            if (lazyString != null)
            {
                var result = LazyStringParser.TryParseDateTime(lazyString.Buffer, lazyString.Size, out DateTime dt, out DateTimeOffset dto);
                if (result == LazyStringParser.Result.DateTime)
                {
                    return(dt);
                }
                if (result == LazyStringParser.Result.DateTimeOffset)
                {
                    return(dto);
                }

                if (LazyStringParser.TryParseTimeSpan(lazyString.Buffer, lazyString.Size, out TimeSpan ts))
                {
                    return(ts);
                }

                return(lazyString); // ensure that the decompressed lazy string value is returned
            }

            if (value is string s)
            {
                fixed(char *str = s)
                {
                    var result = LazyStringParser.TryParseDateTime(str, s.Length, out DateTime dt, out DateTimeOffset dto);

                    if (result == LazyStringParser.Result.DateTime)
                    {
                        return(dt);
                    }
                    if (result == LazyStringParser.Result.DateTimeOffset)
                    {
                        return(dto);
                    }

                    if (LazyStringParser.TryParseTimeSpan(str, s.Length, out TimeSpan ts))
                    {
                        return(ts);
                    }
                }
            }

            return(value);
        }
示例#4
0
        public static unsafe object ConvertForIndexing(object value)
        {
            if (value == null)
            {
                return(null);
            }

            var blittableJsonObject = value as BlittableJsonReaderObject;

            if (blittableJsonObject != null)
            {
                string type;
                if (blittableJsonObject.TryGet(TypePropertyName, out type) == false)
                {
                    return(blittableJsonObject);
                }

                if (type == null)
                {
                    return(blittableJsonObject);
                }

                if (type.StartsWith(TypeList) == false)
                {
                    return(blittableJsonObject);
                }

                // TODO [ppekrol] probably we will have to support many more cases here

                BlittableJsonReaderArray values;
                if (blittableJsonObject.TryGet(ValuesPropertyName, out values))
                {
                    return(values);
                }

                throw new NotSupportedException($"Detected list type '{type}' but could not extract '{values}'.");
            }

            var lazyString = value as LazyStringValue;

            if (lazyString == null)
            {
                var lazyCompressedStringValue = value as LazyCompressedStringValue;
                if (lazyCompressedStringValue != null)
                {
                    lazyString = lazyCompressedStringValue.ToLazyStringValue();
                }
            }

            if (lazyString != null)
            {
                DateTime       dt;
                DateTimeOffset dto;
                switch (LazyStringParser.TryParseDateTime(lazyString.Buffer, lazyString.Size, out dt, out dto))
                {
                case LazyStringParser.Result.DateTime:
                    return(dt);

                case LazyStringParser.Result.DateTimeOffset:
                    return(dto);
                }

                TimeSpan ts;
                if (LazyStringParser.TryParseTimeSpan(lazyString.Buffer, lazyString.Size, out ts))
                {
                    return(ts);
                }
            }

            return(value);
        }