Example #1
0
 internal DataKind(
     string name,
     SerializerToJWriter internalSerializer,
     DeserializerFromJReader internalDeserializer)
 {
     _name = name;
     _internalSerializer   = internalSerializer;
     _internalDeserializer = internalDeserializer;
     _serializer           = item =>
     {
         var w = JWriter.New();
         if (item.Item is null)
         {
             var obj = w.Object();
             obj.Name("version").Int(item.Version);
             obj.Name("deleted").Bool(true);
             obj.End();
         }
         else
         {
             internalSerializer(item.Item, w);
         }
         return(w.GetString());
     };
     _deserializer = s =>
     {
         var r = JReader.FromString(s);
         return(_internalDeserializer(ref r));
     };
 }
        /// <summary>
        /// Parses the user index from a JSON representation. If the JSON string is null or
        /// empty, it returns an empty user index.
        /// </summary>
        /// <param name="json">the JSON representation</param>
        /// <returns>the parsed data</returns>
        /// <exception cref="FormatException">if the JSON is malformed</exception>
        public static UserIndex Deserialize(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return(new UserIndex());
            }
            var builder = ImmutableList.CreateBuilder <IndexEntry>();

            try
            {
                var r = JReader.FromString(json);
                for (var ar0 = r.Array(); ar0.Next(ref r);)
                {
                    var ar1 = r.Array();
                    if (ar1.Next(ref r))
                    {
                        var userId = r.String();
                        if (ar1.Next(ref r))
                        {
                            var timeMillis = r.Long();
                            builder.Add(new IndexEntry {
                                UserId = userId, Timestamp = UnixMillisecondTime.OfMillis(timeMillis)
                            });
                            ar1.Next(ref r);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new FormatException("invalid stored user index", e);
            }
            return(new UserIndex(builder.ToImmutable()));
        }
Example #3
0
        // Currently there is only one serialization schema, but it is possible that future
        // SDK versions will require a richer model. In that case we will need to design the
        // serialized format to be distinguishable from previous formats and allow reading
        // of older formats, while only writing the new format.

        internal static FullDataSet DeserializeV1Schema(string serializedData)
        {
            var builder = ImmutableList.CreateBuilder <KeyValuePair <string, ItemDescriptor> >();
            var r       = JReader.FromString(serializedData);

            try
            {
                for (var or = r.Object(); or.Next(ref r);)
                {
                    var flag = FeatureFlagJsonConverter.ReadJsonValue(ref r);
                    builder.Add(new KeyValuePair <string, ItemDescriptor>(or.Name.ToString(), flag.ToItemDescriptor()));
                }
            }
            catch (Exception e)
            {
                throw new InvalidDataException(ParseErrorMessage, r.TranslateException(e));
            }
            return(new FullDataSet(builder.ToImmutable()));
        }
Example #4
0
        private FullDataSet <ItemDescriptor> ParseAllData(string json)
        {
            var r = JReader.FromString(json);

            return(StreamProcessorEvents.ParseFullDataset(ref r));
        }
        private static FullDataSet <ItemDescriptor> ParseJson(string data, int version)
        {
            var r = JReader.FromString(data);

            return(ParseJson(ref r, version));
        }
 public void ReadStructs()
 {
     var r      = JReader.FromString(ListOfStructsJson);
     var values = ReadStructs(ref r);
 }
 public void ReadBools()
 {
     var r      = JReader.FromString(ListOfBoolsJson);
     var values = ReadBools(ref r);
 }
        private static FlagFileData ParseJson(string data)
        {
            var r = JReader.FromString(data);

            return(ParseJson(ref r));
        }