C# Класс OpenNos.Core.Networking.Communication.Scs.Communication.Protocols.BinarySerialization.BinarySerializationProtocol

Default communication protocol between server and clients to send and receive a message. It uses .NET binary serialization to write and read messages. A Message format: [Message Length (4 bytes)][Serialized Message Content] If a message is serialized to byte array as N bytes, this protocol adds 4 bytes size information to head of the message bytes, so total length is (4 + N) bytes. This class can be derived to change serializer (default: BinaryFormatter). To do this, SerializeMessage and DeserializeMessage methods must be overrided.
Наследование: IScsWireProtocol, IDisposable
Показать файл Открыть проект

Открытые методы

Метод Описание
BinarySerializationProtocol ( ) : System

Creates a new instance of BinarySerializationProtocol.

CreateMessages ( byte receivedBytes ) : IEnumerable

Builds messages from a byte array that is received from remote application. The Byte array may contain just a part of a message, the protocol must cumulate bytes to build messages. This method is synchronized. So, only one thread can call it concurrently.

Dispose ( ) : void
GetBytes ( IScsMessage message ) : byte[]

Serializes a message to a byte array to send to remote application. This method is synchronized. So, only one thread can call it concurrently.

Reset ( ) : void

This method is called when connection with remote application is reset (connection is renewing or first connecting). So, wire protocol must reset itself.

Защищенные методы

Метод Описание
DeserializeMessage ( byte bytes ) : IScsMessage

This method is used to deserialize a IScsMessage from it's bytes. This method can be overrided by derived Classs to change deserialization strategy. It is a couple with SerializeMessage method and must be overrided together.

Dispose ( bool disposing ) : void
SerializeMessage ( IScsMessage message ) : byte[]

This method is used to serialize a IScsMessage to a byte array. This method can be overrided by derived Classs to change serialization strategy. It is a couple with DeserializeMessage method and must be overrided together.

Приватные методы

Метод Описание
ReadByteArray ( Stream stream, int length ) : byte[]

Reads a byte array with specified length.

ReadSingleMessage ( ICollection messages ) : bool

This method tries to read a single message and add to the messages collection.

WriteInt32 ( byte buffer, int startIndex, int number ) : void

Writes a int value to a byte array from a starting index.

Описание методов

BinarySerializationProtocol() публичный Метод

Creates a new instance of BinarySerializationProtocol.
public BinarySerializationProtocol ( ) : System
Результат System

CreateMessages() публичный Метод

Builds messages from a byte array that is received from remote application. The Byte array may contain just a part of a message, the protocol must cumulate bytes to build messages. This method is synchronized. So, only one thread can call it concurrently.
public CreateMessages ( byte receivedBytes ) : IEnumerable
receivedBytes byte Received bytes from remote application
Результат IEnumerable

DeserializeMessage() защищенный Метод

This method is used to deserialize a IScsMessage from it's bytes. This method can be overrided by derived Classs to change deserialization strategy. It is a couple with SerializeMessage method and must be overrided together.
protected DeserializeMessage ( byte bytes ) : IScsMessage
bytes byte /// Bytes of message to be deserialized (does not include message length. It consist of a /// single whole message) ///
Результат IScsMessage

Dispose() публичный Метод

public Dispose ( ) : void
Результат void

Dispose() защищенный Метод

protected Dispose ( bool disposing ) : void
disposing bool
Результат void

GetBytes() публичный Метод

Serializes a message to a byte array to send to remote application. This method is synchronized. So, only one thread can call it concurrently.
/// Throws CommunicationException if message is bigger than maximum allowed message length. ///
public GetBytes ( IScsMessage message ) : byte[]
message IScsMessage Message to be serialized
Результат byte[]

Reset() публичный Метод

This method is called when connection with remote application is reset (connection is renewing or first connecting). So, wire protocol must reset itself.
public Reset ( ) : void
Результат void

SerializeMessage() защищенный Метод

This method is used to serialize a IScsMessage to a byte array. This method can be overrided by derived Classs to change serialization strategy. It is a couple with DeserializeMessage method and must be overrided together.
protected SerializeMessage ( IScsMessage message ) : byte[]
message IScsMessage Message to be serialized
Результат byte[]