Esempio n. 1
0
        sizeof(ushort);     // Port

        /// <summary>
        /// Initializes a new instance of the <see cref="ServerCapability"/> class.
        /// </summary>
        /// <param name="type">The type of the <see cref="ServerCapability"/>. It must be <see cref="NodeCapabilityType.TcpServer"/> or <see cref="NodeCapabilityType.WsServer"/></param>
        /// <param name="port">The port that the node is listening on.</param>
        public ServerCapability(NodeCapabilityType type, ushort port = 0) : base(type)
        {
            if (type != NodeCapabilityType.TcpServer && type != NodeCapabilityType.WsServer)
            {
                throw new ArgumentException(nameof(type));
            }

            Port = port;
        }
Esempio n. 2
0
        /// <summary>
        /// Deserializes an <see cref="NodeCapability"/> object from a <see cref="MemoryReader"/>.
        /// </summary>
        /// <param name="reader">The <see cref="MemoryReader"/> for reading data.</param>
        /// <returns>The deserialized <see cref="NodeCapability"/>.</returns>
        public static NodeCapability DeserializeFrom(ref MemoryReader reader)
        {
            NodeCapabilityType type       = (NodeCapabilityType)reader.ReadByte();
            NodeCapability     capability = type switch
            {
                NodeCapabilityType.TcpServer or NodeCapabilityType.WsServer => new ServerCapability(type),
                NodeCapabilityType.FullNode => new FullNodeCapability(),
                _ => throw new FormatException(),
            };

            capability.DeserializeWithoutType(ref reader);
            return(capability);
        }
Esempio n. 3
0
        public static NodeCapability DeserializeFrom(BinaryReader reader)
        {
            NodeCapability     capability;
            NodeCapabilityType type = (NodeCapabilityType)reader.ReadByte();

            switch (type)
            {
            case NodeCapabilityType.TcpServer:
            case NodeCapabilityType.WsServer:
                capability = new ServerCapability(type);
                break;

            case NodeCapabilityType.FullNode:
                capability = new FullNodeCapability();
                break;

            default:
                throw new FormatException();
            }
            capability.DeserializeWithoutType(reader);
            return(capability);
        }
Esempio n. 4
0
        public virtual int Size => sizeof(NodeCapabilityType); // Type

        /// <summary>
        /// Initializes a new instance of the <see cref="NodeCapability"/> class.
        /// </summary>
        /// <param name="type">The type of the <see cref="NodeCapability"/>.</param>
        protected NodeCapability(NodeCapabilityType type)
        {
            this.Type = type;
        }