/// <summary>
 /// Gets the frame. It consists of <see cref="FrameMetadata"/> header immediately followed by frame bytes.
 /// </summary>
 /// <returns>The memory containing frame data.</returns>
 internal Memory <byte> GetRawFrameWithMetadata()
 {
     if (_memoryOwner == null)
     {
         throw new InvalidOperationException("Buffer not assigned.");
     }
     return(FrameValue.GetFrameMetadataAndBytes(this._memoryOwner.Memory));
 }
 /// <summary>
 /// Copies the current object to the specified <see cref="FrameValue"/> object.
 /// <para/>
 /// The caller is responsible that the destination <see cref="FrameValue"/> is backed with
 /// a byte array (on stack or heap) of the sufficient size. The size of the destination needs to be at least <see cref="FrameValue.Length"/> bytes.
 /// </summary>
 /// <param name="dst">The destionation <see cref="FrameValue"/> object to be filled with bytes of the current object.</param>
 unsafe internal void CopyTo(ref FrameValue dst)
 {
     Buffer.MemoryCopy(Unsafe.AsPointer(ref this.Length), Unsafe.AsPointer(ref dst.Length), Length, Length);
 }
 /// <summary>
 /// Creates a new <see cref="FrameValue"/> for the given metadata and frame bytes.
 /// <para/>
 /// As <see cref="FrameValue"/> can only be created in the allocated byte buffer (on stack or heap)
 /// it is required to provide the uninitialized object as a parameter.
 /// The underlying byte array must be pinned or stack allocated.
 /// This object will then
 /// be intialized using the provided <paramref name="frameMetadata"/> and <paramref name="frameBytes"/>.
 /// </summary>
 /// <param name="frameValue">The allocated space for <see cref="FrameValue"/> structure.
 /// The underlying byte array must be pinned or stack allocated.</param>
 /// <param name="frameMetadata">The metadata.</param>
 /// <param name="frameBytes">The frame bytes.</param>
 /// <returns>Reference to newly initialzied <see cref="FrameValue"/> object.</returns>
 internal static void Create(ref FrameValue frameValue, ref FrameMetadata frameMetadata, Span <byte> frameBytes)
 {
     frameValue.Length = GetRequiredSize(frameBytes.Length);
     frameValue.Meta   = frameMetadata;
     frameBytes.CopyTo(new Span <byte>(Unsafe.AsPointer(ref frameValue.Bytes), frameBytes.Length));
 }