kiritobuf

0.0.3 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i kiritobuf

Weekly Downloads

5

Version

0.0.3

License

MIT

Unpacked Size

12.2 kB

Total Files

4

Last publish

Collaborators

  • zhoumq