// Copyright (C) 2015-2026 The Neo Project.
//
// ISerializableSpan.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using System;

namespace Neo.IO
{
    /// <summary>
    /// Represents NEO objects that can be serialized.
    /// </summary>
    public interface ISerializableSpan
    {
        /// <summary>
        /// The size of the object in bytes after serialization.
        /// </summary>
        int Size { get; }

        /// <summary>
        /// Gets a ReadOnlySpan that represents the current value
        /// Requires keeping the data returned by GetSpan consistent with the data generated by <see cref="ISerializable"/>.
        /// </summary>
        ReadOnlySpan<byte> GetSpan();

        /// <summary>
        /// Serializes the object using the specified Span.
        /// </summary>
        /// <param name="destination">The Span for writing data.</param>
        void Serialize(Span<byte> destination)
        {
            var buffer = GetSpan();
            buffer.CopyTo(destination);
        }
    }
}
