packF8() публичный Метод

public packF8 ( int offs, double val ) : int
offs int
val double
Результат int
        private int packKeyPart(ByteBuffer buf, int dst, ClassDescriptor.FieldType type, object val)
        {
            switch (type)
            {
            case ClassDescriptor.FieldType.tpBoolean:
                dst = buf.packBool(dst, (bool)val);
                break;

            case ClassDescriptor.FieldType.tpByte:
                dst = buf.packI1(dst, (byte)val);
                break;

            case ClassDescriptor.FieldType.tpSByte:
                dst = buf.packI1(dst, (sbyte)val);
                break;

            case ClassDescriptor.FieldType.tpShort:
                dst = buf.packI2(dst, (short)val);
                break;

            case ClassDescriptor.FieldType.tpUShort:
                dst = buf.packI2(dst, (ushort)val);
                break;

            case ClassDescriptor.FieldType.tpChar:
                dst = buf.packI2(dst, (char)val);
                break;

            case ClassDescriptor.FieldType.tpInt:
            case ClassDescriptor.FieldType.tpOid:
            case ClassDescriptor.FieldType.tpEnum:
                dst = buf.packI4(dst, (int)val);
                break;

            case ClassDescriptor.FieldType.tpUInt:
                dst = buf.packI4(dst, (int)(uint)val);
                break;

            case ClassDescriptor.FieldType.tpObject:
                dst = buf.packI4(dst, val != null ? (int)((IPersistent)val).Oid : 0);
                break;

            case ClassDescriptor.FieldType.tpLong:
                dst = buf.packI8(dst, (long)val);
                break;

            case ClassDescriptor.FieldType.tpULong:
                dst = buf.packI8(dst, (long)(ulong)val);
                break;

            case ClassDescriptor.FieldType.tpDate:
                dst = buf.packDate(dst, (DateTime)val);
                break;

            case ClassDescriptor.FieldType.tpFloat:
                dst = buf.packF4(dst, (float)val);
                break;

            case ClassDescriptor.FieldType.tpDouble:
                dst = buf.packF8(dst, (double)val);
                break;

            case ClassDescriptor.FieldType.tpDecimal:
                dst = buf.packDecimal(dst, (decimal)val);
                break;

            case ClassDescriptor.FieldType.tpGuid:
                dst = buf.packGuid(dst, (Guid)val);
                break;

            case ClassDescriptor.FieldType.tpString:
                dst = buf.packString(dst, (string)val);
                break;

            case ClassDescriptor.FieldType.tpArrayOfByte:
                buf.extend(dst + 4);
                if (val != null)
                {
                    byte[] arr = (byte[])val;
                    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:
                Debug.Assert(false, "Invalid type");
                break;
            }
            return(dst);
        }
Пример #2
0
        Key createCompoundKey(ClassDescriptor.FieldType[] types, String[] values)
        {
            ByteBuffer buf = new ByteBuffer();
            int dst = 0;

            for (int i = 0; i < types.Length; i++)
            {
                String val = values[i];
                switch (types[i])
                {
                    case ClassDescriptor.FieldType.tpBoolean:
                        dst = buf.packBool(dst, Int32.Parse(val) != 0);
                        break;

                    case ClassDescriptor.FieldType.tpByte:
                    case ClassDescriptor.FieldType.tpSByte:
                        dst = buf.packI1(dst, Int32.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpChar:
                    case ClassDescriptor.FieldType.tpShort:
                    case ClassDescriptor.FieldType.tpUShort:
                        dst = buf.packI2(dst, Int32.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpInt:
                        dst = buf.packI4(dst, Int32.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpEnum:
                    case ClassDescriptor.FieldType.tpUInt:
                        dst = buf.packI4(dst, (int)UInt32.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpObject:
                    case ClassDescriptor.FieldType.tpOid:
                        dst = buf.packI4(dst, mapId((int)UInt32.Parse(val)));
                        break;

                    case ClassDescriptor.FieldType.tpLong:
                        dst = buf.packI8(dst, Int64.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpULong:
                        dst = buf.packI8(dst, (long)UInt64.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpDate:
                        dst = buf.packDate(dst, DateTime.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpFloat:
                        dst = buf.packF4(dst, Single.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpDouble:
                        dst = buf.packF8(dst, Double.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpDecimal:
                        dst = buf.packDecimal(dst, Decimal.Parse(val));
                        break;

                    case ClassDescriptor.FieldType.tpGuid:
                        dst = buf.packGuid(dst, new Guid(val));
                        break;

                    case ClassDescriptor.FieldType.tpString:
                        dst = buf.packString(dst, val);
                        break;

                    case ClassDescriptor.FieldType.tpArrayOfByte:
                        buf.extend(dst + 4 + (val.Length >> 1));
                        Bytes.pack4(buf.arr, dst, 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;
                }
            }
            return new Key(buf.toArray());
        }