<'
# Copyright (c) 2013-2014, 2017-2018, 2026 LAAS/CNRS
# All rights reserved.
#
# Redistribution and use  in source  and binary  forms,  with or without
# modification, are permitted provided that the following conditions are
# met:
#
#   1. Redistributions of  source  code must retain the  above copyright
#      notice and this list of conditions.
#   2. Redistributions in binary form must reproduce the above copyright
#      notice and  this list of  conditions in the  documentation and/or
#      other materials provided with the distribution.
#
#                                      Anthony Mallet on Wed Mar 27 2013
#

if {[llength $argv] != 1} { error "expected arguments: component" }
lassign $argv component

# compute handy shortcuts
set comp [$component name]

lang c
'>
#include "autoconf/acheader.h"

#include <cstdlib>
#include <string>

#include "jsonops-c.h"

/* --- Generic exception encoding/decoding --------------------------------- */

void
genom_<"$comp">_encodex(std::string &json, genom_event ex, const void *exdetail)
{
  char *buf;
  int s;

  s = genom_json_printex(&buf, ex, exdetail);
  if (s) { json = "{\"ex\":\"::genom::fatal\"}"; return; }

  json = buf;
  free(buf);
  return;
}

genom_event
genom_<"$comp">_decodex(const char *json, genom_context self)
{
  genom_event e;
  void *detail;
  size_t size;

  e = genom_json_scanex(&json, &detail, &size);
  return self->raise(e, detail, size, self);
}
