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
파일 보기 프로젝트 열기: OpenNos/OpenNos

공개 메소드들

메소드 설명
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[]