コード例 #1
0
 public int packString(int offs, string s)
 {
     if (s == null)
     {
         extend(offs + 4);
         Bytes.pack4(arr, offs, -1);
         offs += 4;
     }
     else
     {
         int len = s.Length;
         if (encoding == null)
         {
             extend(offs + 4 + len * 2);
             Bytes.pack4(arr, offs, len);
             offs += 4;
             for (int i = 0; i < len; i++)
             {
                 Bytes.pack2(arr, offs, (short)s[i]);
                 offs += 2;
             }
         }
         else
         {
             byte[] bytes = encoding.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);
 }
コード例 #2
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[BtreePage.firstKeyOffs + i] = (byte)key.ival;
                break;

            case ClassDescriptor.FieldType.tpShort:
            case ClassDescriptor.FieldType.tpUShort:
            case ClassDescriptor.FieldType.tpChar:
                Bytes.pack2(dst, BtreePage.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, BtreePage.firstKeyOffs + i * 4, key.ival);
                break;

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

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

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

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

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


            default:
                Debug.Assert(false, "Invalid type");
                break;
            }
            Bytes.pack4(dst, BtreePage.firstKeyOffs + (BtreePage.maxItems - i - 1) * 4, oid);
        }
コード例 #3
0
 public int packI2(int offs, int val)
 {
     extend(offs + 2);
     Bytes.pack2(arr, offs, (short)val);
     return(offs + 2);
 }