public void UseStandardSession ()
		{
			MemoryStream ms = new MemoryStream ();
			XmlBinaryWriterSession session =
				new XmlBinaryWriterSession ();
			XmlDictionary dic = new XmlDictionary ();
			XmlDictionaryWriter w = XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
			w.WriteStartElement (dic.Add ("FOO"), XmlDictionaryString.Empty);
			w.WriteStartElement (dic.Add ("blah"), XmlDictionaryString.Empty);
			w.WriteStartElement (dic.Add ("blabla"), XmlDictionaryString.Empty);
			w.Close ();
			Assert.AreEqual (new byte [] {0x42, 0, 0x42, 2, 0x42, 4, 1, 1, 1}, ms.ToArray ());
		}
Exemplo n.º 2
0
		public static XmlDictionaryWriter CreateBinaryWriter (
			Stream stream, IXmlDictionary dictionary,
			XmlBinaryWriterSession session, bool ownsStream)
		{
			return new XmlBinaryDictionaryWriter (stream,
				dictionary, session, ownsStream);
		}
Exemplo n.º 3
0
 public static XmlDictionaryWriter CreateBinaryWriter(
     Stream stream, IXmlDictionary dictionary,
     XmlBinaryWriterSession session, bool ownsStream)
 {
     return(new XmlBinaryDictionaryWriter(stream,
                                          dictionary, session, ownsStream));
 }
Exemplo n.º 4
0
		public void TryAddDuplicate ()
		{
			XmlDictionary dic = new XmlDictionary ();
			XmlDictionaryString d1 = dic.Add ("foo");
			XmlBinaryWriterSession s = new XmlBinaryWriterSession ();
			int idx;
			s.TryAdd (d1, out idx);
			s.TryAdd (d1, out idx);
		}
 public void SetOutput(Stream stream, IXmlDictionary dictionary, XmlBinaryWriterSession session, bool ownsStream)
 {
     this.dictionary = dictionary;
     this.session = session;
     this.inAttribute = false;
     this.inList = false;
     this.attributeValue.Clear();
     this.textNodeOffset = -1;
     base.SetOutput(stream, ownsStream, null);
 }
Exemplo n.º 6
0
 public void SetOutput(Stream stream, IXmlDictionary dictionary, XmlBinaryWriterSession session, bool ownsStream)
 {
     _dictionary = dictionary;
     _session = session;
     _inAttribute = false;
     _inList = false;
     _attributeValue.Clear();
     _textNodeOffset = -1;
     SetOutput(stream, ownsStream, null);
 }
 public void SetOutput(Stream stream, IXmlDictionary dictionary, XmlBinaryWriterSession session, bool ownsStream)
 {
     this.dictionary  = dictionary;
     this.session     = session;
     this.inAttribute = false;
     this.inList      = false;
     this.attributeValue.Clear();
     this.textNodeOffset = -1;
     base.SetOutput(stream, ownsStream, null);
 }
 public void SetOutput(Stream stream, IXmlDictionary dictionary, XmlBinaryWriterSession session, bool ownsStream)
 {
     if (stream == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("stream"));
     }
     if (this.writer == null)
     {
         this.writer = new XmlBinaryNodeWriter();
     }
     this.writer.SetOutput(stream, dictionary, session, ownsStream);
     base.SetOutput(this.writer);
 }
Exemplo n.º 9
0
 public void SetOutput(Stream stream, IXmlDictionary dictionary, XmlBinaryWriterSession session, bool ownsStream)
 {
     if (stream == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("stream"));
     }
     if (this.writer == null)
     {
         this.writer = new XmlBinaryNodeWriter();
     }
     this.writer.SetOutput(stream, dictionary, session, ownsStream);
     base.SetOutput(this.writer);
 }
Exemplo n.º 10
0
		public void TryAddIndex ()
		{
			XmlDictionary dic = new XmlDictionary ();
			XmlDictionaryString d1 = dic.Add ("foo");
			XmlDictionaryString d2 = dic.Add ("bar");
			XmlDictionaryString d3 = dic.Add ("baz");
			XmlBinaryWriterSession s = new XmlBinaryWriterSession ();
			int idx;
			s.TryAdd (d1, out idx);
			Assert.AreEqual (0, idx, "#1");
			s.TryAdd (d3, out idx);
			Assert.AreEqual (1, idx, "#2"); // not 2
		}
Exemplo n.º 11
0
        // XmlWriterSettings support

        #endregion

        #region Constructors

        public XmlBinaryDictionaryWriter(Stream stream,
                                         IXmlDictionary dictionary,
                                         XmlBinaryWriterSession session, bool ownsStream)
        {
            if (dictionary == null)
            {
                dictionary = new XmlDictionary();
            }
            if (session == null)
            {
                session = new XmlBinaryWriterSession();
            }

            original      = new MyBinaryWriter(stream);
            this.writer   = original;
            buffer_writer = new MyBinaryWriter(buffer);
            this.dict_ext = dictionary;
            this.session  = session;
            owns_stream   = ownsStream;

            AddNamespace("xml", "http://www.w3.org/XML/1998/namespace");
            AddNamespace("xml", "http://www.w3.org/2000/xmlns/");
            ns_index = 2;
        }
		public void WriteDictionaryStringWithDifferentDictionary () // it actually works
		{
			MemoryStream ms = new MemoryStream ();
			XmlBinaryWriterSession session = new XmlBinaryWriterSession ();
			XmlDictionaryWriter w = XmlDictionaryWriter.CreateBinaryWriter (ms, new XmlDictionary (), session);
			XmlDictionary dic = new XmlDictionary ();
			w.WriteStartElement (dic.Add ("FOO"), XmlDictionaryString.Empty);
			w.Close ();
			Assert.AreEqual (new byte [] {0x42, 1, 1}, ms.ToArray ());
		}
Exemplo n.º 13
0
 public static XmlDictionaryWriter CreateBinaryWriter(
     Stream stream, IXmlDictionary dictionary,
     XmlBinaryWriterSession session)
 {
     return(CreateBinaryWriter(stream, dictionary, session, false));
 }
 public static XmlDictionaryWriter CreateBinaryWriter(Stream stream, IXmlDictionary dictionary, XmlBinaryWriterSession session, bool ownsStream)
 {
     XmlBinaryWriter writer = new XmlBinaryWriter();
     writer.SetOutput(stream, dictionary, session, ownsStream);
     return writer;
 }
 public static XmlDictionaryWriter CreateBinaryWriter(Stream stream, IXmlDictionary dictionary, XmlBinaryWriterSession session)
 {
     return CreateBinaryWriter(stream, dictionary, session, true);
 }
		public void Beyond128DictionaryEntries ()
		{
			XmlDictionaryString ds;
			MemoryStream ms = new MemoryStream ();
			XmlDictionary dic = new XmlDictionary ();
			for (int i = 0; i < 260; i++)
				Assert.AreEqual (i, dic.Add ("n" + i).Key, "d");
			XmlDictionary dic2 = new XmlDictionary ();
			XmlBinaryWriterSession session = new XmlBinaryWriterSession ();
			int idx;
			for (int i = 0; i < 260; i++)
				session.TryAdd (dic2.Add ("n" + i), out idx);
			XmlDictionaryWriter w = XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
			w.WriteStartElement (dic.Add ("n128"), dic.Add ("n129"));
			w.WriteStartElement (dic2.Add ("n130"), dic2.Add ("n131"));
			w.WriteStartElement (dic.Add ("n132"), dic2.Add ("n133"));
			w.WriteStartElement (dic.Add ("n256"), dic2.Add ("n256"));
			w.Close ();

			byte [] bytes = new byte [] {
				// so, when it went beyond 128, the index
				// becomes 2 bytes, where
				// - the first byte always becomes > 80, and
				// - the second byte becomes (n / 0x80) * 2.
				0x42, 0x80, 2, 0x0A, 0x82, 2,
				0x42, 0x85, 2, 0x0A, 0x87, 2,
				0x42, 0x88, 2, 0x0A, 0x8B, 2,
				0x42, 0x80, 4, 0x0A, 0x81, 4,
				1, 1, 1, 1};
			Assert.AreEqual (bytes, ms.ToArray (), "result");
		}
		public void UseStandardSession2 ()
		{
			MemoryStream ms = new MemoryStream ();
			XmlBinaryWriterSession session =
				new XmlBinaryWriterSession ();
			XmlDictionary dic = new XmlDictionary ();
			XmlDictionaryString x = dic.Add ("urn:foo");
			XmlDictionaryWriter w = XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
			w.WriteStartElement (dic.Add ("FOO"), x);
			w.WriteStartElement (dic.Add ("blah"), x);
			w.WriteStartElement (dic.Add ("blabla"), x);
			w.Close ();
			Assert.AreEqual (new byte [] {0x42, 2, 0x0A, 0, 0x42, 4, 0x42, 6, 1, 1, 1}, ms.ToArray (), "#1");

			XmlDictionaryString ds;
			Assert.IsTrue (dic.TryLookup (0, out ds), "#2-1");
			Assert.AreEqual ("urn:foo", ds.Value, "#2-2");
			Assert.AreEqual (0, ds.Key, "#2-3");
			Assert.IsTrue (dic.TryLookup (1, out ds), "#3-1");
			Assert.AreEqual ("FOO", ds.Value, "#3-2");
			Assert.AreEqual (1, ds.Key, "#3-3");
			Assert.IsTrue (dic.TryLookup (2, out ds), "#4-1");
			Assert.AreEqual ("blah", ds.Value, "#4-2");
			Assert.AreEqual (2, ds.Key, "#4-3");
			Assert.IsTrue (dic.TryLookup (3, out ds), "#5-1");
			Assert.AreEqual ("blabla", ds.Value, "#5-2");
			Assert.AreEqual (3, ds.Key, "#5-3");
		}
		public void IndicesFromDictionaryAndSession ()
		{
			// So, I found out the solution for the indices puzzle.
			MemoryStream ms = new MemoryStream ();
			XmlBinaryWriterSession session = new XmlBinaryWriterSession ();
			XmlDictionary dic = new XmlDictionary ();
			XmlDictionaryWriter w = XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
			XmlDictionary dic2 = new XmlDictionary ();
			XmlDictionary dic3 = new XmlDictionary ();
			w.WriteStartElement (dic.Add ("FOO"), XmlDictionaryString.Empty);
			w.WriteStartElement (dic2.Add ("FOO"), XmlDictionaryString.Empty);
			w.WriteStartElement (dic3.Add ("FOO"), XmlDictionaryString.Empty);
			w.WriteStartElement (dic2.Add ("BAR"), XmlDictionaryString.Empty);
			w.WriteStartElement (dic.Add ("BAR"), XmlDictionaryString.Empty);
			w.Close ();
			// ... so, looks like even indices are for dictionary, 
			// and odd indices are for session.
			byte [] bytes = new byte [] {
				0x42, 0, 0x42, 1, 0x42, 1,0x42, 3,
				0x42, 2, 1, 1, 1, 1, 1};
			Assert.AreEqual (bytes, ms.ToArray ());
		}
Exemplo n.º 19
0
 public void SetOutput(Stream stream, IXmlDictionary dictionary, XmlBinaryWriterSession session, bool ownsStream)
 {
     if (stream == null)
         throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(stream)));
     if (_writer == null)
         _writer = new XmlBinaryNodeWriter();
     _writer.SetOutput(stream, dictionary, session, ownsStream);
     SetOutput(_writer);
 }
Exemplo n.º 20
0
        public static XmlDictionaryWriter CreateBinaryWriter(Stream stream, IXmlDictionary dictionary, XmlBinaryWriterSession session, bool ownsStream)
        {
            XmlBinaryWriter writer = new XmlBinaryWriter();

            writer.SetOutput(stream, dictionary, session, ownsStream);
            return(writer);
        }
		// XmlWriterSettings support

		#endregion

		#region Constructors

		public XmlBinaryDictionaryWriter (Stream stream,
			IXmlDictionary dictionary,
			XmlBinaryWriterSession session, bool ownsStream)
		{
			if (dictionary == null)
				dictionary = new XmlDictionary ();
			if (session == null)
				session = new XmlBinaryWriterSession ();

			original = new MyBinaryWriter (stream);
			this.writer = original;
			buffer_writer = new MyBinaryWriter (buffer);
			this.dict_ext = dictionary;
			this.session = session;
			owns_stream = ownsStream;

			AddNamespace ("xml", "http://www.w3.org/XML/1998/namespace");
			AddNamespace ("xml", "http://www.w3.org/2000/xmlns/");
			ns_index = 2;
		}
Exemplo n.º 22
0
 public BinaryBufferedMessageWriter(IXmlDictionary dictionary, XmlBinaryWriterSession session)
 {
     _dictionary = dictionary;
     _session = session;
 }