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)); }; }
public void WriteStructs() { var w = JWriter.New(); WriteStructs(w, ListOfStructs); var s = w.GetString(); }
public void WriteBools() { var w = JWriter.New(); WriteBools(w, ListOfBools); var s = w.GetString(); }
public string SerializeOutputEvents(object[] events, EventSummary summary, out int eventCountOut) { var jsonWriter = JWriter.New(); var scope = new EventOutputFormatterScope(_config, jsonWriter, _config.InlineUsersInEvents); eventCountOut = scope.WriteOutputEvents(events, summary); return(jsonWriter.GetString()); }
internal static string MakeJsonData(FullDataSet data) { var w = JWriter.New(); using (var ow = w.Object()) { foreach (var item in data.Items) { if (item.Value.Item != null) { FeatureFlagJsonConverter.WriteJsonValue(item.Value.Item, ow.Name(item.Key)); } } } return(w.GetString()); }
/// <summary> /// Converts the value to its JSON encoding. /// </summary> /// <remarks> /// For instance, <c>LdValue.Of(1).ToJsonString()</c> returns <c>"1"</c>; /// <c>LdValue.Of("x").ToJsonString()</c> returns <c>"\"x\""</c>; and /// <c>LdValue.Null.ToJsonString()</c> returns <c>"null"</c>. /// </remarks> /// <returns>the JSON encoding of the value</returns> /// <see cref="Parse(string)"/> public string ToJsonString() { switch (_type) { case LdValueType.Null: return("null"); case LdValueType.Bool: return(_boolValue ? "true" : "false"); default: var writer = JWriter.New(); LdJsonConverters.LdValueConverter.WriteJsonValue(this, writer); return(writer.GetString()); } }
/// <summary> /// Returns a JSON representation of the user index. /// </summary> /// <returns>the JSON representation</returns> public string Serialize() { var w = JWriter.New(); using (var aw0 = w.Array()) { foreach (var e in Data) { using (var aw1 = aw0.Array()) { aw1.String(e.UserId); aw1.Long(e.Timestamp.Value); } } } return(w.GetString()); }