1234567891011121314151617181920212223242526272829303132 |
- using System.Text;
- using PCC.App.BinaryFormatter;
- namespace PCC.App.TransferModels;
- public static class BlockWithNonce1
- {
- public static ReadOnlyMemory<byte> Mux(ReadOnlyMemory<byte> payload, ReadOnlyMemory<byte> nonce)
- {
- // 计算总长度
- var totalLength = payload.Length + nonce.Length;
- var buffer = new byte[totalLength];
- // 将 payload 和 nonce 拷贝到 buffer 中
- payload.Span.CopyTo(buffer);
- nonce.Span.CopyTo(buffer.AsSpan(payload.Length));
- return buffer;
- }
- public static (ReadOnlyMemory<byte> payload, ReadOnlyMemory<byte> nonce) Demux(ReadOnlyMemory<byte> transferBlock, int nonceBytes)
- {
- // 计算 payload 的长度
- var payloadLength = transferBlock.Length - nonceBytes;
- // 获取 payload 和 nonce
- var payload = transferBlock.Slice(0, payloadLength);
- var nonce = transferBlock.Slice(payloadLength, nonceBytes);
- return (payload, nonce);
- }
- }
|