| | | 1 | | using MessagePack; |
| | | 2 | | using MessagePack.Formatters; |
| | | 3 | | using MessagePack.Resolvers; |
| | | 4 | | |
| | | 5 | | namespace NLightning.Transport.Ipc.MessagePack; |
| | | 6 | | |
| | | 7 | | using Domain.Bitcoin.ValueObjects; |
| | | 8 | | using Domain.Channels.ValueObjects; |
| | | 9 | | using Domain.Crypto.ValueObjects; |
| | | 10 | | using Domain.Money; |
| | | 11 | | using Domain.Node; |
| | | 12 | | using Domain.Node.ValueObjects; |
| | | 13 | | using Domain.Protocol.ValueObjects; |
| | | 14 | | using Formatters; |
| | | 15 | | |
| | | 16 | | public class NLightningFormatterResolver : IFormatterResolver |
| | | 17 | | { |
| | 0 | 18 | | private readonly Dictionary<Type, object> _formatters = new(); |
| | | 19 | | |
| | 0 | 20 | | public static readonly IFormatterResolver Instance = new NLightningFormatterResolver(); |
| | | 21 | | |
| | 0 | 22 | | private NLightningFormatterResolver() |
| | 0 | 23 | | { |
| | 0 | 24 | | _formatters[typeof(Hash)] = new HashFormatter(); |
| | 0 | 25 | | _formatters[typeof(BitcoinNetwork)] = new BitcoinNetworkFormatter(); |
| | 0 | 26 | | _formatters[typeof(PeerAddressInfo?)] = new PeerAddressInfoNullableFormatter(); |
| | 0 | 27 | | _formatters[typeof(PeerAddressInfo)] = new PeerAddressInfoFormatter(); |
| | 0 | 28 | | _formatters[typeof(CompactPubKey?)] = new CompactPubKeyNullableFormatter(); |
| | 0 | 29 | | _formatters[typeof(CompactPubKey)] = new CompactPubKeyFormatter(); |
| | 0 | 30 | | _formatters[typeof(FeatureSet)] = new FeatureSetFormatter(); |
| | 0 | 31 | | _formatters[typeof(LightningMoney)] = new LightningMoneyFormatter(); |
| | 0 | 32 | | _formatters[typeof(SignedTransaction)] = new SignedTransactionFormatter(); |
| | 0 | 33 | | _formatters[typeof(ChannelId)] = new ChannelIdFormatter(); |
| | 0 | 34 | | _formatters[typeof(TxId)] = new TxIdFormatter(); |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | public IMessagePackFormatter<T>? GetFormatter<T>() |
| | 0 | 38 | | { |
| | 0 | 39 | | if (_formatters.TryGetValue(typeof(T), out var formatter)) |
| | 0 | 40 | | { |
| | 0 | 41 | | return (IMessagePackFormatter<T>)formatter; |
| | | 42 | | } |
| | | 43 | | |
| | 0 | 44 | | return StandardResolver.Instance.GetFormatter<T>(); |
| | 0 | 45 | | } |
| | | 46 | | } |