private static FLSlice TypeForDict(FLDict *dict, SharedStringCache sharedKeys)
        {
            var typeKey = FLSlice.Constant(Constants.ObjectTypeProperty);
            var type    = sharedKeys != null
                ? sharedKeys.GetDictValue(dict, typeKey)
                : NativeRaw.FLDict_Get(dict, typeKey);

            return(NativeRaw.FLValue_AsString(type));
        }
 public JsonFLValueReader(FLValue *root, SharedStringCache stringCache)
 {
     _currentValue = root;
     _stringCache  = stringCache;
 }
Exemplo n.º 3
0
 public SharedStringCache(SharedStringCache other, FLDict *root)
     : this(other)
 {
     _root = root;
 }
Exemplo n.º 4
0
 public SharedStringCache(SharedStringCache other)
 {
     Debug.Assert(other != null);
     SharedKeys = other.SharedKeys;
 }
        private static object ToObject(FLValue *value, SharedStringCache sharedKeys, int level = 0, Type hintType1 = null)
        {
            if (value == null)
            {
                return(null);
            }

            switch (Native.FLValue_GetType(value))
            {
            case FLValueType.Array: {
                var arr      = Native.FLValue_AsArray(value);
                var hintType = level == 0 && hintType1 != null ? hintType1 : typeof(object);
                var count    = (int)Native.FLArray_Count(arr);
                if (count == 0)
                {
                    return(new List <object>());
                }

                var retVal =
                    (IList)Activator.CreateInstance(typeof(List <>).GetTypeInfo().MakeGenericType(hintType),
                                                    count);

                var i = default(FLArrayIterator);
                Native.FLArrayIterator_Begin(arr, &i);
                do
                {
                    retVal.Add(ToObject(Native.FLArrayIterator_GetValue(&i), sharedKeys, level + 1, hintType1));
                } while (Native.FLArrayIterator_Next(&i));

                return(retVal);
            }

            case FLValueType.Boolean:
                return(Native.FLValue_AsBool(value));

            case FLValueType.Data:
                return(Native.FLValue_AsData(value));

            case FLValueType.Dict: {
                var dict     = Native.FLValue_AsDict(value);
                var hintType = level == 0 && hintType1 != null ? hintType1 : typeof(object);
                var count    = (int)Native.FLDict_Count(dict);
                if (count == 0)
                {
                    return(new Dictionary <string, object>());
                }

                var retVal = (IDictionary)Activator.CreateInstance(typeof(Dictionary <,>).MakeGenericType(typeof(string), hintType), count);
                var i      = default(FLDictIterator);
                Native.FLDictIterator_Begin(dict, &i);
                do
                {
                    var    rawKey = Native.FLDictIterator_GetKey(&i);
                    string key;
                    if (Native.FLValue_GetType(rawKey) == FLValueType.Number)
                    {
                        key = sharedKeys.GetKey((int)Native.FLValue_AsInt(rawKey));
                        if (key == null)
                        {
                            Log.To.Database.W(Tag, "Corrupt key found during deserialization, skipping...");
                            continue;
                        }
                    }
                    else
                    {
                        key = Native.FLValue_AsString(rawKey);
                    }

                    retVal[key] = ToObject(Native.FLDictIterator_GetValue(&i), sharedKeys, level + 1, hintType1);
                } while (Native.FLDictIterator_Next(&i));

                return(retVal);
            }

            case FLValueType.Null:
                return(null);

            case FLValueType.Number:
                if (Native.FLValue_IsInteger(value))
                {
                    if (Native.FLValue_IsUnsigned(value))
                    {
                        return(Native.FLValue_AsUnsigned(value));
                    }

                    return(Native.FLValue_AsInt(value));
                }
                else if (Native.FLValue_IsDouble(value))
                {
                    return(Native.FLValue_AsDouble(value));
                }

                return(Native.FLValue_AsFloat(value));

            case FLValueType.String:
                return(Native.FLValue_AsString(value));

            default:
                return(null);
            }
        }