Code Monkey home page Code Monkey logo

nanoc's Introduction

nanoc

nanoc is a compiler for NanoPack that compiles NanoPack schemas to code that enables portable data serialization/deserialization in NanoPack.

Requirements

  • Go >= 1.20
  • Formatter installed for the corresponding language:
    • C++: clang-format
    • Swift: swift-format
    • JavaScript/TypeScript: prettier will be used via npx, so npm needs to be available

Installation

nanoc is available as pre-built binaries on the GitHub Releases page.

Compiling the Compiler

# Assuming the cwd is in the project directory where go.mod is
go install nanoc/cmd/nanoc

The above compiles the source code, produces an executable called nanoc, and then moves (installs) it to GOBIN, or GOPATH/bin if GOBIN is not set. Make sure either is in PATH.

Usage

nanoc has the following arguments:

  • --language specifies the language of the generated code. Can be c++, swift, or ts.
  • --factory-out (optional) specifies the folder in which the message factory code file should be put.
  • The list of relative paths to the NanoPack schemas that should be compiled.

Example

Compiling person.yml and car.yml in the current directory to C++:

nanoc --language=c++ ./person.yml ./car.yml

Compiling person.yml and car.yml in the current directory to TypeScript, and generate the message factory in the current directory:

nanoc --language=ts --factory-out=. ./person.yml ./car.yml

nanoc's People

Contributors

kennethnym avatar

Watchers

 avatar

nanoc's Issues

Remove the need to specify field numbers in schema files

Currently, a field number must be explicitly assigned for every field in a message. The field numbers only indicate the order of the fields in the serialized bytes. For example, field number 0 appears first in the buffer, then field number 1, so on and so forth. Field numbers are needed because the YAML parser doesn't guarantee that the fields are traversed in the order they appear in the schema file, and the numbers are therefore used to give the compiler a consistent order across invocations.

In a7609e1, the YAML parser was downgraded to introduce the MapSlice struct that preserves the order of the fields as they appear in the schema file. This eliminates the need for explicit field numbers, which reduces noise in the schema file.

Auto infer type ID

Currently, a type ID must be explicitly specified for every NanoPack message in its schema. As the project grows, this will be completely unmaintainable. To mitigate this, the compiler should be able to:

  • automatically assign a new type ID for every new message defined; and
  • persist the assigned type IDs so that they are consistent for every compiler invocation.

To do so, the compiler should follow the following algorithm:

check whether the generated code for a schema exists
if it exists:
    read code header and check if a type ID is assigned
    if not exist:
        generate a new type ID
        write the type ID to the code header
else:
    generate a new type ID
    write the type ID to the code header

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.