public void CanTranscode() { using (var stream1 = new MemoryStream()) using (var stream2 = new MemoryStream()) using (var writerStream1 = new WriterStream(stream1)) using (var writerStream2 = new WriterStream(stream2)) { // write into compact binary protocol first var writer = writerStream1.CreateCompactBinaryWriter(); writer.Write(this.testObject); stream1.Position = 0; using (var readerStream1 = ReaderStream.FromMemoryStreamBuffer(stream1, null)) { var reader = readerStream1.CreateCompactBinaryReader(); // re-write as simple protocol var writer2 = writerStream2.CreateSimpleBinaryWriter(); Transcode.FromTo(reader, writer2); stream2.Position = 0; using (var readerStream2 = new ReaderStream(stream2)) { var reader2 = readerStream2.CreateSimpleBinaryReader(); var anotherObject = reader2.Read <AnotherDerivedThing>(); Assert.IsTrue(Comparer.Equal(anotherObject, this.testObject)); } } } }
public static void TranscodeCBJson <From>(Stream from, Stream to) { var input = new InputStream(from, 11); var reader = new CompactBinaryReader <InputStream>(input); var writer = new SimpleJsonWriter(to); Transcode <From> .FromTo(reader, writer); writer.Flush(); }
public static void TranscodeCBFB(Stream from, Stream to) { var input = new InputStream(from, 11); var reader = new CompactBinaryReader <InputStream>(input); var output = new OutputStream(to, 19); var writer = new FastBinaryWriter <OutputStream>(output); Transcode.FromTo(reader, writer); output.Flush(); }
public static void TranscodeSPSP <From>(Stream from, Stream to) { var input = new InputStream(from, 11); var reader = new SimpleBinaryReader <InputStream>(input); var output = new OutputStream(to, 19); var writer = new SimpleBinaryWriter <OutputStream>(output); Transcode <From> .FromTo(reader, writer); output.Flush(); }
public static void TranscodeCBXml <From>(Stream from, Stream to) { var input = new InputStream(from, 11); var reader = new CompactBinaryReader <InputStream>(input); var hasBase = Schema <From> .RuntimeSchema.HasBase; var writer = new SimpleXmlWriter(to, new SimpleXmlWriter.Settings { UseNamespaces = hasBase }); Transcode <From> .FromTo(reader, writer); writer.Flush(); }
static void Main() { var src = new Example { Widgets = { new Widget { Name = "Konfabulator", Number = 3.14 } } }; var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); Serialize.To(writer, src); var input = new InputBuffer(output.Data); var reader = new CompactBinaryReader <InputBuffer>(input); var xmlString = new StringBuilder(); var xmlWriter = new SimpleXmlWriter(XmlWriter.Create(xmlString, new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true })); Transcode <Example> .FromTo(reader, xmlWriter); xmlWriter.Flush(); string[] expectedLines = @"<Example> <Widgets> <Item> <Widget> <Name>Konfabulator</Name> <Number>3.14</Number> </Widget> </Item> </Widgets> </Example>".Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.None); string[] actualLines = xmlString.ToString().Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.None); ThrowIfFalse(expectedLines.SequenceEqual(actualLines)); }
static void Main() { var src = new Example { Widgets = { new Widget { Name = "Konfabulator", Number = 3.14 } } }; var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); Serialize.To(writer, src); var input = new InputBuffer(output.Data); var reader = new CompactBinaryReader <InputBuffer>(input); var xmlString = new StringBuilder(); var xmlWriter = new SimpleXmlWriter(XmlWriter.Create(xmlString, new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true })); Transcode <Example> .FromTo(reader, xmlWriter); xmlWriter.Flush(); Debug.Assert(xmlString.ToString() == @"<Example> <Widgets> <Item> <Widget> <Name>Konfabulator</Name> <Number>3.14</Number> </Widget> </Item> </Widgets> </Example>"); }