/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 */

#ifndef SH4LT_METADATA_H_
#define SH4LT_METADATA_H_

#include <cstdint>
#include <cstring>

namespace sh4lt {

struct Metadata {
  // Metadata is the structure used as header for inline sh4lt metadata.
  bool is_dirty{false};
  size_t size{0};

  /**
   * Check if metadata has been updated. This method must be called from Reader::onData
   * callback. See check-metadata.cpp file for and example.
   *
   * \param data the sh4lt data pointer provided by the Reader::onData callback
   * \param size the sh4lt data size provided by the Reader::onData callback
   * \param info the sh4lt info provided by the Reader::onData callback
   *
   * \return true if metadata has been updated by the writer, false otherwise
   **/
  static bool has_update(void* data, size_t size);

  /**
   * Get the size of the metadata. This method must be called from Reader::onData
   * callback. See check-metadata.cpp file for and example.
   *
   * \param data the sh4lt data pointer provided by the Reader::onData callback
   * \param size the sh4lt data size provided by the Reader::onData callback
   *
   * \return the size of the metadata
   **/
  static size_t get_size(void* data, size_t size);

  /**
   * Get the pointer to the metadata. This method must be called from Reader::onData
   * callback. See check-metadata.cpp file for and example.
   *
   * \param data the sh4lt data pointer provided by the Reader::onData callback
   * \param size the sh4lt data size provided by the Reader::onData callback
   *
   * \return the pointer to the metadata. nullptr if no metadata is available.
   **/
  static void* get_mem(void* data, size_t size);
};

}  // namespace sh4lt
#endif
