pack4() public static method

public static pack4 ( byte arr, int offs, int val ) : void
arr byte
offs int
val int
return void
Exemplo n.º 1
0
        internal void pack(Page pg, int i)
        {
            byte[] dst = pg.data;
            switch (key.type)
            {
            case ClassDescriptor.FieldType.tpBoolean:
            case ClassDescriptor.FieldType.tpSByte:
            case ClassDescriptor.FieldType.tpByte:
                dst[OldBtreePage.firstKeyOffs + i] = (byte)key.ival;
                break;

            case ClassDescriptor.FieldType.tpShort:
            case ClassDescriptor.FieldType.tpUShort:
            case ClassDescriptor.FieldType.tpChar:
                Bytes.pack2(dst, OldBtreePage.firstKeyOffs + i * 2, (short)key.ival);
                break;

            case ClassDescriptor.FieldType.tpInt:
            case ClassDescriptor.FieldType.tpUInt:
            case ClassDescriptor.FieldType.tpEnum:
            case ClassDescriptor.FieldType.tpObject:
            case ClassDescriptor.FieldType.tpOid:
                Bytes.pack4(dst, OldBtreePage.firstKeyOffs + i * 4, key.ival);
                break;

            case ClassDescriptor.FieldType.tpLong:
            case ClassDescriptor.FieldType.tpULong:
            case ClassDescriptor.FieldType.tpDate:
                Bytes.pack8(dst, OldBtreePage.firstKeyOffs + i * 8, key.lval);
                break;

            case ClassDescriptor.FieldType.tpFloat:
                Bytes.packF4(dst, OldBtreePage.firstKeyOffs + i * 4, (float)key.dval);
                break;

            case ClassDescriptor.FieldType.tpDouble:
                Bytes.packF8(dst, OldBtreePage.firstKeyOffs + i * 8, key.dval);
                break;

            case ClassDescriptor.FieldType.tpDecimal:
                Bytes.packDecimal(dst, OldBtreePage.firstKeyOffs + i * 16, key.dec);
                break;

            case ClassDescriptor.FieldType.tpGuid:
                Bytes.packGuid(dst, OldBtreePage.firstKeyOffs + i * 16, key.guid);
                break;


            default:
                Debug.Assert(false, "Invalid type");
                break;
            }
            Bytes.pack4(dst, OldBtreePage.firstKeyOffs + (OldBtreePage.maxItems - i - 1) * 4, oid);
        }
Exemplo n.º 2
0
        public int packString(int offs, string s)
        {
            if (s == null)
            {
                extend(offs + 4);
                Bytes.pack4(arr, offs, -1);
                offs += 4;
                return offs;
            }

            byte[] bytes = Encoding.UTF8.GetBytes(s);
            extend(offs + 4 + bytes.Length);
            Bytes.pack4(arr, offs, -2 - bytes.Length);
            Array.Copy(bytes, 0, arr, offs + 4, bytes.Length);
            offs += 4 + bytes.Length;
            return offs;
        }
        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);
        }
Exemplo n.º 4
0
 internal static void setType(byte[] arr, int offs, int type)
 {
     Bytes.pack4(arr, offs + 4, type);
 }
Exemplo n.º 5
0
 internal static void setSize(byte[] arr, int offs, int size)
 {
     Bytes.pack4(arr, offs, size);
 }
Exemplo n.º 6
0
 public int packI4(int offs, int val)
 {
     extend(offs + 4);
     Bytes.pack4(arr, offs, val);
     return offs + 4;
 }
Exemplo n.º 7
0
 internal static void setItem(Page pg, int index, int mask)
 {
     Bytes.pack4(pg.data, firstKeyOffs + index * 4, mask);
 }