示例#1
0
        internal int PackObject(object obj, ClassDescriptor desc, int offs, ByteBuffer buf, IPersistent po)
        {
            ClassDescriptor.FieldDescriptor[] flds = desc.allFields;
            for (int i = 0, n = flds.Length; i < n; i++)
            {
                ClassDescriptor.FieldDescriptor fd = flds[i];
                FieldInfo f = fd.field;
                switch (fd.type)
                {
                    case ClassDescriptor.tpByte:
                        buf.Extend(offs + 1);
                        buf.arr[offs++] = (byte) f.GetValue(obj);
                        continue;

                    case ClassDescriptor.tpBoolean:
                        buf.Extend(offs + 1);
                        buf.arr[offs++] = (byte) ((bool) f.GetValue(obj) ? 1 : 0);
                        continue;

                    case ClassDescriptor.tpShort:
                        buf.Extend(offs + 2);
                        Bytes.Pack2(buf.arr, offs, (short) f.GetValue(obj));
                        offs += 2;
                        continue;

                    case ClassDescriptor.tpChar:
                        buf.Extend(offs + 2);
                        Bytes.Pack2(buf.arr, offs, (short) f.GetValue(obj));
                        offs += 2;
                        continue;

                    case ClassDescriptor.tpInt:
                        buf.Extend(offs + 4);
                        Bytes.Pack4(buf.arr, offs, (int) f.GetValue(obj));
                        offs += 4;
                        continue;

                    case ClassDescriptor.tpLong:
                        buf.Extend(offs + 8);
                        Bytes.Pack8(buf.arr, offs, (long) f.GetValue(obj));
                        offs += 8;
                        continue;

                    case ClassDescriptor.tpFloat:
                        buf.Extend(offs + 4);
                        Bytes.PackF4(buf.arr, offs, (float) f.GetValue(obj));
                        offs += 4;
                        continue;

                    case ClassDescriptor.tpDouble:
                        buf.Extend(offs + 8);
                        Bytes.PackF8(buf.arr, offs, (double) f.GetValue(obj));
                        offs += 8;
                        continue;

                    case ClassDescriptor.tpDate:
                    {
                        buf.Extend(offs + 8);
                        DateTime d = (DateTime) f.GetValue(obj);
                        //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL.
                        //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior.
                        long msec = (d == null) ? -1 : d.Ticks;
                        Bytes.Pack8(buf.arr, offs, msec);
                        offs += 8;
                        continue;
                    }

                    case ClassDescriptor.tpString:
                        offs = buf.PackString(offs, (string) f.GetValue(obj), encoding);
                        continue;

                    case ClassDescriptor.tpObject:
                    {
                        buf.Extend(offs + 4);
                        Bytes.Pack4(buf.arr, offs, Swizzle((IPersistent) f.GetValue(obj)));
                        offs += 4;
                        continue;
                    }

                    case ClassDescriptor.tpValue:
                    {
                        object val = f.GetValue(obj);
                        if (val == null)
                        {
                            throw new StorageError(StorageError.NULL_VALUE, fd.fieldName);
                        }
                        else if (val is IPersistent)
                        {
                            throw new StorageError(StorageError.SERIALIZE_PERSISTENT);
                        }
                        offs = PackObject(val, fd.valueDesc, offs, buf, po);
                        continue;
                    }

                    case ClassDescriptor.tpRaw:
                        offs = PackValue(f.GetValue(obj), offs, buf);
                        continue;

                    case ClassDescriptor.tpArrayOfByte:
                    {
                        byte[] arr = (byte[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4 + len);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            Array.Copy(arr, 0, buf.arr, offs, len);
                            offs += len;
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfBoolean:
                    {
                        bool[] arr = (bool[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4 + len);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++, offs++)
                            {
                                buf.arr[offs] = (byte) (arr[j] ? 1 : 0);
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfShort:
                    {
                        short[] arr = (short[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4 + len * 2);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++)
                            {
                                Bytes.Pack2(buf.arr, offs, arr[j]);
                                offs += 2;
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfChar:
                    {
                        char[] arr = (char[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4 + len * 2);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++)
                            {
                                Bytes.Pack2(buf.arr, offs, (short) arr[j]);
                                offs += 2;
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfInt:
                    {
                        int[] arr = (int[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4 + len * 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++)
                            {
                                Bytes.Pack4(buf.arr, offs, arr[j]);
                                offs += 4;
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfLong:
                    {
                        long[] arr = (long[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4 + len * 8);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++)
                            {
                                Bytes.Pack8(buf.arr, offs, arr[j]);
                                offs += 8;
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfFloat:
                    {
                        float[] arr = (float[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4 + len * 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++)
                            {
                                Bytes.PackF4(buf.arr, offs, arr[j]);
                                offs += 4;
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfDouble:
                    {
                        double[] arr = (double[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4 + len * 8);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++)
                            {
                                Bytes.PackF8(buf.arr, offs, arr[j]);
                                offs += 8;
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfDate:
                    {
                        DateTime[] arr = (DateTime[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4 + len * 8);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++)
                            {
                                DateTime d = arr[j];
                                //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL.
                                //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior.
                                long msec = (d == null) ? -1 : d.Ticks;
                                Bytes.Pack8(buf.arr, offs, msec);
                                offs += 8;
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfString:
                    {
                        string[] arr = (string[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++)
                            {
                                offs = buf.PackString(offs, (string) arr[j], encoding);
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfObject:
                    {
                        IPersistent[] arr = (IPersistent[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4 + len * 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++)
                            {
                                Bytes.Pack4(buf.arr, offs, Swizzle(arr[j]));
                                offs += 4;
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfValue:
                    {
                        object[] arr = (object[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            ClassDescriptor elemDesc = fd.valueDesc;
                            for (int j = 0; j < len; j++)
                            {
                                object val = arr[j];
                                if (val == null)
                                    throw new StorageError(StorageError.NULL_VALUE, fd.fieldName);

                                offs = PackObject(val, elemDesc, offs, buf, po);
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpArrayOfRaw:
                    {
                        object[] arr = (object[]) f.GetValue(obj);
                        if (arr == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            int len = arr.Length;
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++)
                            {
                                offs = PackValue(arr[j], offs, buf);
                            }
                        }
                        continue;
                    }

                    case ClassDescriptor.tpLink:
                    {
                        LinkImpl link = (LinkImpl) f.GetValue(obj);
                        if (link == null)
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            link.owner = po;
                            int len = link.Size;
                            buf.Extend(offs + 4 + len * 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            for (int j = 0; j < len; j++)
                            {
                                Bytes.Pack4(buf.arr, offs, Swizzle(link.GetRaw(j)));
                                offs += 4;
                            }
                            link.Unpin();
                        }
                        continue;
                    }
                    }
            }
            return offs;
        }
示例#2
0
 internal int PackValue(object val, int offs, ByteBuffer buf)
 {
     if (val == null)
     {
         buf.Extend(offs + 4);
         Bytes.Pack4(buf.arr, offs, -1);
         offs += 4;
     }
     else if (val is IPersistent)
     {
         buf.Extend(offs + 8);
         Bytes.Pack4(buf.arr, offs, -2 - ClassDescriptor.tpObject);
         Bytes.Pack4(buf.arr, offs + 4, Swizzle((IPersistent) val));
         offs += 8;
     }
     else
     {
         Type c = val.GetType();
         if (c == typeof(bool))
         {
             buf.Extend(offs + 5);
             Bytes.Pack4(buf.arr, offs, -2 - ClassDescriptor.tpBoolean);
             buf.arr[offs + 4] = (byte) (((bool) val) ? 1 : 0);
             offs += 5;
         }
         else if (c == typeof(System.Char))
         {
             buf.Extend(offs + 6);
             Bytes.Pack4(buf.arr, offs, -2 - ClassDescriptor.tpChar);
             Bytes.Pack2(buf.arr, offs + 4, (short) ((System.Char) val));
             offs += 6;
         }
         else if (c == typeof(System.SByte))
         {
             buf.Extend(offs + 5);
             Bytes.Pack4(buf.arr, offs, -2 - ClassDescriptor.tpByte);
             buf.arr[offs + 4] = (byte) ((System.SByte) val);
             offs += 5;
         }
         else if (c == typeof(System.Int16))
         {
             buf.Extend(offs + 6);
             Bytes.Pack4(buf.arr, offs, -2 - ClassDescriptor.tpShort);
             Bytes.Pack2(buf.arr, offs + 4, (short) ((System.Int16) val));
             offs += 6;
         }
         else if (c == typeof(Int32))
         {
             buf.Extend(offs + 8);
             Bytes.Pack4(buf.arr, offs, -2 - ClassDescriptor.tpInt);
             Bytes.Pack4(buf.arr, offs + 4, ((Int32) val));
             offs += 8;
         }
         else if (c == typeof(Int64))
         {
             buf.Extend(offs + 12);
             Bytes.Pack4(buf.arr, offs, -2 - ClassDescriptor.tpLong);
             Bytes.Pack8(buf.arr, offs + 4, (long) ((Int64) val));
             offs += 12;
         }
         else if (c == typeof(System.Single))
         {
             buf.Extend(offs + 8);
             Bytes.Pack4(buf.arr, offs, -2 - ClassDescriptor.tpFloat);
             Bytes.PackF4(buf.arr, offs + 4, (float)val);
             offs += 8;
         }
         else if (c == typeof(System.Double))
         {
             buf.Extend(offs + 12);
             Bytes.Pack4(buf.arr, offs, -2 - ClassDescriptor.tpDouble);
             Bytes.PackF8(buf.arr, offs + 4, (System.Double) val);
             offs += 12;
         }
         else if (c == typeof(System.DateTime))
         {
             buf.Extend(offs + 12);
             Bytes.Pack4(buf.arr, offs, -2 - ClassDescriptor.tpDate);
             //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior.
             Bytes.Pack8(buf.arr, offs + 4, ((DateTime) val).Ticks);
             offs += 12;
         }
         else
         {
             System.IO.MemoryStream streamOut = new System.IO.MemoryStream();
             BinaryFormatter formatter = new BinaryFormatter();
             formatter.Serialize(streamOut, val);
             streamOut.Close();
             byte[] arr = streamOut.ToArray();
             int len = arr.Length;
             buf.Extend(offs + 4 + len);
             Bytes.Pack4(buf.arr, offs, len);
             offs += 4;
             Array.Copy(arr, 0, buf.arr, offs, len);
             offs += len;
         }
     }
     return offs;
 }
示例#3
0
        private Key ExtractKey(IPersistent obj)
        {
            try
            {
                ByteBuffer buf = new ByteBuffer();
                int dst = 0;
                for (int i = 0; i < fld.Length; i++)
                {
                    FieldInfo f = (FieldInfo) fld[i];
                    switch (types[i])
                    {
                        case ClassDescriptor.tpBoolean:
                            buf.Extend(dst + 1);
                            buf.arr[dst++] = (byte) ((bool) f.GetValue(obj) ? 1 : 0);
                            break;

                        case ClassDescriptor.tpByte:
                            buf.Extend(dst + 1);
                            buf.arr[dst++] = (byte) f.GetValue(obj);
                            break;

                        case ClassDescriptor.tpShort:
                            buf.Extend(dst + 2);
                            Bytes.Pack2(buf.arr, dst, (short) f.GetValue(obj));
                            dst += 2;
                            break;

                        case ClassDescriptor.tpChar:
                            buf.Extend(dst + 2);
                            Bytes.Pack2(buf.arr, dst, (short) f.GetValue(obj));
                            dst += 2;
                            break;

                        case ClassDescriptor.tpInt:
                            buf.Extend(dst + 4);
                            Bytes.Pack4(buf.arr, dst, (int) f.GetValue(obj));
                            dst += 4;
                            break;

                        case ClassDescriptor.tpObject:
                        {
                            IPersistent p = (IPersistent) f.GetValue(obj);
                            int oid = p == null ? 0 : p.Oid;
                            buf.Extend(dst + 4);
                            Bytes.Pack4(buf.arr, dst, oid);
                            dst += 4;
                            break;
                        }

                        case ClassDescriptor.tpLong:
                            buf.Extend(dst + 8);
                            Bytes.Pack8(buf.arr, dst, (long) f.GetValue(obj));
                            dst += 8;
                            break;

                        case ClassDescriptor.tpDate:
                        {
                            DateTime d = (DateTime) f.GetValue(obj);
                            buf.Extend(dst + 8);
                            //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL.
                            //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior.
                            Bytes.Pack8(buf.arr, dst, d == null ? -1 : d.Ticks);
                            dst += 8;
                            break;
                        }

                        case ClassDescriptor.tpFloat:
                            buf.Extend(dst + 4);
                            Bytes.PackF4(buf.arr, dst, (float) f.GetValue(obj));
                            dst += 4;
                            break;

                        case ClassDescriptor.tpDouble:
                            buf.Extend(dst + 8);
                            Bytes.PackF8(buf.arr, dst, (double) f.GetValue(obj));
                            dst += 8;
                            break;

                        case ClassDescriptor.tpString:
                        {
                            buf.Extend(dst + 4);
                            string str = (string) f.GetValue(obj);
                            if (str != null)
                            {
                                int len = str.Length;
                                Bytes.Pack4(buf.arr, dst, len);
                                dst += 4;
                                buf.Extend(dst + len * 2);
                                for (int j = 0; j < len; j++)
                                {
                                    Bytes.Pack2(buf.arr, dst, (short) str[j]);
                                    dst += 2;
                                }
                            }
                            else
                            {
                                Bytes.Pack4(buf.arr, dst, 0);
                                dst += 4;
                            }
                            break;
                        }

                        case ClassDescriptor.tpArrayOfByte:
                        {
                            buf.Extend(dst + 4);
                            byte[] arr = (byte[]) f.GetValue(obj);
                            if (arr != null)
                            {
                                int len = arr.Length;
                                Bytes.Pack4(buf.arr, dst, len);
                                dst += 4;
                                buf.Extend(dst + len);
                                Array.Copy(arr, 0, buf.arr, dst, len);
                                dst += len;
                            }
                            else
                            {
                                Bytes.Pack4(buf.arr, dst, 0);
                                dst += 4;
                            }
                            break;
                        }

                        default:
                            Assert.Failed("Invalid type");
                            break;
                    }
                }
                return new Key(buf.ToArray());
            }
            catch (System.Exception x)
            {
                throw new StorageError(StorageError.ACCESS_VIOLATION, x);
            }
        }
示例#4
0
 internal byte[] PackObject(IPersistent obj)
 {
     ByteBuffer buf = new ByteBuffer();
     int offs = ObjectHeader.Sizeof;
     buf.Extend(offs);
     ClassDescriptor desc = GetClassDescriptor(obj.GetType());
     if (obj is FastSerializable)
     {
         offs = ((FastSerializable) obj).Pack(buf, offs, encoding);
     }
     else
     {
         try
         {
             offs = PackObject(obj, desc, offs, buf, obj);
         }
         catch (System.Exception x)
         {
             throw new StorageError(StorageError.ACCESS_VIOLATION, x);
         }
     }
     ObjectHeader.SetSize(buf.arr, 0, offs);
     ObjectHeader.SetType(buf.arr, 0, desc.Oid);
     return buf.arr;
 }
示例#5
0
        private Key ConvertKey(Key key)
        {
            if (key == null)
            {
                return null;
            }

            if (key.type != ClassDescriptor.tpArrayOfObject)
            {
                throw new StorageError(StorageError.INCOMPATIBLE_KEY_TYPE);
            }

            object[] values = (object[]) key.oval;
            ByteBuffer buf = new ByteBuffer();
            int dst = 0;
            for (int i = 0; i < values.Length; i++)
            {
                object v = values[i];
                switch (types[i])
                {
                    case ClassDescriptor.tpBoolean:
                        buf.Extend(dst + 1);
                        buf.arr[dst++] = (byte) (((bool) v) ? 1 : 0);
                        break;

                    case ClassDescriptor.tpByte:
                        buf.Extend(dst + 1);
                        buf.arr[dst++] = (byte) Convert.ToSByte(((System.ValueType) v));
                        break;

                    case ClassDescriptor.tpShort:
                        buf.Extend(dst + 2);
                        Bytes.Pack2(buf.arr, dst, Convert.ToInt16(((System.ValueType) v)));
                        dst += 2;
                        break;

                    case ClassDescriptor.tpChar:
                        buf.Extend(dst + 2);
                        Bytes.Pack2(buf.arr, dst, (v is System.ValueType) ? Convert.ToInt16(((System.ValueType) v)) : (short) ((System.Char) v));
                        dst += 2;
                        break;

                    case ClassDescriptor.tpInt:
                        buf.Extend(dst + 4);
                        Bytes.Pack4(buf.arr, dst, Convert.ToInt32(((System.ValueType) v)));
                        dst += 4;
                        break;

                    case ClassDescriptor.tpObject:
                        buf.Extend(dst + 4);
                        Bytes.Pack4(buf.arr, dst, v == null ? 0 : ((IPersistent) v).Oid);
                        dst += 4;
                        break;

                    case ClassDescriptor.tpLong:
                        buf.Extend(dst + 8);
                        Bytes.Pack8(buf.arr, dst, Convert.ToInt64(((System.ValueType) v)));
                        dst += 8;
                        break;

                    case ClassDescriptor.tpDate:
                        buf.Extend(dst + 8);
                        //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior.
                        Bytes.Pack8(buf.arr, dst, v == null ? -1 : ((DateTime) v).Ticks);
                        dst += 8;
                        break;

                    case ClassDescriptor.tpFloat:
                        buf.Extend(dst + 4);
                        float f = (float)v;
                        Bytes.PackF4(buf.arr, dst, f);
                        dst += 4;
                        break;

                    case ClassDescriptor.tpDouble:
                        buf.Extend(dst + 8);
                        double d = (double)v; // TODOPORT: Convert.ToDouble(((System.ValueType) v) ?
                        Bytes.PackF8(buf.arr, dst, d);
                        dst += 8;
                        break;

                    case ClassDescriptor.tpString:
                    {
                        buf.Extend(dst + 4);
                        if (v != null)
                        {
                            string str = (string) v;
                            int len = str.Length;
                            Bytes.Pack4(buf.arr, dst, len);
                            dst += 4;
                            buf.Extend(dst + len * 2);
                            for (int j = 0; j < len; j++)
                            {
                                Bytes.Pack2(buf.arr, dst, (short) str[j]);
                                dst += 2;
                            }
                        }
                        else
                        {
                            Bytes.Pack4(buf.arr, dst, 0);
                            dst += 4;
                        }
                        break;
                    }

                    case ClassDescriptor.tpArrayOfByte:
                    {
                        buf.Extend(dst + 4);
                        if (v != null)
                        {
                            byte[] arr = (byte[]) v;
                            int len = arr.Length;
                            Bytes.Pack4(buf.arr, dst, len);
                            dst += 4;
                            buf.Extend(dst + len);
                            Array.Copy(arr, 0, buf.arr, dst, len);
                            dst += len;
                        }
                        else
                        {
                            Bytes.Pack4(buf.arr, dst, 0);
                            dst += 4;
                        }
                        break;
                    }

                    default:
                        Assert.Failed("Invalid type");
                        break;
                }
            }
            return new Key(buf.ToArray(), key.inclusion != 0);
        }
示例#6
0
        internal Key CreateCompoundKey(int[] types, string[] values)
        {
            ByteBuffer buf = new ByteBuffer();
            int dst = 0;

            try
            {
                for (int i = 0; i < types.Length; i++)
                {
                    string val = values[i];
                    switch (types[i])
                    {
                        case ClassDescriptor.tpBoolean:
                            buf.Extend(dst + 1);
                            buf.arr[dst++] = (byte) (Int32.Parse(val) != 0 ? 1 : 0);
                            break;

                        case ClassDescriptor.tpByte:
                            buf.Extend(dst + 1);
                            buf.arr[dst++] = (byte) System.SByte.Parse(val);
                            break;

                        case ClassDescriptor.tpChar:
                            buf.Extend(dst + 2);
                            Bytes.Pack2(buf.arr, dst, (short) Int32.Parse(val));
                            dst += 2;
                            break;

                        case ClassDescriptor.tpShort:
                            buf.Extend(dst + 2);
                            Bytes.Pack2(buf.arr, dst, System.Int16.Parse(val));
                            dst += 2;
                            break;

                        case ClassDescriptor.tpInt:
                            buf.Extend(dst + 4);
                            Bytes.Pack4(buf.arr, dst, Int32.Parse(val));
                            dst += 4;
                            break;

                        case ClassDescriptor.tpObject:
                            buf.Extend(dst + 4);
                            Bytes.Pack4(buf.arr, dst, MapId(Int32.Parse(val)));
                            dst += 4;
                            break;

                        case ClassDescriptor.tpLong:
                        case ClassDescriptor.tpDate:
                            buf.Extend(dst + 8);
                            Bytes.Pack8(buf.arr, dst, Int64.Parse(val));
                            dst += 8;
                            break;

                        case ClassDescriptor.tpFloat:
                            buf.Extend(dst + 4);
                            Bytes.PackF4(buf.arr, dst, Single.Parse(val));
                            dst += 4;
                            break;

                        case ClassDescriptor.tpDouble:
                            buf.Extend(dst + 8);
                            Bytes.PackF8(buf.arr, dst, Double.Parse(val));
                            dst += 8;
                            break;

                        case ClassDescriptor.tpString:
                            dst = buf.PackString(dst, val, storage.encoding);
                            break;

                        case ClassDescriptor.tpArrayOfByte:
                            buf.Extend(dst + 4 + (SupportClass.URShift(val.Length, 1)));
                            Bytes.Pack4(buf.arr, dst, SupportClass.URShift(val.Length, 1));
                            dst += 4;
                            for (int j = 0, n = val.Length; j < n; j += 2)
                            {
                                buf.arr[dst++] = (byte) ((GetHexValue(val[j]) << 4) | GetHexValue(val[j + 1]));
                            }
                            break;

                        default:
                            ThrowException("Bad key type");
                            break;
                    }
                }
            }
            catch (FormatException)
            {
                ThrowException("Failed to convert key value");
            }
            return new Key(buf.ToArray());
        }
示例#7
0
        internal int PackObject(XMLElement objElem, ClassDescriptor desc, int offs, ByteBuffer buf)
        {
            ClassDescriptor.FieldDescriptor[] flds = desc.allFields;
            for (int i = 0, n = flds.Length; i < n; i++)
            {
                ClassDescriptor.FieldDescriptor fd = flds[i];
                string fieldName = fd.fieldName;
                XMLElement elem = (objElem != null) ? objElem.GetSibling(fieldName) : null;

                switch (fd.type)
                {
                    case ClassDescriptor.tpByte:
                        buf.Extend(offs + 1);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                buf.arr[offs] = (byte) elem.GetIntValue();
                            }
                            else if (elem.IsRealValue())
                            {
                                //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                buf.arr[offs] = (byte) elem.GetRealValue();
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 1;
                        continue;

                    case ClassDescriptor.tpBoolean:
                        buf.Extend(offs + 1);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                buf.arr[offs] = (byte) (elem.GetIntValue() != 0 ? 1 : 0);
                            }
                            else if (elem.IsRealValue())
                            {
                                buf.arr[offs] = (byte) (elem.GetRealValue() != 0.0 ? 1 : 0);
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 1;
                        continue;

                    case ClassDescriptor.tpShort:
                    case ClassDescriptor.tpChar:
                        buf.Extend(offs + 2);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                Bytes.Pack2(buf.arr, offs, (short) elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                Bytes.Pack2(buf.arr, offs, (short) elem.GetRealValue());
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 2;
                        continue;

                    case ClassDescriptor.tpInt:
                        buf.Extend(offs + 4);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                Bytes.Pack4(buf.arr, offs, (int) elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                Bytes.Pack4(buf.arr, offs, (int) elem.GetRealValue());
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 4;
                        continue;

                    case ClassDescriptor.tpLong:
                        buf.Extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                Bytes.Pack8(buf.arr, offs, elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                Bytes.Pack8(buf.arr, offs, (long) elem.GetRealValue());
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;

                    case ClassDescriptor.tpFloat:
                        buf.Extend(offs + 4);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                Bytes.PackF4(buf.arr, offs, (float) elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                Bytes.PackF4(buf.arr, offs, (float) elem.GetRealValue());
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 4;
                        continue;

                    case ClassDescriptor.tpDouble:
                        buf.Extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                Bytes.PackF8(buf.arr, offs, (double) elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                Bytes.PackF8(buf.arr, offs, (double) elem.GetRealValue());
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;

                    case ClassDescriptor.tpDate:
                        buf.Extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                Bytes.Pack8(buf.arr, offs, elem.GetIntValue());
                            }
                            else if (elem.IsNullValue())
                            {
                                Bytes.Pack8(buf.arr, offs, -1);
                            }
                            else if (elem.IsStringValue())
                            {
                                /* TODOPORT:
                                //UPGRADE_ISSUE: Method 'java.text.DateFormat.parse' was not converted.
                                DateTime date = httpFormatter.parse(elem.GetStringValue(), 0);
                                //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL.
                                if (date == null)
                                {
                                    ThrowException("Invalid date");
                                }
                                //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior.
                                Bytes.Pack8(buf.arr, offs, date.Ticks);
                                */
                                ThrowException("Not implemented");
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;

                    case ClassDescriptor.tpString:
                        if (elem != null)
                        {
                            string val = null;
                            if (elem.IsIntValue())
                            {
                                val = Convert.ToString(elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                val = elem.GetRealValue().ToString();
                            }
                            else if (elem.IsStringValue())
                            {
                                val = elem.GetStringValue();
                            }
                            else if (elem.IsNullValue())
                            {
                                val = null;
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                            offs = buf.PackString(offs, val, storage.encoding);
                            continue;
                        }

                        buf.Extend(offs + 4);
                        Bytes.Pack4(buf.arr, offs, -1);
                        offs += 4;
                        continue;

                    case ClassDescriptor.tpObject:
                    {
                        int oid = 0;
                        if (elem != null)
                        {
                            XMLElement ref_Renamed = elem.GetSibling("ref");
                            if (ref_Renamed == null)
                            {
                                ThrowException("<ref> element expected");
                            }
                            oid = MapId(GetIntAttribute(ref_Renamed, "id"));
                        }
                        buf.Extend(offs + 4);
                        Bytes.Pack4(buf.arr, offs, oid);
                        offs += 4;
                        continue;
                    }

                    case ClassDescriptor.tpValue:
                        offs = PackObject(elem, fd.valueDesc, offs, buf);
                        continue;

                    case ClassDescriptor.tpRaw:
                    case ClassDescriptor.tpArrayOfByte:
                        offs = ImportBinary(elem, offs, buf, fieldName);
                        continue;

                    case ClassDescriptor.tpArrayOfBoolean:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    buf.arr[offs] = (byte) (item.GetIntValue() != 0 ? 1 : 0);
                                }
                                else if (item.IsRealValue())
                                {
                                    buf.arr[offs] = (byte) (item.GetRealValue() != 0.0 ? 1 : 0);
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 1;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfChar:
                    case ClassDescriptor.tpArrayOfShort:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 2);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    Bytes.Pack2(buf.arr, offs, (short) item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                    Bytes.Pack2(buf.arr, offs, (short) item.GetRealValue());
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 2;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfInt:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    Bytes.Pack4(buf.arr, offs, (int) item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                    Bytes.Pack4(buf.arr, offs, (int) item.GetRealValue());
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfLong:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 8);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    Bytes.Pack8(buf.arr, offs, item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                    Bytes.Pack8(buf.arr, offs, (long) item.GetRealValue());
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfFloat:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    Bytes.PackF4(buf.arr, offs, (float) item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    Bytes.PackF4(buf.arr, offs, (float) item.GetRealValue());
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfDouble:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 8);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                    Bytes.PackF8(buf.arr, offs, (double) item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    Bytes.PackF8(buf.arr, offs, (double) item.GetRealValue());
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfDate:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 8);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsNullValue())
                                {
                                    Bytes.Pack8(buf.arr, offs, -1);
                                }
                                else if (item.IsStringValue())
                                {
                                    /* TODOPORT:
                                    //UPGRADE_ISSUE: Method 'java.text.DateFormat.parse' was not converted.
                                    DateTime date = httpFormatter.parse(item.GetStringValue(), 0);
                                    //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL.
                                    if (date == null)
                                    {
                                        ThrowException("Invalid date");
                                    }
                                    //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior.
                                    Bytes.Pack8(buf.arr, offs, date.Ticks);
                                    */
                                    ThrowException("Not implemented");
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfString:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                string val = null;
                                if (item.IsIntValue())
                                {
                                    val = Convert.ToString(item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    val = item.GetRealValue().ToString();
                                }
                                else if (item.IsStringValue())
                                {
                                    val = item.GetStringValue();
                                }
                                else if (elem.IsNullValue())
                                {
                                    val = null;
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }

                                offs = buf.PackString(offs, val, storage.encoding);
                                item = item.NextSibling;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfObject:
                    case ClassDescriptor.tpLink:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                XMLElement ref_Renamed = item.GetSibling("ref");
                                if (ref_Renamed == null)
                                {
                                    ThrowException("<ref> element expected");
                                }
                                int oid = MapId(GetIntAttribute(ref_Renamed, "id"));
                                Bytes.Pack4(buf.arr, offs, oid);
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfValue:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            ClassDescriptor elemDesc = fd.valueDesc;
                            while (--len >= 0)
                            {
                                offs = PackObject(item, elemDesc, offs, buf);
                                item = item.NextSibling;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfRaw:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                offs = ImportBinary(item, offs, buf, fieldName);
                                item = item.NextSibling;
                            }
                        }
                        continue;
                    }
            }
            return offs;
        }
示例#8
0
 internal int ImportBinary(XMLElement elem, int offs, ByteBuffer buf, string fieldName)
 {
     if (elem == null || elem.IsNullValue())
     {
         buf.Extend(offs + 4);
         Bytes.Pack4(buf.arr, offs, -1);
         offs += 4;
     }
     else if (elem.IsStringValue())
     {
         string hexStr = elem.GetStringValue();
         int len = hexStr.Length;
         if (hexStr.StartsWith("#"))
         {
             buf.Extend(offs + 4 + len / 2 - 1);
             Bytes.Pack4(buf.arr, offs, -2 - GetHexValue(hexStr[1]));
             offs += 4;
             for (int j = 2; j < len; j += 2)
             {
                 buf.arr[offs++] = (byte) ((GetHexValue(hexStr[j]) << 4) | GetHexValue(hexStr[j + 1]));
             }
         }
         else
         {
             buf.Extend(offs + 4 + len / 2);
             Bytes.Pack4(buf.arr, offs, len / 2);
             offs += 4;
             for (int j = 0; j < len; j += 2)
             {
                 buf.arr[offs++] = (byte) ((GetHexValue(hexStr[j]) << 4) | GetHexValue(hexStr[j + 1]));
             }
         }
     }
     else
     {
         XMLElement ref_Renamed = elem.GetSibling("ref");
         if (ref_Renamed != null)
         {
             buf.Extend(offs + 4);
             Bytes.Pack4(buf.arr, offs, MapId(GetIntAttribute(ref_Renamed, "id")));
             offs += 4;
         }
         else
         {
             XMLElement item = elem.GetSibling("element");
             int len = (item == null) ? 0 : item.Counter;
             buf.Extend(offs + 4 + len);
             Bytes.Pack4(buf.arr, offs, len);
             offs += 4;
             while (--len >= 0)
             {
                 if (item.IsIntValue())
                 {
                     buf.arr[offs] = (byte) item.GetIntValue();
                 }
                 else if (item.IsRealValue())
                 {
                     //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                     buf.arr[offs] = (byte) item.GetRealValue();
                 }
                 else
                 {
                     ThrowException("Conversion for field " + fieldName + " is not possible");
                 }
                 item = item.NextSibling;
                 offs += 1;
             }
         }
     }
     return offs;
 }
示例#9
0
        internal void CreateObject(XMLElement elem)
        {
            Type cls = ClassDescriptor.LoadClass(storage, elem.name);
            ClassDescriptor desc = storage.GetClassDescriptor(cls);
            int oid = MapId(GetIntAttribute(elem, "id"));
            ByteBuffer buf = new ByteBuffer();
            int offs = ObjectHeader.Sizeof;
            buf.Extend(offs);

            offs = PackObject(elem, desc, offs, buf);

            ObjectHeader.SetSize(buf.arr, 0, offs);
            ObjectHeader.SetType(buf.arr, 0, desc.Oid);

            long pos = storage.Allocate(offs, 0);
            storage.SetPos(oid, pos | StorageImpl.dbModifiedFlag);
            storage.pool.Put(pos, buf.arr, offs);
        }