/*
 * Copyright(c) 2021 to 2022 ZettaScale Technology and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
 * v. 1.0 which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 */

#if defined(__IDLC__)

@nested @final
struct b {
  boolean b1;
  long long b2[2];
};

@topic @mutable
struct struct_test {
  b a1[2];
};

#else

#include <string.h>
#include "dds/dds.h"
#include "test_struct_alignment.h"
#include "common.h"

const dds_topic_descriptor_t *desc = &struct_test_desc;

void init_sample (void *s)
{
  struct_test *t = (struct_test *) s;
  t->a1[0].b1 = false;
  t->a1[0].b2[0] = 1;
  t->a1[0].b2[1] = 1;
  t->a1[1].b1 = true;
  t->a1[1].b2[0] = 3;
  t->a1[1].b2[1] = 4;
}

int cmp_sample (const void *sa, const void *sb)
{
  struct_test *a = (struct_test *) sa;
  struct_test *b = (struct_test *) sb;
  CMP(a, b, a1[0].b1, false);
  CMP(a, b, a1[0].b2[0], 1);
  CMP(a, b, a1[0].b2[1], 1);
  CMP(a, b, a1[1].b1, true);
  CMP(a, b, a1[1].b2[0], 3);
  CMP(a, b, a1[1].b2[1], 4);
  return 0;
}

NO_KEY_CMP

#endif
