internal void getStr(Page pg, int i) { int len = OldBtreePage.getKeyStrSize(pg, i); int offs = OldBtreePage.firstKeyOffs + OldBtreePage.getKeyStrOffs(pg, i); char[] sval = new char[len]; for (int j = 0; j < len; j++) { sval[j] = (char)Bytes.unpack2(pg.data, offs); offs += 2; } key = new Key(sval); }
protected override object unpackByteArrayKey(Page pg, int pos) { int offs = OldBtreePage.firstKeyOffs + OldBtreePage.getKeyStrOffs(pg, pos); byte[] data = pg.data; Object[] values = new Object[types.Length]; for (int i = 0; i < types.Length; i++) { Object v = null; switch (types[i]) { case ClassDescriptor.FieldType.tpBoolean: v = data[offs++] != 0; break; case ClassDescriptor.FieldType.tpSByte: v = (sbyte)data[offs++]; break; case ClassDescriptor.FieldType.tpByte: v = data[offs++]; break; case ClassDescriptor.FieldType.tpShort: v = Bytes.unpack2(data, offs); offs += 2; break; case ClassDescriptor.FieldType.tpUShort: v = (ushort)Bytes.unpack2(data, offs); offs += 2; break; case ClassDescriptor.FieldType.tpChar: v = (char)Bytes.unpack2(data, offs); offs += 2; break; case ClassDescriptor.FieldType.tpInt: v = Bytes.unpack4(data, offs); offs += 4; break; case ClassDescriptor.FieldType.tpEnum: v = Enum.ToObject(mbr[i] is FieldInfo ? ((FieldInfo)mbr[i]).FieldType : ((PropertyInfo)mbr[i]).PropertyType, Bytes.unpack4(data, offs)); offs += 4; break; case ClassDescriptor.FieldType.tpUInt: v = (uint)Bytes.unpack4(data, offs); offs += 4; break; case ClassDescriptor.FieldType.tpOid: case ClassDescriptor.FieldType.tpObject: { int oid = Bytes.unpack4(data, offs); v = oid == 0 ? null : ((DatabaseImpl)Database).lookupObject(oid, null); offs += 4; break; } case ClassDescriptor.FieldType.tpLong: v = Bytes.unpack8(data, offs); offs += 8; break; case ClassDescriptor.FieldType.tpDate: { v = new DateTime(Bytes.unpack8(data, offs)); offs += 8; break; } case ClassDescriptor.FieldType.tpULong: v = (ulong)Bytes.unpack8(data, offs); offs += 8; break; case ClassDescriptor.FieldType.tpFloat: v = Bytes.unpackF4(data, offs); offs += 4; break; case ClassDescriptor.FieldType.tpDouble: v = Bytes.unpackF8(data, offs); offs += 8; break; case ClassDescriptor.FieldType.tpDecimal: v = Bytes.unpackDecimal(data, offs); offs += 16; break; case ClassDescriptor.FieldType.tpGuid: v = Bytes.unpackGuid(data, offs); offs += 16; break; case ClassDescriptor.FieldType.tpString: { int len = Bytes.unpack4(data, offs); offs += 4; char[] sval = new char[len]; for (int j = 0; j < len; j++) { sval[j] = (char)Bytes.unpack2(pg.data, offs); offs += 2; } v = new String(sval); break; } case ClassDescriptor.FieldType.tpArrayOfByte: { int len = Bytes.unpack4(data, offs); offs += 4; byte[] val = new byte[len]; Array.Copy(pg.data, offs, val, 0, len); offs += len; v = val; break; } default: Debug.Assert(false, "Invalid type"); break; } values[i] = v; } return(values); }
public override int compareByteArrays(byte[] key, byte[] item, int offs, int lengtn) { int o1 = 0; int o2 = offs; byte[] a1 = key; byte[] a2 = item; for (int i = 0; i < types.Length && o1 < key.Length; i++) { int diff = 0; switch (types[i]) { case ClassDescriptor.FieldType.tpBoolean: case ClassDescriptor.FieldType.tpByte: diff = a1[o1++] - a2[o2++]; break; case ClassDescriptor.FieldType.tpSByte: diff = (sbyte)a1[o1++] - (sbyte)a2[o2++]; break; case ClassDescriptor.FieldType.tpShort: diff = Bytes.unpack2(a1, o1) - Bytes.unpack2(a2, o2); o1 += 2; o2 += 2; break; case ClassDescriptor.FieldType.tpUShort: diff = (ushort)Bytes.unpack2(a1, o1) - (ushort)Bytes.unpack2(a2, o2); o1 += 2; o2 += 2; break; case ClassDescriptor.FieldType.tpChar: diff = (char)Bytes.unpack2(a1, o1) - (char)Bytes.unpack2(a2, o2); o1 += 2; o2 += 2; break; case ClassDescriptor.FieldType.tpInt: { int i1 = Bytes.unpack4(a1, o1); int i2 = Bytes.unpack4(a2, o2); diff = i1 < i2 ? -1 : i1 == i2 ? 0 : 1; o1 += 4; o2 += 4; break; } case ClassDescriptor.FieldType.tpUInt: case ClassDescriptor.FieldType.tpEnum: case ClassDescriptor.FieldType.tpObject: case ClassDescriptor.FieldType.tpOid: { uint u1 = (uint)Bytes.unpack4(a1, o1); uint u2 = (uint)Bytes.unpack4(a2, o2); diff = u1 < u2 ? -1 : u1 == u2 ? 0 : 1; o1 += 4; o2 += 4; break; } case ClassDescriptor.FieldType.tpLong: { long l1 = Bytes.unpack8(a1, o1); long l2 = Bytes.unpack8(a2, o2); diff = l1 < l2 ? -1 : l1 == l2 ? 0 : 1; o1 += 8; o2 += 8; break; } case ClassDescriptor.FieldType.tpULong: case ClassDescriptor.FieldType.tpDate: { ulong l1 = (ulong)Bytes.unpack8(a1, o1); ulong l2 = (ulong)Bytes.unpack8(a2, o2); diff = l1 < l2 ? -1 : l1 == l2 ? 0 : 1; o1 += 8; o2 += 8; break; } case ClassDescriptor.FieldType.tpFloat: { float f1 = Bytes.unpackF4(a1, o1); float f2 = Bytes.unpackF4(a2, o2); diff = f1 < f2 ? -1 : f1 == f2 ? 0 : 1; o1 += 4; o2 += 4; break; } case ClassDescriptor.FieldType.tpDouble: { double d1 = Bytes.unpackF8(a1, o1); double d2 = Bytes.unpackF8(a2, o2); diff = d1 < d2 ? -1 : d1 == d2 ? 0 : 1; o1 += 8; o2 += 8; break; } case ClassDescriptor.FieldType.tpDecimal: { decimal d1 = Bytes.unpackDecimal(a1, o1); decimal d2 = Bytes.unpackDecimal(a2, o2); diff = d1.CompareTo(d2); o1 += 16; o2 += 16; break; } case ClassDescriptor.FieldType.tpGuid: { Guid g1 = Bytes.unpackGuid(a1, o1); Guid g2 = Bytes.unpackGuid(a2, o2); diff = g1.CompareTo(g2); o1 += 16; o2 += 16; break; } case ClassDescriptor.FieldType.tpString: { string s1, s2; o1 = Bytes.unpackString(a1, o1, out s1); o2 = Bytes.unpackString(a2, o2, out s2); diff = String.CompareOrdinal(s1, s2); /* TODO: old version, remove * int len1 = Bytes.unpack4(a1, o1); * int len2 = Bytes.unpack4(a2, o2); * o1 += 4; * o2 += 4; * int len = len1 < len2 ? len1 : len2; * while (--len >= 0) * { * diff = (char)Bytes.unpack2(a1, o1) - (char)Bytes.unpack2(a2, o2); * if (diff != 0) * { * return diff; * } * o1 += 2; * o2 += 2; * } * diff = len1 - len2; */ break; } case ClassDescriptor.FieldType.tpArrayOfByte: { int len1 = Bytes.unpack4(a1, o1); int len2 = Bytes.unpack4(a2, o2); o1 += 4; o2 += 4; int len = len1 < len2 ? len1 : len2; while (--len >= 0) { diff = a1[o1++] - a2[o2++]; if (diff != 0) { return(diff); } } diff = len1 - len2; break; } default: Debug.Assert(false, "Invalid type"); break; } if (diff != 0) { return(diff); } } return(0); }
internal void extract(Page pg, int offs, ClassDescriptor.FieldType type) { byte[] data = pg.data; switch (type) { case ClassDescriptor.FieldType.tpBoolean: key = new Key(data[offs] != 0); break; case ClassDescriptor.FieldType.tpSByte: key = new Key((sbyte)data[offs]); break; case ClassDescriptor.FieldType.tpByte: key = new Key(data[offs]); break; case ClassDescriptor.FieldType.tpShort: key = new Key(Bytes.unpack2(data, offs)); break; case ClassDescriptor.FieldType.tpUShort: key = new Key((ushort)Bytes.unpack2(data, offs)); break; case ClassDescriptor.FieldType.tpChar: key = new Key((char)Bytes.unpack2(data, offs)); break; case ClassDescriptor.FieldType.tpInt: key = new Key(Bytes.unpack4(data, offs)); break; case ClassDescriptor.FieldType.tpEnum: case ClassDescriptor.FieldType.tpUInt: case ClassDescriptor.FieldType.tpObject: case ClassDescriptor.FieldType.tpOid: key = new Key((uint)Bytes.unpack4(data, offs)); break; case ClassDescriptor.FieldType.tpLong: key = new Key(Bytes.unpack8(data, offs)); break; case ClassDescriptor.FieldType.tpDate: case ClassDescriptor.FieldType.tpULong: key = new Key((ulong)Bytes.unpack8(data, offs)); break; case ClassDescriptor.FieldType.tpFloat: key = new Key(Bytes.unpackF4(data, offs)); break; case ClassDescriptor.FieldType.tpDouble: key = new Key(Bytes.unpackF8(data, offs)); break; case ClassDescriptor.FieldType.tpGuid: key = new Key(Bytes.unpackGuid(data, offs)); break; case ClassDescriptor.FieldType.tpDecimal: key = new Key(Bytes.unpackDecimal(data, offs)); break; default: Debug.Assert(false, "Invalid type"); break; } }