<commit_before>// Copyright (c) 2014 Quanta Research Cambridge, Inc.

// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <string.h>
#include "portal.h"

static int trace_json;// = 1;
void connectalJsonEncode(char *datap, void *binarydata, ConnectalMethodJsonInfo *info)
{
    ConnectalParamJsonInfo *iparam = info->param;
    char *data = (char *)datap;
    data += sprintf(data, "{\"name\":\"%s\"", info->name);
    while(iparam->name) {
        uint8_t  tmp8;
        uint16_t tmp16;
        uint32_t tmp32;
        uint64_t tmp64;
	int8_t  stmp8;
	int16_t stmp16;
	int32_t stmp32;
	int64_t stmp64;
        int      tmpint;
        data += sprintf(data, ",\"%s\":", iparam->name);
        switch(iparam->itype) {
	case ITYPE_int8_t:
            stmp8 = *(int8_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", stmp8);
            break;
	case ITYPE_int16_t:
            stmp16 = *(int16_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", stmp16);
            break;
	case ITYPE_int32_t:
            stmp32 = *(int32_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", stmp32);
            break;
	case ITYPE_int64_t:
            stmp64 = *(int64_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%ld", stmp64);
            break;
        case ITYPE_uint8_t:
            tmp8 = *(uint8_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", tmp8);
            break;
        case ITYPE_uint16_t:
            tmp16 = *(uint16_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", tmp16);
            break;
        case ITYPE_uint32_t:
            tmp32 = *(uint32_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", tmp32);
            break;
        case ITYPE_uint64_t:
            tmp64 = *(uint64_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%ld", (unsigned long)tmp64);
            break;
        case ITYPE_SpecialTypeForSendingFd:
            tmpint = *(int *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", tmpint);
            break;
        default:
            fprintf(stderr, "%x type %d\n", *(uint32_t *)((unsigned long)binarydata + iparam->offset), iparam->itype);
        }
        iparam++;
    }
    data += sprintf(data, "}");
    if (trace_json)
        fprintf(stderr, "[%s] num %d message '%s'\n", __FUNCTION__, iparam->offset, (char *)datap);
    int slength = strlen(datap);
    int rounded_size = (slength + sizeof(uint32_t) - 1) / sizeof(uint32_t);
    while (slength++ < (int)(rounded_size*sizeof(uint32_t)))
        *data++ = ' ';
    *data++ = 0;
}

void connectalJsonEncodeAndSend(PortalInternal *pint, void *binarydata, ConnectalMethodJsonInfo *info)
{
    ConnectalParamJsonInfo *iparam = info->param;
    char *jsonp = (char *)pint->item->mapchannelInd(pint, 0);
    connectalJsonEncode(jsonp, binarydata, info); 
    int rounded_size = strlen(jsonp);
    pint->item->send(pint, (volatile unsigned int*)jsonp, (iparam->offset << 16) | (1 + rounded_size), -1);
}<commit_msg>update portalJson.c so it compiles for 32-bit CPUs again<commit_after>// Copyright (c) 2014 Quanta Research Cambridge, Inc.

// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <string.h>
#include "portal.h"

static int trace_json;// = 1;
void connectalJsonEncode(char *datap, void *binarydata, ConnectalMethodJsonInfo *info)
{
    ConnectalParamJsonInfo *iparam = info->param;
    char *data = (char *)datap;
    data += sprintf(data, "{\"name\":\"%s\"", info->name);
    while(iparam->name) {
        uint8_t  tmp8;
        uint16_t tmp16;
        uint32_t tmp32;
        uint64_t tmp64;
	int8_t  stmp8;
	int16_t stmp16;
	int32_t stmp32;
	int64_t stmp64;
        int      tmpint;
        data += sprintf(data, ",\"%s\":", iparam->name);
        switch(iparam->itype) {
	case ITYPE_int8_t:
            stmp8 = *(int8_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", stmp8);
            break;
	case ITYPE_int16_t:
            stmp16 = *(int16_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", stmp16);
            break;
	case ITYPE_int32_t:
            stmp32 = *(int32_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", stmp32);
            break;
	case ITYPE_int64_t:
            stmp64 = *(int64_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%lld", (long long)stmp64);
            break;
        case ITYPE_uint8_t:
            tmp8 = *(uint8_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", tmp8);
            break;
        case ITYPE_uint16_t:
            tmp16 = *(uint16_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", tmp16);
            break;
        case ITYPE_uint32_t:
            tmp32 = *(uint32_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", tmp32);
            break;
        case ITYPE_uint64_t:
            tmp64 = *(uint64_t *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%lld", (unsigned long long)tmp64);
            break;
        case ITYPE_SpecialTypeForSendingFd:
            tmpint = *(int *)((unsigned long)binarydata + iparam->offset);
            data += sprintf(data, "%d", tmpint);
            break;
        default:
            fprintf(stderr, "%x type %d\n", *(uint32_t *)((unsigned long)binarydata + iparam->offset), iparam->itype);
        }
        iparam++;
    }
    data += sprintf(data, "}");
    if (trace_json)
        fprintf(stderr, "[%s] num %d message '%s'\n", __FUNCTION__, iparam->offset, (char *)datap);
    int slength = strlen(datap);
    int rounded_size = (slength + sizeof(uint32_t) - 1) / sizeof(uint32_t);
    while (slength++ < (int)(rounded_size*sizeof(uint32_t)))
        *data++ = ' ';
    *data++ = 0;
}

void connectalJsonEncodeAndSend(PortalInternal *pint, void *binarydata, ConnectalMethodJsonInfo *info)
{
    ConnectalParamJsonInfo *iparam = info->param;
    char *jsonp = (char *)pint->item->mapchannelInd(pint, 0);
    connectalJsonEncode(jsonp, binarydata, info); 
    int rounded_size = strlen(jsonp);
    pint->item->send(pint, (volatile unsigned int*)jsonp, (iparam->offset << 16) | (1 + rounded_size), -1);
}
{'fraction_non_alphanumeric': 0.12974353023093885, 'fraction_numerical': 0.024370430544272948, 'mean_word_length': 2.8559284116331094, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5347832', 'n_tokens_mistral': 2749, 'n_tokens_neox': 2661, 'n_words': 808}