Dreamine.Communication.Core 1.0.2
Dreamine.Communication.Core 통신 기능과 관련 API를 제공합니다.
로딩중...
검색중...
일치하는것 없음
Dreamine.Communication.Core.Framing.LengthPrefixedMessageFrameCodec 클래스 참조sealed

더 자세히 ...

Dreamine.Communication.Core.Framing.LengthPrefixedMessageFrameCodec에 대한 상속 다이어그램 :
Dreamine.Communication.Core.Framing.LengthPrefixedMessageFrameCodec에 대한 협력 다이어그램:

Public 멤버 함수

 LengthPrefixedMessageFrameCodec ()
 LengthPrefixedMessageFrameCodec (int maxFrameLength)
async Task WriteFrameAsync (Stream stream, byte[] payload, CancellationToken cancellationToken=default)
async Task< byte[]?> ReadFrameAsync (Stream stream, CancellationToken cancellationToken=default)

정적 Private 멤버 함수

static async Task< byte[]?> ReadExactAsync (Stream stream, int length, CancellationToken cancellationToken)

Private 속성

readonly int _maxFrameLength

정적 Private 속성

const int HeaderSize = 4

상세한 설명

4바이트 빅 엔디언 길이 접두사로 메시지 프레임을 구분합니다.

LengthPrefixedMessageFrameCodec.cs 파일의 13 번째 라인에서 정의되었습니다.

생성자 & 소멸자 문서화

◆ LengthPrefixedMessageFrameCodec() [1/2]

Dreamine.Communication.Core.Framing.LengthPrefixedMessageFrameCodec.LengthPrefixedMessageFrameCodec ( )
inline

최대 프레임 길이 1MiB로 코덱을 초기화합니다.

LengthPrefixedMessageFrameCodec.cs 파일의 43 번째 라인에서 정의되었습니다.

44 : this(1024 * 1024)
45 {
46 }

◆ LengthPrefixedMessageFrameCodec() [2/2]

Dreamine.Communication.Core.Framing.LengthPrefixedMessageFrameCodec.LengthPrefixedMessageFrameCodec ( int maxFrameLength)
inline

지정한 최대 프레임 길이로 코덱을 초기화합니다.

매개변수
maxFrameLength허용할 최대 페이로드 바이트 수입니다.
예외
ArgumentOutOfRangeException값이 0 이하인 경우 발생합니다.

LengthPrefixedMessageFrameCodec.cs 파일의 72 번째 라인에서 정의되었습니다.

73 {
74 if (maxFrameLength <= 0)
75 {
76 throw new ArgumentOutOfRangeException(nameof(maxFrameLength));
77 }
78
79 _maxFrameLength = maxFrameLength;
80 }

다음을 참조함 : _maxFrameLength.

멤버 함수 문서화

◆ ReadExactAsync()

async Task< byte[]?> Dreamine.Communication.Core.Framing.LengthPrefixedMessageFrameCodec.ReadExactAsync ( Stream stream,
int length,
CancellationToken cancellationToken )
inlinestaticprivate

요청한 바이트 수를 모두 읽거나 스트림 종료를 만날 때까지 반복해서 읽습니다.

매개변수
stream데이터를 읽을 스트림입니다.
length정확히 읽을 바이트 수입니다.
cancellationToken읽기 취소 요청을 감시하는 토큰입니다.
반환값
완성된 버퍼이며, 첫 바이트 전에 스트림이 끝나면 null입니다.
예외
EndOfStreamException일부 바이트를 읽은 뒤 스트림이 끝난 경우 발생합니다.
OperationCanceledException작업 취소가 요청된 경우 발생할 수 있습니다.

LengthPrefixedMessageFrameCodec.cs 파일의 319 번째 라인에서 정의되었습니다.

323 {
324 var buffer = new byte[length];
325 var offset = 0;
326
327 while (offset < length)
328 {
329 var read = await stream.ReadAsync(
330 buffer.AsMemory(offset, length - offset),
331 cancellationToken)
332 .ConfigureAwait(false);
333
334 if (read == 0)
335 {
336 return null;
337 }
338
339 offset += read;
340 }
341
342 return buffer;
343 }

다음에 의해서 참조됨 : ReadFrameAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ ReadFrameAsync()

async Task< byte[]?> Dreamine.Communication.Core.Framing.LengthPrefixedMessageFrameCodec.ReadFrameAsync ( Stream stream,
CancellationToken cancellationToken = default )
inline

길이 접두사와 해당 크기의 페이로드를 비동기 읽습니다.

매개변수
stream읽을 스트림입니다.
cancellationToken읽기 취소 요청을 감시하는 토큰입니다.
반환값
읽은 페이로드이며, 헤더 전에 스트림이 끝나면 null입니다.
예외
ArgumentNullExceptionstreamnull인 경우 발생합니다.
InvalidDataException길이가 허용 범위를 벗어나거나 프레임이 불완전한 경우 발생합니다.
OperationCanceledException작업 취소가 요청된 경우 발생할 수 있습니다.

Dreamine.Communication.Core.Framing.IMessageFrameCodec를 구현.

LengthPrefixedMessageFrameCodec.cs 파일의 232 번째 라인에서 정의되었습니다.

235 {
236 ArgumentNullException.ThrowIfNull(stream);
237
238 var header = await ReadExactAsync(stream, HeaderSize, cancellationToken)
239 .ConfigureAwait(false);
240
241 if (header is null)
242 {
243 return null;
244 }
245
246 var length = BinaryPrimitives.ReadInt32BigEndian(header);
247
248 if (length < 0 || length > _maxFrameLength)
249 {
250 throw new InvalidDataException(
251 $"Invalid frame length. Length={length}, MaxFrameLength={_maxFrameLength}");
252 }
253
254 if (length == 0)
255 {
256 return Array.Empty<byte>();
257 }
258
259 return await ReadExactAsync(stream, length, cancellationToken)
260 .ConfigureAwait(false);
261 }

다음을 참조함 : _maxFrameLength, HeaderSize, ReadExactAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ WriteFrameAsync()

async Task Dreamine.Communication.Core.Framing.LengthPrefixedMessageFrameCodec.WriteFrameAsync ( Stream stream,
byte[] payload,
CancellationToken cancellationToken = default )
inline

4바이트 길이 접두사와 페이로드를 스트림에 비동기 기록합니다.

매개변수
stream기록할 스트림입니다.
payload프레임에 기록할 메시지 데이터입니다.
cancellationToken쓰기 취소 요청을 감시하는 토큰입니다.
반환값
비동기 프레임 쓰기 작업입니다.
예외
ArgumentNullException스트림 또는 페이로드가 null인 경우 발생합니다.
ArgumentOutOfRangeException페이로드가 최대 길이를 초과한 경우 발생합니다.
InvalidDataException페이로드 길이가 구성된 최대 프레임 길이를 초과한 경우 발생합니다.
OperationCanceledException작업 취소가 요청된 경우 발생할 수 있습니다.

Dreamine.Communication.Core.Framing.IMessageFrameCodec를 구현.

LengthPrefixedMessageFrameCodec.cs 파일의 154 번째 라인에서 정의되었습니다.

158 {
159 ArgumentNullException.ThrowIfNull(stream);
160 ArgumentNullException.ThrowIfNull(payload);
161
162 if (payload.Length > _maxFrameLength)
163 {
164 throw new InvalidDataException(
165 $"Frame length exceeded. Length={payload.Length}, MaxFrameLength={_maxFrameLength}");
166 }
167
168 var header = new byte[HeaderSize];
169 BinaryPrimitives.WriteInt32BigEndian(header, payload.Length);
170
171 await stream.WriteAsync(header, cancellationToken).ConfigureAwait(false);
172 await stream.WriteAsync(payload, cancellationToken).ConfigureAwait(false);
173 await stream.FlushAsync(cancellationToken).ConfigureAwait(false);
174 }

다음을 참조함 : _maxFrameLength, HeaderSize.

멤버 데이터 문서화

◆ _maxFrameLength

readonly int Dreamine.Communication.Core.Framing.LengthPrefixedMessageFrameCodec._maxFrameLength
private

max Frame Length 값을 보관합니다.

LengthPrefixedMessageFrameCodec.cs 파일의 33 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : LengthPrefixedMessageFrameCodec(), ReadFrameAsync(), WriteFrameAsync().

◆ HeaderSize

const int Dreamine.Communication.Core.Framing.LengthPrefixedMessageFrameCodec.HeaderSize = 4
staticprivate

Header Size 값을 보관합니다.

LengthPrefixedMessageFrameCodec.cs 파일의 23 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ReadFrameAsync(), WriteFrameAsync().


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: