/* * private void ReplaceHead(object valu) * { * fis.SetOffset(this.offset); * switch (typ.Vid) * { * case PTypeEnumeration.none: break; * case PTypeEnumeration.boolean: fis.bw.Write((bool)valu); * case PTypeEnumeration.character: fis.bw.Write((short)valu); * case PTypeEnumeration.integer: fis.bw.Write((int)valu); * case PTypeEnumeration.longinteger: fis.bw.Write((long)valu); * case PTypeEnumeration.real: fis.bw.Write((double)valu); * case PTypeEnumeration.sstring: * { * int len = fis.br.ReadInt32(); * long off = fis.br.ReadInt64(); * if (len > 0) * { * fis.SetOffset(off); * byte[] b = fis.br.ReadBytes(len * 2); * return Encoding.Unicode.GetString(b); * } * else return ""; * } * case PTypeEnumeration.record: * { * PTypeRecord r_tp = (PTypeRecord)typ; * object[] fields = new object[r_tp.Fields.Length]; * long off = offse; * for (int i = 0; i < r_tp.Fields.Length; i++) * { * PType ftyp = r_tp.Fields[i].Type; * fields[i] = GetPObject(ftyp, off, fis); * off += ftyp.HeadSize; * } * return fields; * } * case PTypeEnumeration.sequence: * { * PTypeSequence mts = (PTypeSequence)typ; * PType tel = mts.ElementType; * long llen = fis.br.ReadInt64(); * fis.br.ReadInt64(); * long off = fis.br.ReadInt64(); * object[] els = new object[llen]; * for (long ii = 0; ii < llen; ii++) * { * els[ii] = GetPObject(tel, off, fis); * off += tel.HeadSize; * } * return els; * } * case PTypeEnumeration.union: * { * PTypeUnion mtu = (PTypeUnion)typ; * int v = fis.br.ReadByte(); * long off = fis.br.ReadInt64(); * PType mt = mtu.Variants[v].Type; * if (mt.IsAtom) return new object[] { v, GetPObject(mt, offse + 1, fis) }; * else return new object[] { v, GetPObject(mt, off, fis) }; * } * * default: throw new Exception("Err in TPath Get(): type is not implemented " + typ.Vid); * } * } */ private static object GetPObject(PType typ, long offse, PxCell fis) { fis.SetOffset(offse); switch (typ.Vid) { case PTypeEnumeration.none: return(null); case PTypeEnumeration.boolean: return(fis.br.ReadBoolean()); case PTypeEnumeration.character: return(fis.br.ReadChar()); case PTypeEnumeration.integer: return(fis.br.ReadInt32()); case PTypeEnumeration.longinteger: return(fis.br.ReadInt64()); case PTypeEnumeration.real: return(fis.br.ReadDouble()); case PTypeEnumeration.@byte: return(fis.br.ReadByte()); case PTypeEnumeration.sstring: { int len = fis.br.ReadInt32(); long off = fis.br.ReadInt64(); if (len > 0) { fis.SetOffset(off); byte[] b = fis.br.ReadBytes(len * 2); return(Encoding.Unicode.GetString(b)); } else { return(""); } } case PTypeEnumeration.fstring: { int size = ((PTypeFString)typ).Size; byte[] arr = new byte[size]; arr = fis.br.ReadBytes(size); int count = size / 2; while (count > 0 && arr[2 * count - 1] == 0 && arr[2 * count - 2] == 0) { count--; } string s = System.Text.Encoding.Unicode.GetString(arr, 0, 2 * count); return(s); } case PTypeEnumeration.record: { PTypeRecord r_tp = (PTypeRecord)typ; object[] fields = new object[r_tp.Fields.Length]; long off = offse; for (int i = 0; i < r_tp.Fields.Length; i++) { PType ftyp = r_tp.Fields[i].Type; fields[i] = GetPObject(ftyp, off, fis); off += ftyp.HeadSize; } return(fields); } case PTypeEnumeration.sequence: { PTypeSequence mts = (PTypeSequence)typ; PType tel = mts.ElementType; long llen = fis.br.ReadInt64(); fis.br.ReadInt64(); long off = fis.br.ReadInt64(); object[] els = new object[llen]; for (long ii = 0; ii < llen; ii++) { els[ii] = GetPObject(tel, off, fis); off += tel.HeadSize; } return(els); } case PTypeEnumeration.union: { PTypeUnion mtu = (PTypeUnion)typ; int v = fis.br.ReadByte(); PType mt = mtu.Variants[v].Type; long off = fis.br.ReadInt64(); if (mt.IsAtom) { return new object[] { v, off == -1L ? null : fis.ReadAtomFromLong(mt.Vid, offse + 1) } } ; else { return(new object[] { v, GetPObject(mt, off, fis) }); } } default: throw new Exception("Err in TPath Get(): type is not implemented " + typ.Vid); } }
public PxCell fis; //TODO: Надо защитить это поле public PxEntry(PType tp, long offset, PxCell fis) { this.typ = tp; this.offset = offset; this.fis = fis; }