Giter VIP home page Giter VIP logo

binxml's Introduction

binxml - a binary XML protocol implemented in C

Binary XML serialization protocol that uses binary structure tables to encode/decode data, allowing faster processing and smaller files sizes. Supports random-access querying and modification of data.
Has a two-phase workflow, with protobuf-like compilation phase, where C files are being generated based on the XML schema.

Advantages

XML is a standardized, highly popular, widespread tool for stroring and transporting data.
Dealing with huge files it can be too verbose because of its character encoding mechanism, and processing can be done linearly.

binxml allows random access querying and modification plus smaller network footprint.

Disadvantages

The XML schema has to be available for both parties upfront.
Comes with the usual problems of binary protocols, namely that if something does not function according to expectations, debugging not human readable formats are time consuming and hard.

Disclaimer

binxml is not producion ready! The project is a work in progress and the initial scope has many limitations e.g. what parts of an XML schema is supported.
At this point if the XSD has complexTypes or/and elements with nested anonymous complexTypes in it, it is going to work. Other components like simpleType, simpleContext, complexContext are not supported yet.
From an attribute point of view, attributes other than name and type are ignored.

binxml is not an EXI (Efficient Extensible Interchange) or BiM (Binary XML) implementation at the moment.

How does it work?

// TBD

Build and run

Being cross-platform is not a priority at this point.

On a Unix-based system, build the project with clang with the ./build.sh script.
Pre-generate C files with the generate commmand. See Usage.

Scopes

[X] Optional schema validation
[X] Translate XSD (with limitations) to C types
[X] Generate C files with type definitions
[ ] Add encoding functions to C files.
[ ] Add decoding functions to C files.
[ ] Add marshalling functions to C files.
[ ] Add unmarshalling functions to C files.

Dependencies

The project relies heavily on libxml2 for XML and schema parsing/validation.

Usage

binxml generate <xsd_path> <output_dir> for generating C files.
Use these to write your logic and their encoding/decoding functions to handle .bin files, or their marshalling/unmarshalling functions for XML.

XML files can be validated upon receiving or before sending.
The marshalling functions do not make validation checks.

TBD not up-to-date

Use binxml help for info on how to use the program. There are 4 commands at the moment, from valdidate and generate works, pack is WIP and unpack is TBD.

Commands:
         validate        args: <xml_path> <xsd_path>
         generate        args: <xsd_path> <output_dir>
         pack            args: <xml_path> <output_dir>
         unpack          args: <bin_path> <xsd_path> <output_dir>

Example output:

XML is valid against the schema!
C header file has been generated with the schema types at ./target/generated/Library_types.h

The content then of the header file is:

typedef struct LibraryType LibraryType;
typedef struct PublishingCompanyType PublishingCompanyType;
typedef struct Books Books;
typedef struct BookType BookType;

struct LibraryType {
	size_t PublishingCompanyType_count;
	PublishingCompanyType* PublishingCompany;
};

struct PublishingCompanyType {
	char* CompanyName;
	size_t Books_count;
	Books* Books;
};

struct Books {
	size_t BookType_count;
	BookType* Book;
};

struct BookType {
	char* Empty;
	char* Title;
	char* Author;
	int PublicationYear;
	char* Genre;
};

If I make a deliberate mistake in the XML - e.g. add not supported simpleType;
Then I get an error for the validity of the XML with the error description.

./data/Library.xsd:21: element element: Schemas parser error : element decl. 'Genre', attribute 'type': The QName value 'GenreType' does not resolve to a(n) type definition.
Failed to parse XSD schema.
XML is not valid against the schema.

binxml's People

Contributors

takacs-bence avatar

Watchers

 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.