コード例 #1
0
        public static IPEndPointSerializer Register(SerializationContext context)
        {
            var serializer = new IPEndPointSerializer(context);

            context.Serializers.RegisterOverride(serializer);

            return(serializer);
        }
コード例 #2
0
        public WireSerialization()
        {
            IPEndPointSerializer.Register();

            _ConsensusExtSerializers     = new Dictionary <Type, MessagePackSerializer>();
            _ConsensusExtTypes           = new Dictionary <byte, Type>();
            _NetworkingPayloadTypes      = new Dictionary <string, Type>();
            _EmptyNetworkingPayloadTypes = new List <Type>();
            _NetworkingPayloadCodes      = new Dictionary <Type, string>();

            var mapping = Consensus.Serialization.context.ExtTypeCodeMapping;

            foreach (var item in mapping)
            {
                Type type;
                switch (item.Key)
                {
                case "Transaction":
                    type = typeof(Consensus.Types.Transaction);
                    _ConsensusExtSerializers[type]        = Consensus.Serialization.context.GetSerializer <Consensus.Types.Transaction>();
                    _ConsensusExtTypes[mapping[item.Key]] = type;
                    break;

                case "Block":
                    type = typeof(Consensus.Types.Block);
                    _ConsensusExtSerializers[type]        = Consensus.Serialization.context.GetSerializer <Consensus.Types.Block>();
                    _ConsensusExtTypes[mapping[item.Key]] = type;
                    break;
                }
            }

            _NetworkingPayloadTypes["addr"]    = typeof(AddrPayload);
            _NetworkingPayloadTypes["getaddr"] = typeof(GetAddrPayload);
            _NetworkingPayloadTypes["getdata"] = typeof(GetDataPayload);
            _NetworkingPayloadTypes["inv"]     = typeof(InvPayload);
            _NetworkingPayloadTypes["ping"]    = typeof(PingPayload);
            _NetworkingPayloadTypes["pong"]    = typeof(PongPayload);
            _NetworkingPayloadTypes["reject"]  = typeof(RejectPayload);
            _NetworkingPayloadTypes["ver"]     = typeof(VersionPayload);
            _NetworkingPayloadTypes["verack"]  = typeof(VerAckPayload);
            _NetworkingPayloadTypes["gettip"]  = typeof(GetTipPayload);

            _EmptyNetworkingPayloadTypes.Add(typeof(VerAckPayload));
            _EmptyNetworkingPayloadTypes.Add(typeof(GetAddrPayload));
            _EmptyNetworkingPayloadTypes.Add(typeof(GetTipPayload));

            foreach (var item in _NetworkingPayloadTypes)
            {
                _NetworkingPayloadCodes[item.Value] = item.Key;
            }
        }