public DxRecordValue NewRecord(string keyName) { if (keyName == "") { return(null); } DxBaseValue value = null; bool haskey = records.TryGetValue(keyName, out value); if (haskey) { if (value.Type == ValueType.VT_Map) { ((DxRecordValue)value).Clear(); return((DxRecordValue)value); } else if (value.Type == ValueType.VT_Array) { ((DxArrayValue)value).Clear(); } } DxRecordValue result = new DxRecordValue(); result.parent = this; if (haskey) { records[keyName] = result; } else { records.Add(keyName, result); } return(result); }
public DxArrayValue ForcePathArray(string path) { string[] pathNames = path.Split('.'); if (pathNames.Length == 0) { return(null); } DxBaseValue vbase = this[pathNames[0]]; if (vbase == null || vbase.Type != ValueType.VT_Map) { vbase = NewRecord(pathNames[0]); } for (int i = 1; i < pathNames.Length - 1; i++) { DxRecordValue oldbase = (DxRecordValue)vbase; if (vbase.Type == ValueType.VT_Map) { vbase = ((DxRecordValue)vbase)[pathNames[i]]; if (vbase == null || vbase.Type != ValueType.VT_Map) { vbase = oldbase.NewRecord(pathNames[i]); } } else { vbase = vbase.Parent; vbase = ((DxRecordValue)vbase).NewRecord(pathNames[i - 1]).NewRecord(pathNames[i]); } } return(((DxRecordValue)vbase).NewArray(pathNames[pathNames.Length - 1])); }
void btnEncodeClick() { DxValue.DxRecordValue v = new DxValue.DxRecordValue(); v.SetString("Name", "不得闲"); v.SetInt("Age", 23); v.SetDouble("money", 234234234.234); v.SetDateTime("Date", System.DateTime.Now); DxValue.DxArrayValue arr = v.ForcePathArray("test.data"); arr.SetString(-1, "gas"); //-1就是表示在末尾加 arr.SetString(1, "234"); arr.SetDateTime(4, System.DateTime.Now); Debug.Log(v.AsString); byte[] bt = v.AsMsgPackBytes; DxValue.DxRecordValue newValue = new DxValue.DxRecordValue(); newValue.AsMsgPackBytes = bt; Debug.Log(newValue.AsString); DxValue.DxArrayValue arr1 = newValue.ArrayByPath("test.data"); if (arr1 != null) { Debug.Log(arr1.AsString); byte[] arrybt = arr1.AsMsgPackBytes; arr1.Clear(); Debug.Log(arr1.AsString); arr1.AsMsgPackBytes = arrybt; Debug.Log(arr1.AsString); } }
void btnParseClick() { System.IO.FileStream stream = new System.IO.FileStream("d:\\1.bin", System.IO.FileMode.Open); DxMsgPack.DxMsgPack.Decoder decoder = new DxMsgPack.DxMsgPack.Decoder(stream); stream.Close(); DxValue.DxRecordValue bv = (DxValue.DxRecordValue)decoder.Parser(); DxValue.DxRecordValue test = bv.ForcePathRecord("code.data"); Debug.Log(bv.AsString); }
public DxRecordValue NewRecord(int idx) { idx = ifNilInitArr2idx(idx); DxBaseValue v = arrayList[idx]; if (v != null) { switch (v.Type) { case ValueType.VT_Map: return((DxRecordValue)v); case ValueType.VT_Array: ((DxArrayValue)v).Clear(); break; } } DxRecordValue result = new DxRecordValue(); result.Parent = this; arrayList[idx] = result; return(result); }
private void btnMapClick() { DxValue.DxRecordValue mapValue = new DxValue.DxRecordValue(); mapValue.SetInt("code", 0); mapValue.SetString("msg", "消息返回成功"); DxValue.DxArrayValue arr = mapValue.ForcePathArray("Data.Records"); for (int i = 0; i < 4; i++) { DxValue.DxRecordValue rec = arr.NewRecord(-1); rec.SetString("Name", "不得闲" + i); rec.SetInt("Age", 35); rec.SetString("sex", "男"); rec.SetDateTime("Birth", System.DateTime.Now); rec.SetDouble("Money", 2224495.9323); rec.SetString("mobile", "13129903278"); } DxValue.DxRecordValue datamap = (DxValue.DxRecordValue)mapValue["Data"]; datamap.SetString("msg", "人物信息表"); Debug.Log(mapValue.AsString); Debug.Log(mapValue.GetInt("code", -1)); arr = (DxValue.DxArrayValue)mapValue.ValueByPath("Data.Records"); Debug.Log(((DxValue.DxRecordValue)arr[0]).GetString("Name", "test")); }