public static void SetupBondJson( out Action <object, ChunkedMemoryStream> serialize, out Func <ChunkedMemoryStream, Type, object> deserialize) { var serializers = new Dictionary <Type, Bond.Serializer <SimpleJsonWriter> >(); var deserializers = new Dictionary <Type, Bond.Deserializer <SimpleJsonReader> >(); serialize = (obj, stream) => { var jsonWriter = new SimpleJsonWriter(stream); var type = obj.GetType(); Bond.Serializer <SimpleJsonWriter> serializer; if (!serializers.TryGetValue(type, out serializer)) { serializers[type] = serializer = new Bond.Serializer <SimpleJsonWriter>(type); } serializer.Serialize(obj, jsonWriter); jsonWriter.Flush(); }; deserialize = (stream, type) => { var reader = new SimpleJsonReader(stream); Bond.Deserializer <SimpleJsonReader> deserializer; if (!deserializers.TryGetValue(type, out deserializer)) { deserializers[type] = deserializer = new Bond.Deserializer <SimpleJsonReader>(type); } return(deserializer.Deserialize(reader)); }; }
public string Get(string str) { /*if (str == "foo") * return "bar"; * else * return "no bar"; */ // Convert string to json var reader = new SimpleJsonReader(new StringReader(str)); // Deserialize the json to record var readRecord = Deserialize <Record> .From(reader); // Change record readRecord.Name = "Changed"; // Convert json back to string var jsonString = new StringBuilder(); var jsonWriter = new SimpleJsonWriter(new StringWriter(jsonString)); //Reserialize Serialize.To(jsonWriter, readRecord); jsonWriter.Flush(); // Send response return(jsonString.ToString()); }
private static T ParseJson <T>(string json) where T : new() { var deserializer = new Deserializer <SimpleJsonReader>(typeof(T)); var reader = new SimpleJsonReader(new StringReader(json)); var target = deserializer.Deserialize <T>(reader); return(target); }
public static Record Deserializer(string responseBody) { //Deserialize a Json string Record and return thedeserialized Record back var reader = new SimpleJsonReader(new StringReader(responseBody)); var readRecord = Deserialize <Record> .From(reader); return(readRecord); }
/// <summary> /// Deserializes an EntryPointOperation object from its JSON representation. /// </summary> public static EntryPointOperation DeserializeFromJson(Stream stream) { var reader = new SimpleJsonReader(stream); var deserializer = new Deserializer <SimpleJsonReader>(typeof(EntryPointOperation)); var entryPoint = deserializer.Deserialize <EntryPointOperation>(reader); return(entryPoint); }
public override object Deserialize(Stream inputStream) { Initialize(); inputStream.Seek(0, SeekOrigin.Begin); var reader = new SimpleJsonReader(inputStream); return(_deserializer.Deserialize(reader)); }
/// <summary> /// /// </summary> public bool Load(string file_name) { if (SimpleJsonReader.ReadFromFile <SceneConfigData>(ref Data, file_name)) { return(true); } return(false); }
public override object Deserialize(string serialized) { Initialize(); using (var tr = new StringReader(serialized)) { var reader = new SimpleJsonReader(tr); return(_deserializer.Deserialize(reader)); } }
/// <summary> /// /// </summary> public bool LoadFromString(string str) { if (SimpleJsonReader.ReadFromString <SceneConfigData>(ref Data, str)) { return(true); } return(false); }
/// <summary> /// /// </summary> public bool Load(string file_name) { bool result = SimpleJsonReader.ReadFromFile <ResourcesManifestData>(ref Data, file_name); if (result) { Build(); } return(result); }
/// <inheritdoc/> public override object Deserialize(byte[] data, Type target) { var deserializer = _cache.GetDeserializer(target); var value = Encoding.UTF8.GetString(data, 0, data.Length); using (var reader = new StringReader(value)) { var jsonReader = new SimpleJsonReader(reader); return(deserializer.Deserialize(jsonReader)); } }
/// <summary> /// /// </summary> public bool Load(string file_name) { bool result = SimpleJsonReader.ReadFromFile <AssetBundleBuildData>(ref Data, file_name); if (result) { MatchAssetRuleElement(EditorCommon.ASSET_START_PATH, Data.Assets.Root); MatchSceneRuleData(ref Data.Scenes); } else { GenerateDefaultData(); } return(result); }
public void AnalyzeDocuments() { string fileName = @"D:\Project\TopicPanorama\data\TopicGraphs\NewCode-Ebola-Test2\Raw\news\result\lda.top.json"; string indexPath = @"D:\DataProcess\Index\Raw_EbolaEnBingNews_Ebola_0_1_RS_R-1"; int topDocCnt = 20; var indexReader = LuceneOperations.GetIndexReader(indexPath); //Read from json and sort SimpleJsonReader reader = new SimpleJsonReader(new StreamReader(File.Open(fileName, FileMode.Open))); HeapSortDouble[] hsd = null; int topicNumber = -1; ProgramProgress progress = new ProgramProgress(indexReader.NumDocs()); while (reader.IsReadable) { int docID = int.Parse(reader.ReadPropertyName()); double[] topicArray = reader.ReadDoubleArray(); if (topicNumber < 0) { topicNumber = topicArray.Length; hsd = new HeapSortDouble[topicNumber]; for (int i = 0; i < topicNumber; i++) { hsd[i] = new HeapSortDouble(topDocCnt); } } for (int i = 0; i < topicNumber; i++) { hsd[i].Insert(docID, topicArray[i]); } progress.PrintIncrementExperiment(); } progress.PrintTotalTime(); //Statistics Console.ReadLine(); }
static void Main() { var config = new Config { Variant = "Simple", Enabled = true, Urls = { "http://example.com", "http://www.example.com" } }; var jsonString = new StringBuilder(); var jsonWriter = new SimpleJsonWriter(new StringWriter(jsonString)); Serialize.To(jsonWriter, config); jsonWriter.Flush(); Console.WriteLine(jsonString); var reader = new SimpleJsonReader(new StringReader(jsonString.ToString())); config = Deserialize <Config> .From(reader); }
public static T DeserializeJson <T>(Stream stream) { var reader = new SimpleJsonReader(stream); return(Deserialize <T> .From(reader)); }
/// <summary> /// /// </summary> public bool Load(string file_name) { return(SimpleJsonReader.ReadFromFile <DownloadCacheData>(ref Data, file_name)); }
/// <summary> /// /// </summary> public bool Load(string file_name) { return(SimpleJsonReader.ReadFromFile <ResourcesPackagesData>(ref Data, file_name)); }
/// <summary> /// /// </summary> public bool Load(string file_name) { return(SimpleJsonReader.ReadFromFile <AssetBundleBuildData>(ref Data, file_name)); }
static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage:\nBond.CompatibilityTest json|compact|compact2|fast|simple|simple2|schema input_file output_file [json|compact|fast|simple|simple2]"); return; } var fromProtocol = args[0]; var toProtocol = fromProtocol; var inputFile = args[1]; var outputFile = args[2]; if (args.Length == 4) { toProtocol = args[3]; } using (var inputStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read)) { var input = new InputStream(inputStream); using (var outputStream = new FileStream(outputFile, FileMode.Create)) { var output = new OutputStream(outputStream); if (fromProtocol == "json") { var reader = new SimpleJsonReader(inputStream); var writer = new SimpleJsonWriter(outputStream); var transcoder = new Transcoder <SimpleJsonReader, SimpleJsonWriter>(Schema <Compat> .RuntimeSchema); transcoder.Transcode(reader, writer); writer.Flush(); } else if (fromProtocol == "compact") { var reader = new CompactBinaryReader <InputStream>(input); Write(reader, output, toProtocol); } else if (fromProtocol == "compact2") { var reader = new CompactBinaryReader <InputStream>(input, 2); Write(reader, output, toProtocol); } else if (fromProtocol == "fast") { var reader = new FastBinaryReader <InputStream>(input, 2); Write(reader, output, toProtocol); } else if (fromProtocol == "simple") { var reader = new SimpleBinaryReader <InputStream>(input); Write(reader, output, toProtocol); } else if (fromProtocol == "simple2") { var reader = new SimpleBinaryReader <InputStream>(input, 2); Write(reader, output, toProtocol); } else if (fromProtocol == "schema") { var schema = Unmarshal <SchemaDef> .From(input); if (!Comparer.Equal(schema, Schema <Compat> .RuntimeSchema.SchemaDef)) { Console.WriteLine("SchemaDef is different"); } var writer = new CompactBinaryWriter <OutputStream>(output); Marshal.To(writer, Schema <Compat> .RuntimeSchema.SchemaDef); output.Flush(); } else { Console.WriteLine("Unsupported input protocol {0}", fromProtocol); } } } }