<commit_before>/*
 * waysome - wayland based window manager
 *
 * Copyright in alphabetical order:
 *
 * Copyright (C) 2014-2015 <NAME>
 * Copyright (C) 2014-2015 <NAME>
 * Copyright (C) 2014-2015 <NAME>
 * Copyright (C) 2014-2015 <NAME>
 * Copyright (C) 2014-2015 <NAME>
 *
 * This file is part of waysome.
 *
 * waysome 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.
 *
 * waysome 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.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with waysome. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file json/serializer.c
 *
 * This file contains the serializer backend for JSON.
 *
 * The implementation makes use of the yajl library. For a documentation of the
 * yajl library, see: https://lloyd.github.io/yajl/
 */

#include <errno.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <yajl/yajl_common.h>
#include <yajl/yajl_gen.h>

#include "objects/message/error_reply.h"
#include "objects/message/event.h"
#include "objects/message/message.h"
#include "objects/message/value_reply.h"
#include "objects/string.h"
#include "serialize/json/keys.h"
#include "serialize/json/serializer.h"
#include "serialize/json/serializer_state.h"
#include "serialize/serializer.h"
#include "util/arithmetical.h"
#include "values/object_id.h"
#include "values/value.h"

/*
 *
 * Forward declarations
 *
 */

/**
 * serialize() callback
 *
 * @return negative errno.h number on failure, else the number of written bytes
 */
static ssize_t
serialize(
    struct ws_serializer* self,
    char* buf,
    size_t nbuf
);

/**
 * Serialize an error reply type
 *
 * @return zero on success, else negative errno.h number
 */<commit_msg>Add logging context for serializer<commit_after>/*
 * waysome - wayland based window manager
 *
 * Copyright in alphabetical order:
 *
 * Copyright (C) 2014-2015 <NAME>
 * Copyright (C) 2014-2015 <NAME>
 * Copyright (C) 2014-2015 <NAME>
 * Copyright (C) 2014-2015 <NAME>
 * Copyright (C) 2014-2015 <NAME>
 *
 * This file is part of waysome.
 *
 * waysome 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.
 *
 * waysome 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.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with waysome. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file json/serializer.c
 *
 * This file contains the serializer backend for JSON.
 *
 * The implementation makes use of the yajl library. For a documentation of the
 * yajl library, see: https://lloyd.github.io/yajl/
 */

#include <errno.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <yajl/yajl_common.h>
#include <yajl/yajl_gen.h>

#include "logger/module.h"
#include "objects/message/error_reply.h"
#include "objects/message/event.h"
#include "objects/message/message.h"
#include "objects/message/value_reply.h"
#include "objects/string.h"
#include "serialize/json/keys.h"
#include "serialize/json/serializer.h"
#include "serialize/json/serializer_state.h"
#include "serialize/serializer.h"
#include "util/arithmetical.h"
#include "values/object_id.h"
#include "values/value.h"

static struct ws_logger_context log_ctx = {
    .prefix = "[Serializer/JSON] ",
};

/*
 *
 * Forward declarations
 *
 */

/**
 * serialize() callback
 *
 * @return negative errno.h number on failure, else the number of written bytes
 */
static ssize_t
serialize(
    struct ws_serializer* self,
    char* buf,
    size_t nbuf
);

/**
 * Serialize an error reply type
 *
 * @return zero on success, else negative errno.h number
 */
{'fraction_non_alphanumeric': 0.11426624261699228, 'fraction_numerical': 0.019082235347569285, 'mean_word_length': 3.941638608305275, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6864935', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1364, 'n_words': 490}