// 読み込む 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 List <WpcEntry> ParseDataEntry(string str) { Buf src = new Buf(Str.AsciiEncoding.GetBytes(str)); List <WpcEntry> o = new List <WpcEntry>(); while (true) { byte[] entryNameByte = src.Read(4); if (entryNameByte.Length != 4) { break; } byte[] sizeStrByte = src.Read(10); if (sizeStrByte.Length != 10) { break; } string sizeStr = Str.AsciiEncoding.GetString(sizeStrByte); uint size = Str.StrToUInt(sizeStr); byte[] strData = src.Read(size); if ((uint)strData.Length != size) { break; } string payload = Str.AsciiEncoding.GetString(strData); byte[] data = Wpc.StrToByte(payload); WpcEntry e = new WpcEntry(entryNameByte, data); o.Add(e); } return(o); }
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); }