// 読み込む public static Value CreateFromBuf(Buf b, uint index, ValueType type) { switch (type) { case ValueType.Int: return(new Value(index, b.ReadInt())); case ValueType.Int64: return(new Value(index, b.ReadInt64())); case ValueType.Str: return(new Value(index, b.ReadStr().Trim())); case ValueType.UniStr: uint len = b.ReadInt(); if (len == 0) { return(new Value(index, "")); } else { byte[] data = b.Read(len - 1); b.Read(1); return(new Value(index, Str.Utf8Encoding.GetString(data).Trim())); } case ValueType.Data: uint size = b.ReadInt(); return(new Value(index, b.Read(size))); } return(null); }
public static FullRouteIPInfoCache LoadFromBuf(Buf b) { b.Seek(b.Size - 20, SeekOrigin.Begin); byte[] hash = b.Read(20); b.SeekToBegin(); byte[] hash2 = Secure.HashSHA1(Util.CopyByte(b.ByteData, 0, (int)b.Size - 20)); if (Util.CompareByte(hash, hash2) == false) { throw new ApplicationException("Invalid Hash"); } FullRouteIPInfoCache ret = new FullRouteIPInfoCache(); ret.TimeStamp = new DateTime((long)b.ReadInt64()); int num = (int)b.ReadInt(); int i; for (i = 0; i < num; i++) { FullRouteIPInfoEntry e = new FullRouteIPInfoEntry(); e.From = b.ReadInt(); e.To = b.ReadInt(); e.Registry = b.ReadStr(); e.Assigned = b.ReadInt(); e.Country2 = b.ReadStr(); e.Country3 = b.ReadStr(); e.CountryFull = DeleteSemi(b.ReadStr()); ret.EntryList.Add(e); } ret.EntryList.Sort(); ret.build_country_code_to_name_db(); return(ret); }