// 読み込む public static PackElement CreateFromBuf(Buf b) { // 名前 string name = b.ReadStr(true); // 種類 PackValueType type = (PackValueType)b.ReadInt(); // 項目数 uint num = b.ReadInt(); PackElement e = new PackElement(name, type); // 値 uint i; for (i = 0; i < num; i++) { PackValue v = PackValue.CreateFromBuf(b, i, type) !; e.AddValue(v); } return(e); }
PackElement getElementAndCreateIfNotExists(string name, PackValueType type) { PackElement?e = getElement(name); if (e != null) { return(e); } e = new PackElement(name, type); addElement(e); return(e); }
// 要素の取得 PackElement?getElement(string name) { PackElement t = new PackElement(name, PackValueType.Int); if (elementsSorted == false) { elements.Sort(); elementsSorted = true; } int i = elements.BinarySearch(t); if (i < 0) { return(null); } else { return(elements[i]); } }
// 読み込む public static Pack CreateFromBuf(Buf b) { Pack p = new Pack(); uint i, num; if (b.Size > Pack.MaxPackSize) { throw new OverflowException(); } num = b.ReadInt(); if (num > Pack.MaxElementNum) { throw new OverflowException(); } for (i = 0; i < num; i++) { p.addElement(PackElement.CreateFromBuf(b)); } return(p); }
public void AddData(string name, byte[] data, uint index) { PackElement e = getElementAndCreateIfNotExists(name, PackValueType.Data); e.AddValue(new PackValue(index, data)); }
public void AddInt64(string name, ulong int64Value, uint index) { PackElement e = getElementAndCreateIfNotExists(name, PackValueType.Int64); e.AddValue(new PackValue(index, int64Value)); }
public void AddUniStr(string name, string strValue, uint index) { PackElement e = getElementAndCreateIfNotExists(name, PackValueType.UniStr); e.AddValue(new PackValue(index, strValue)); }
// 要素の追加 void addElement(PackElement e) { elements.Add(e); elementsSorted = false; }
int IComparable.CompareTo(object?obj) { PackElement e = (PackElement)obj !; return(this.name.ToUpper().CompareTo(e.name.ToUpper())); }