46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using EonaCat.WebSockets.Buffer;
|
|
|
|
namespace EonaCat.WebSockets;
|
|
// This file is part of the EonaCat project(s) which is released under the Apache License.
|
|
// See the LICENSE file or go to https://EonaCat.com/License for full license details.
|
|
|
|
public sealed class BinaryFrame : DataFrame
|
|
{
|
|
public BinaryFrame(ArraySegment<byte> segment, bool isMasked = true)
|
|
{
|
|
BufferValidator.ValidateArraySegment(segment, "segment");
|
|
|
|
Data = segment.Array;
|
|
Offset = segment.Offset;
|
|
Count = segment.Count;
|
|
IsMasked = isMasked;
|
|
}
|
|
|
|
public BinaryFrame(byte[] data, int offset, int count, bool isMasked = true)
|
|
{
|
|
BufferValidator.ValidateBuffer(data, offset, count, "data");
|
|
|
|
Data = data;
|
|
Offset = offset;
|
|
Count = count;
|
|
IsMasked = isMasked;
|
|
}
|
|
|
|
public byte[] Data { get; private set; }
|
|
public int Offset { get; private set; }
|
|
public int Count { get; private set; }
|
|
public bool IsMasked { get; private set; }
|
|
|
|
public override OpCode OpCode => OpCode.Binary;
|
|
|
|
public byte[] ToArray(IFrameBuilder builder)
|
|
{
|
|
if (builder == null)
|
|
{
|
|
throw new ArgumentNullException("builder");
|
|
}
|
|
|
|
return builder.EncodeFrame(this);
|
|
}
|
|
} |