public override byte[] ToBinary(object obj) { if (obj is Write) { return(writeCache.GetOrAdd((Write)obj)); } if (obj is Read) { return(readCache.GetOrAdd((Read)obj)); } if (obj is WriteAck) { return(writeAckBytes); } return(Serialize(obj)); }
public override byte[] ToBinary(object obj) { switch (obj) { case DataEnvelope envelope: return(DataEnvelopeToProto(envelope).ToByteArray()); case Write write: return(_writeCache.GetOrAdd(write)); case WriteAck _: return(_empty); case Read read: return(_readCache.GetOrAdd(read)); case ReadResult result: return(ReadResultToProto(result).ToByteArray()); case DeltaPropagation propagation: return(DeltaPropagationToProto(propagation).ToByteArray()); case Status status: return(StatusToProto(status).ToByteArray()); case Get get: return(GetToProto(get).ToByteArray()); case GetSuccess success: return(GetSuccessToProto(success).ToByteArray()); case Durable.DurableDataEnvelope envelope: return(DurableDataEnvelopeToProto(envelope).ToByteArray()); case Changed changed: return(ChangedToProto(changed).ToByteArray()); case NotFound found: return(NotFoundToProto(found).ToByteArray()); case GetFailure failure: return(GetFailureToProto(failure).ToByteArray()); case Subscribe subscribe: return(SubscribeToProto(subscribe).ToByteArray()); case Unsubscribe unsubscribe: return(UnsubscribeToProto(unsubscribe).ToByteArray()); case Gossip gossip: return(SerializationSupport.Compress(GossipToProto(gossip))); case WriteNack _: return(_empty); case DeltaNack _: return(_empty); default: throw new ArgumentException($"Can't serialize object of type [{obj.GetType().FullName}] using [{GetType().FullName}]"); } }