You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now when creating a Marshaller<T>, you can only specify either the legacy or contextual serializer. If you use the contextual API, it creates intentionally broken delegates for the legacy API:
// gRPC only uses contextual serializer/deserializer internally, so emulating the legacy// (de)serializer is not necessary.this.serializer =(msg)=>{thrownew NotImplementedException();};this.deserializer =(payload)=>{thrownew NotImplementedException();};
What would be ideal is if we had another constructor, to allow the configuring code to specify both a contextual and legacy API; if the legacy API is omitted, then sure: omit them. By which I mean:
publicMarshaller(
Action<T, SerializationContext> serializer,
Func<DeserializationContext, T> deserializer): this(serializer,deserializer,null,null){}publicMarshaller(
Action<T, SerializationContext> contextualSerializer,
Func<DeserializationContext, T> contextualDeserializer,
Action<T, SerializationContext> legacySerializer,
Func<DeserializationContext, T> legacyDeserializer){this.contextualSerializer = GrpcPreconditions.CheckNotNull(contextualSerializer, nameof(contextualSerializer));this.contextualDeserializer = GrpcPreconditions.CheckNotNull(contextualDeserializer, nameof(contextualDeserializer));// gRPC only uses contextual serializer/deserializer internally, so emulating the legacy// (de)serializer (when they are not provided by the caller) is not necessary.this.serializer =legacySerializer??((msg)=>{thrownew NotImplementedException();});this.deserializer =legacyDeserializer??((payload)=>{thrownew NotImplementedException();});}
This would allow callers to supply "best and fallback" implementations, so that it can at least work on all hosts, even if it doesn't get the full advantages if the host only consumes the legacy API.
Happy to do a PR if it is viable.
The text was updated successfully, but these errors were encountered:
mgravell
changed the title
csharp marshaller : ability to specify legacy *and* contextual serializer
csharp marshaller : emulate legacy serializer via contextual API, or provide ability to specify legacy *and* contextual serializer
Jun 27, 2019
Right now when creating a
Marshaller<T>
, you can only specify either the legacy or contextual serializer. If you use the contextual API, it creates intentionally broken delegates for the legacy API:This is fine for Grpc.Core, but breaks if another host wants to use the legacy API (possibly to avoid the "experimental" API surface).
What would be ideal is if we had another constructor, to allow the configuring code to specify both a contextual and legacy API; if the legacy API is omitted, then sure: omit them. By which I mean:
This would allow callers to supply "best and fallback" implementations, so that it can at least work on all hosts, even if it doesn't get the full advantages if the host only consumes the legacy API.
Happy to do a PR if it is viable.
The text was updated successfully, but these errors were encountered: