Giter Site home page Giter Site logo

exificient-for-json.c's Introduction

exificient-for-json.c

EXI for JSON in C programming language.

Note: source files in "src/exiforjson" and "src/json" are meant to show a mapping between textual JSON and EXIforJSON (and vice-versa). Constrained implementations are encouraged to use code in "src/codec" only by using the streaming API in a datatyped manner.

Build Status

Demo program

Sample program to illustrate how to write EXIforJSON and read JSON again

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "EXIforJSONEncoder.h"
#include "EXIforJSONDecoder.h"

#define BUFFER_SIZE 8192


int main(int argc, char *argv[]) {
	int errn = 0;

	char *JSON_STRING_IN = "{\"keyNumber\":   123, \"keyArrayStrings\": [ \"s1\", \"s2\" ] }";
	const size_t lenOut = strlen(JSON_STRING_IN) + 100; /* some extra space for decoding differences e.g, number 1 -> 1E0 etc */
	char JSON_STRING_OUT[lenOut];

	uint8_t buffer[BUFFER_SIZE];
	size_t posEncode = 0;
	size_t posDecode = 0;

	printf("FROM: \n%s \n", JSON_STRING_IN);

	errn = encodeEXIforJSON(JSON_STRING_IN, strlen(JSON_STRING_IN), buffer, BUFFER_SIZE, &posEncode);
	if( errn == 0 ) {
		/* OK so far */
		printf("Encoding JSON (len=%d) to EXIforJSON (len=%d) was successful \n", strlen(JSON_STRING_IN), posEncode);

		/* Try to transform it back to JSON again */
		errn = decodeEXIforJSON(buffer, BUFFER_SIZE, &posDecode, JSON_STRING_OUT, lenOut);

		if( errn == 0 ) {
			/* OK */
			printf("Decoding EXIforJSON (len=%d) to JSON (len=%d) was successful \n", posEncode, strlen(JSON_STRING_OUT));
			printf("TO: \n%s \n", JSON_STRING_OUT);
		} else {
			/* ERROR */
			printf("Decoding EXIforJSON to JSON failed due to error %d \n", errn);
		}
	} else {
		/* ERROR */
		printf("Encoding JSON to EXIforJSON failed due to error %d \n", errn);
	}

	return errn;
}

exificient-for-json.c's People

Contributors

danielpeintner avatar heyjulian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.