public void Write(ref ProtoWriter.State state, KeyValuePair <TKey, TValue> value) { // this deals with nulls and implicit zeros if (TypeHelper <TKey> .ValueChecker.HasNonTrivialValue(value.Key)) { state.WriteAny(1, _keyFeatures, value.Key, _keySerializer); } // this deals with nulls and implicit zeros if (TypeHelper <TValue> .ValueChecker.HasNonTrivialValue(value.Value)) { state.WriteAny(2, _valueFeatures, value.Value, _valueSerializer); } }
protected override bool TrySerializeAny(int fieldNumber, SerializerFeatures features, TypeModel model, ref ProtoWriter.State state, object value) { var serializer = TypeModel.TryGetSerializer <T>(model); if (serializer == null) { return(false); } // note this null-check is non-trivial; for value-type T it promotes the null to a default T typed = TypeHelper <T> .FromObject(value); CheckAnyAuxFlow(features, serializer); if ((features & SerializerFeatures.CategoryMessageWrappedAtRoot) == SerializerFeatures.CategoryMessageWrappedAtRoot) { if (fieldNumber != TypeModel.ListItemTag) { ThrowHelper.ThrowInvalidOperationException($"Special root-like wrapping is limited to field {TypeModel.ListItemTag}"); } state.WriteAsRoot <T>(typed, serializer); } else { state.WriteAny <T>(fieldNumber, features, typed, serializer); } return(true); }