private TdfMap DecodeTdfMap(string label) { // read list types var listType1 = (TdfBaseType)_stream.ReadByte(); var listType2 = (TdfBaseType)_stream.ReadByte(); // read list size int listSize = _stream.ReadByte(); var map = new TdfMap(label, listType1, listType2, new Dictionary <object, object>()); // read list Func <TdfBaseType, Object> readListItem = (type) => { Object item = null; switch (type) { case TdfBaseType.Integer: item = DecodeInteger(); break; case TdfBaseType.String: item = DecodeString(); break; case TdfBaseType.Struct: item = DecodeStruct(); break; default: Log.Warn(string.Format("Unknown list item type: {0}", type)); break; } return(item); }; for (int i = 0; i < listSize; i++) { Object key = readListItem(listType1); Object value = readListItem(listType2); if (key != null | value != null) { map.Map.Add(key, value); } } return(map); }
private void WriteTdfMap(TdfMap tdf) { // write list types _stream.WriteByte((byte)tdf.KeyType); _stream.WriteByte((byte)tdf.ValueType); // write list size _stream.WriteByte((byte)tdf.Map.Count); // write map Action <TdfBaseType, Object> writeListItem = (type, item) => { switch (type) { case TdfBaseType.Integer: WriteInteger((ulong)item); break; case TdfBaseType.String: WriteString((string)item); break; case TdfBaseType.Struct: WriteStruct((List <Tdf>)item); break; default: Log.Warn(string.Format("Unknown list item type: {0}", type)); break; } }; foreach (var item in tdf.Map) { writeListItem(tdf.KeyType, item.Key); writeListItem(tdf.ValueType, item.Value); } }
private void WriteTdfMap(TdfMap tdf) { // write list types _stream.WriteByte((byte)tdf.KeyType); _stream.WriteByte((byte)tdf.ValueType); // write list size _stream.WriteByte((byte)tdf.Map.Count); // write map Action<TdfBaseType, Object> writeListItem = (type, item) => { switch (type) { case TdfBaseType.Integer: WriteInteger((ulong)item); break; case TdfBaseType.String: WriteString((string)item); break; case TdfBaseType.Struct: WriteStruct((List<Tdf>)item); break; default: Log.Warn(string.Format("Unknown list item type: {0}", type)); break; } }; foreach (var item in tdf.Map) { writeListItem(tdf.KeyType, item.Key); writeListItem(tdf.ValueType, item.Value); } }
private TdfMap DecodeTdfMap(string label) { // read list types var listType1 = (TdfBaseType)_stream.ReadByte(); var listType2 = (TdfBaseType)_stream.ReadByte(); // read list size int listSize = _stream.ReadByte(); var map = new TdfMap(label, listType1, listType2, new Dictionary<object, object>()); // read list Func<TdfBaseType, Object> readListItem = (type) => { Object item = null; switch (type) { case TdfBaseType.Integer: item = DecodeInteger(); break; case TdfBaseType.String: item = DecodeString(); break; case TdfBaseType.Struct: item = DecodeStruct(); break; default: Log.Warn(string.Format("Unknown list item type: {0}", type)); break; } return item; }; for (int i = 0; i < listSize; i++) { Object key = readListItem(listType1); Object value = readListItem(listType2); if (key != null | value != null) { map.Map.Add(key, value); } } return map; }