Skip to content

rickyes/kiritobuf

Repository files navigation

kiritobuf

Interface Description Language | Kirito

Travis Node Version npm

Install

$ npm i kiritobuf --save

Get Started

  1. Define the kirito suffix file
# test

service testService {
  method ping (reqMsg, resMsg)
}

struct reqMsg {
  @1 age = Int16;
  @2 name = Text;
}

struct resMsg {
  @1 age = Int16;
  @2 name = Text;
}
  1. Generate AST
'use strict';

const path = require('path');
const kirito = require('kiritobuf');
const kiritoProto = './test.kirito';

const k = new kirito();

const AST = k.parse(path.join(__dirname, kiritoProto));

console.log(JSON.stringify(AST, null, 2));
  1. AST struct
{
  "type": "Program",
  "body": [
    {
      "type": "StructDeclaration",
      "name": "service",
      "value": "testService",
      "params": [
        {
          "type": "StructDeclaration",
          "name": "method",
          "value": "ping",
          "params": [
            {
              "type": "Identifier",
              "value": "reqMsg"
            },
            {
              "type": "Identifier",
              "value": "resMsg"
            }
          ]
        }
      ]
    },
    {
      "type": "StructDeclaration",
      "name": "struct",
      "value": "reqMsg",
      "params": [
        {
          "type": "VariableDeclaration",
          "name": "@",
          "value": "1",
          "params": [
            {
              "type": "Identifier",
              "value": "age"
            },
            {
              "type": "DataType",
              "value": "Int16"
            }
          ]
        },
        {
          "type": "VariableDeclaration",
          "name": "@",
          "value": "2",
          "params": [
            {
              "type": "Identifier",
              "value": "name"
            },
            {
              "type": "DataType",
              "value": "Text"
            }
          ]
        }
      ]
    },
    {
      "type": "StructDeclaration",
      "name": "struct",
      "value": "resMsg",
      "params": [
        {
          "type": "VariableDeclaration",
          "name": "@",
          "value": "1",
          "params": [
            {
              "type": "Identifier",
              "value": "age"
            },
            {
              "type": "DataType",
              "value": "Int16"
            }
          ]
        },
        {
          "type": "VariableDeclaration",
          "name": "@",
          "value": "2",
          "params": [
            {
              "type": "Identifier",
              "value": "name"
            },
            {
              "type": "DataType",
              "value": "Text"
            }
          ]
        }
      ]
    }
  ]
}

Author

Kiritobuf © Ricky 泽阳, Released under the MIT License.

Releases

No releases published

Packages

No packages published