Author: atsushi
Date: 2007-04-02 10:38:50 -0400 (Mon, 02 Apr 2007)
New Revision: 75281

Modified:
   trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog
   
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryReader.cs
   trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryFormat.cs
Log:
2007-04-02  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * XmlBinaryFormat.cs : added Base64Fixed (0xA0).
        * XmlBinaryDictionaryReader.cs : support 0xA0 type above.
          ReadInt() refactoring. Handle float and double value types.



Modified: trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog
===================================================================
--- trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog 
2007-04-02 14:36:56 UTC (rev 75280)
+++ trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog 
2007-04-02 14:38:50 UTC (rev 75281)
@@ -1,3 +1,9 @@
+2007-04-02  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * XmlBinaryFormat.cs : added Base64Fixed (0xA0).
+       * XmlBinaryDictionaryReader.cs : support 0xA0 type above.
+         ReadInt() refactoring. Handle float and double value types.
+
 2007-03-30  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * XmlBinaryDictionaryReader.cs :

Modified: 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryReader.cs
===================================================================
--- 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryReader.cs
      2007-04-02 14:36:56 UTC (rev 75280)
+++ 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryReader.cs
      2007-04-02 14:38:50 UTC (rev 75281)
@@ -165,6 +165,10 @@
                                                return XmlConvert.ToString 
((int) TypedValue);
                                        case BF.Int64:
                                                return XmlConvert.ToString 
((long) TypedValue);
+                                       case BF.Single:
+                                               return XmlConvert.ToString 
((float) TypedValue);
+                                       case BF.Double:
+                                               return XmlConvert.ToString 
((double) TypedValue);
                                        case BF.DateTime:
                                                return XmlConvert.ToString 
((DateTime) TypedValue);
                                        case BF.TimeSpan:
@@ -174,6 +178,7 @@
                                        case BF.UniqueIdFromGuid:
                                                return TypedValue.ToString ();
                                        case BF.Base64:
+                                       case BF.Base64Fixed:
                                                return Convert.ToBase64String 
((byte []) TypedValue);
                                        default:
                                                throw new 
NotImplementedException ("ValueType " + ValueType + " on node " + NodeType);
@@ -785,8 +790,10 @@
                                        attr_values.Add (new NodeInfo (true));
                                NodeInfo v = attr_values [attr_value_count++];
                                v.Reset ();
-                               next = ReadByteOrError ();
-                               if (!ReadTextOrValue ((byte) next, v, true))
+                               int ident = ReadByteOrError ();
+                               is_next_end_element = ident > 0x80 && (ident & 
1) == 1;
+                               ident -= is_next_end_element ? 1 : 0;
+                               if (!ReadTextOrValue ((byte) ident, v, true) || 
is_next_end_element)
                                        break;
                        } while (true);
                }
@@ -840,10 +847,15 @@
                                break;
                        //case BF.UniqueId: // identical to .Text
                        case BF.Base64:
-                               byte [] base64 = new byte [ReadInt (-1)];
+                               byte [] base64 = new byte [ReadVariantSize ()];
                                source.Reader.Read (base64, 0, base64.Length);
                                node.TypedValue = base64;
                                break;
+                       case BF.Base64Fixed:
+                               base64 = new byte [source.Reader.ReadInt16 ()];
+                               source.Reader.Read (base64, 0, base64.Length);
+                               node.TypedValue = base64;
+                               break;
                        case BF.TimeSpan:
                                node.TypedValue = new TimeSpan 
(source.Reader.ReadInt64 ());
                                break;
@@ -913,35 +925,25 @@
 */
                }
 
-               private int ReadInt (int sizeSpec)
+               private int ReadVariantSize ()
                {
                        int size = 0;
                        // If sizeSpec < 0, then it is variant size specifier.
                        // Otherwise it is fixed size s = sizeSpec + 1 byte(s).
-                       if (sizeSpec < 0) {
-                               do {
-                                       size <<= 7;
-                                       byte got = ReadByteOrError ();
-                                       size += got;
-                                       if (got < 0x80)
-                                               break;
-                                       size -= 0x80;
-                               } while (true);
-                       } else {
-                               for (int i = 0; i < sizeSpec + 1; i++)
-                                       size += ReadByteOrError () << i;
-                       }
+                       do {
+                               size <<= 7;
+                               byte got = ReadByteOrError ();
+                               size += got;
+                               if (got < 0x80)
+                                       break;
+                               size -= 0x80;
+                       } while (true);
                        return size;
                }
 
                private string ReadUTF8 ()
                {
-                       return ReadUTF8 (-1);
-               }
-
-               private string ReadUTF8 (int sizeSpec)
-               {
-                       int size = ReadInt (sizeSpec);
+                       int size = ReadVariantSize ();
                        if (size == 0)
                                return String.Empty;
                        if (tmp_buffer.Length < size) {
@@ -954,7 +956,7 @@
 
                private XmlDictionaryString ReadDictName ()
                {
-                       int key = ReadInt (-1);
+                       int key = ReadVariantSize ();
                        XmlDictionaryString s;
                        if ((key & 1) == 1) {
                                if (session.TryLookup (key >> 1, out s))
@@ -982,7 +984,8 @@
                public override bool TryGetBase64ContentLength (out int length)
                {
                        length = 0;
-                       if (current.ValueType != BF.Base64)
+                       if (current.ValueType != BF.Base64 &&
+                           current.ValueType != BF.Base64Fixed)
                                return false;
                        length = ((byte []) current.TypedValue).Length;
                        return true;
@@ -1027,7 +1030,7 @@
                        case BF.Int32:
                                return (int) current.TypedValue;
                        }
-                       throw new InvalidOperationException ("The element 
content is not an integer");
+                       throw new InvalidOperationException ("Current content 
is not an integer");
                }
 
                public override long ReadContentAsLong ()
@@ -1040,12 +1043,33 @@
                        return ReadContentAsInt ();
                }
 
+               public override float ReadContentAsFloat ()
+               {
+                       if (node.ValueType != BF.Single)
+                               throw new InvalidOperationException ("Current 
content is not a single");
+                       float v = (float) current.TypedValue;
+                       Read ();
+                       return v;
+               }
+
+               public override double ReadContentAsDouble ()
+               {
+                       if (node.ValueType != BF.Double)
+                               throw new InvalidOperationException ("Current 
content is not a double");
+                       double v = (double) current.TypedValue;
+                       Read ();
+                       return v;
+               }
+
+               // FIXME: this is not likely to consume sequential base64 nodes.
                public override byte [] ReadContentAsBase64 ()
                {
                        byte [] ret = null;
-                       if (node.ValueType != BF.Base64)
-                               throw new InvalidOperationException ("The 
element content is not base64");
-                       while (NodeType == XmlNodeType.Text && node.ValueType 
== BF.Base64) {
+                       if (node.ValueType != BF.Base64 &&
+                           node.ValueType != BF.Base64Fixed)
+                               throw new InvalidOperationException ("Current 
content is not base64");
+                       while (NodeType == XmlNodeType.Text &&
+                              (node.ValueType == BF.Base64 || node.ValueType 
== BF.Base64Fixed)) {
                                if (ret == null)
                                        ret = (byte []) node.TypedValue;
                                else {
@@ -1064,7 +1088,7 @@
                public override Guid ReadContentAsGuid ()
                {
                        if (node.ValueType != BF.Guid)
-                               throw new InvalidOperationException ("The 
element content is not Guid");
+                               throw new InvalidOperationException ("Current 
content is not a Guid");
                        Guid ret = (Guid) node.TypedValue;
                        Read ();
                        return ret;
@@ -1082,7 +1106,7 @@
                                Read ();
                                return ret;
                        default:
-                               throw new InvalidOperationException ("The 
element content is not Guid");
+                               throw new InvalidOperationException ("Current 
content is not a UniqueId");
                        }
                }
 

Modified: 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryFormat.cs
===================================================================
--- 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryFormat.cs    
    2007-04-02 14:36:56 UTC (rev 75280)
+++ 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryFormat.cs    
    2007-04-02 14:38:50 UTC (rev 75281)
@@ -64,6 +64,7 @@
                public const byte Decimal = 0x94;
                public const byte DateTime = 0x96;
                public const byte Base64 = 0x9E;
+               public const byte Base64Fixed = 0xA0;
 
                public const byte Text = 0x98;
                public const byte EmptyText = 0xA8;
@@ -133,6 +134,7 @@
                96 : DateTime
                98 : UniqueId
                9E : base64Binary
+               A0 : base64Binary fixed length?
                AC : UniqueId whose IsGuid = true
                AE : TimeSpan
                B0 : Guid

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to