(ReadContext context)
| 206 | } |
| 207 | |
| 208 | public override TDictionary ReadData(ReadContext context) |
| 209 | { |
| 210 | Serializer<TKey> keySerializer = context.TypeResolver.GetSerializer<TKey>(); |
| 211 | Serializer<TValue> valueSerializer = context.TypeResolver.GetSerializer<TValue>(); |
| 212 | TypeInfo keyTypeInfo = context.TypeResolver.GetTypeInfo<TKey>(); |
| 213 | TypeInfo valueTypeInfo = context.TypeResolver.GetTypeInfo<TValue>(); |
| 214 | int totalLength = checked((int)context.Reader.ReadVarUInt32()); |
| 215 | if (totalLength == 0) |
| 216 | { |
| 217 | return CreateMap(0); |
| 218 | } |
| 219 | |
| 220 | context.Reader.CheckBound(totalLength); |
| 221 | TDictionary map = CreateMap(totalLength); |
| 222 | bool keyDynamicType = keyTypeInfo.IsDynamicType; |
| 223 | bool valueDynamicType = valueTypeInfo.IsDynamicType; |
| 224 | int readCount = 0; |
| 225 | while (readCount < totalLength) |
| 226 | { |
| 227 | byte header = context.Reader.ReadUInt8(); |
| 228 | // IMPORTANT: dictionary readers must obey the sender-written |
| 229 | // key/value ref bits in the wire header. Local C# field metadata |
| 230 | // must not override that decision while reading. Shared xlang |
| 231 | // tests intentionally deserialize one ref policy and then |
| 232 | // serialize another local payload. DO NOT REMOVE this comment. |
| 233 | bool trackKeyRef = (header & DictionaryBits.TrackingKeyRef) != 0; |
| 234 | bool keyNull = (header & DictionaryBits.KeyNull) != 0; |
| 235 | bool keyDeclared = (header & DictionaryBits.DeclaredKeyType) != 0; |
| 236 | bool trackValueRef = (header & DictionaryBits.TrackingValueRef) != 0; |
| 237 | bool valueNull = (header & DictionaryBits.ValueNull) != 0; |
| 238 | bool valueDeclared = (header & DictionaryBits.DeclaredValueType) != 0; |
| 239 | |
| 240 | if (keyNull && valueNull) |
| 241 | { |
| 242 | // Dictionary-like containers cannot represent a null key. |
| 243 | // Drop this entry instead of mapping it to default(TKey), which would corrupt key semantics. |
| 244 | readCount += 1; |
| 245 | continue; |
| 246 | } |
| 247 | |
| 248 | if (keyNull) |
| 249 | { |
| 250 | _ = ReadValueElement( |
| 251 | context, |
| 252 | trackValueRef, |
| 253 | !valueDeclared, |
| 254 | valueSerializer); |
| 255 | |
| 256 | // Preserve stream/reference state by reading value payload, then skip null-key entry. |
| 257 | readCount += 1; |
| 258 | continue; |
| 259 | } |
| 260 | |
| 261 | if (valueNull) |
| 262 | { |
| 263 | TKey key = keySerializer.Read( |
| 264 | context, |
| 265 | trackKeyRef ? RefMode.Tracking : RefMode.None, |
nothing calls this directly
no test coverage detected