internal void WriteMap(MProto proto, MioMap meta, Dictionary <object, object> data) { if (data == null) { proto.WriteMapBegin(new MMap(meta.Key.Type, meta.Value.Type, 0)); return; } var map = new MMap(meta.Key.Type, meta.Value.Type, data.Count); proto.WriteMapBegin(map); foreach (var entry in data) { Write(proto, meta.Key, entry.Key); Write(proto, meta.Value, entry.Value); } }
internal Dictionary <object, object> ReadMap(MProto proto, MioMap meta) { if (meta == null) { return(null); } var map = proto.ReadMapBegin(); if (map.KeyType != meta.Key.Type || map.ValueType != meta.Value.Type) { SkipMap(proto, map); return(null); } var res = new Dictionary <object, object>(); for (int i = 0; i < map.Count; i++) { var key = Read(proto, meta.Key); var val = Read(proto, meta.Value); res.Add(key, val); } return(res); }
internal void WriteMap(MProto proto, MioMap meta, Dictionary<object, object> data) { if (data == null) { proto.WriteMapBegin(new MMap(meta.Key.Type, meta.Value.Type, 0)); return; } var map = new MMap(meta.Key.Type, meta.Value.Type, data.Count); proto.WriteMapBegin(map); foreach (var entry in data) { Write(proto, meta.Key, entry.Key); Write(proto, meta.Value, entry.Value); } }
internal Dictionary<object, object> ReadMap(MProto proto, MioMap meta) { if (meta == null) return null; var map = proto.ReadMapBegin(); if (map.KeyType != meta.Key.Type || map.ValueType != meta.Value.Type) { SkipMap(proto, map); return null; } var res = new Dictionary<object, object>(); for (int i = 0; i < map.Count; i++) { var key = Read(proto, meta.Key); var val = Read(proto, meta.Value); res.Add(key, val); } return res; }