项目作者: rickyes

项目描述 :
Interface description language | Kirito ⚔
高级语言: JavaScript
项目地址: git://github.com/rickyes/kiritobuf.git
创建时间: 2018-07-31T11:45:22Z
项目社区:https://github.com/rickyes/kiritobuf

开源协议:MIT License

下载


kiritobuf

Interface Description Language | Kirito

Travis
Node Version
npm

Install

  1. $ npm i kiritobuf --save

Get Started

  1. Define the kirito suffix file
    ```shell

    test

service testService {
method ping (reqMsg, resMsg)
}

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

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

  1. 2. Generate `AST`
  2. ``` js
  3. 'use strict';
  4. const path = require('path');
  5. const kirito = require('kiritobuf');
  6. const kiritoProto = './test.kirito';
  7. const k = new kirito();
  8. const AST = k.parse(path.join(__dirname, kiritoProto));
  9. console.log(JSON.stringify(AST, null, 2));
  1. AST struct
    1. {
    2. "type": "Program",
    3. "body": [
    4. {
    5. "type": "StructDeclaration",
    6. "name": "service",
    7. "value": "testService",
    8. "params": [
    9. {
    10. "type": "StructDeclaration",
    11. "name": "method",
    12. "value": "ping",
    13. "params": [
    14. {
    15. "type": "Identifier",
    16. "value": "reqMsg"
    17. },
    18. {
    19. "type": "Identifier",
    20. "value": "resMsg"
    21. }
    22. ]
    23. }
    24. ]
    25. },
    26. {
    27. "type": "StructDeclaration",
    28. "name": "struct",
    29. "value": "reqMsg",
    30. "params": [
    31. {
    32. "type": "VariableDeclaration",
    33. "name": "@",
    34. "value": "1",
    35. "params": [
    36. {
    37. "type": "Identifier",
    38. "value": "age"
    39. },
    40. {
    41. "type": "DataType",
    42. "value": "Int16"
    43. }
    44. ]
    45. },
    46. {
    47. "type": "VariableDeclaration",
    48. "name": "@",
    49. "value": "2",
    50. "params": [
    51. {
    52. "type": "Identifier",
    53. "value": "name"
    54. },
    55. {
    56. "type": "DataType",
    57. "value": "Text"
    58. }
    59. ]
    60. }
    61. ]
    62. },
    63. {
    64. "type": "StructDeclaration",
    65. "name": "struct",
    66. "value": "resMsg",
    67. "params": [
    68. {
    69. "type": "VariableDeclaration",
    70. "name": "@",
    71. "value": "1",
    72. "params": [
    73. {
    74. "type": "Identifier",
    75. "value": "age"
    76. },
    77. {
    78. "type": "DataType",
    79. "value": "Int16"
    80. }
    81. ]
    82. },
    83. {
    84. "type": "VariableDeclaration",
    85. "name": "@",
    86. "value": "2",
    87. "params": [
    88. {
    89. "type": "Identifier",
    90. "value": "name"
    91. },
    92. {
    93. "type": "DataType",
    94. "value": "Text"
    95. }
    96. ]
    97. }
    98. ]
    99. }
    100. ]
    101. }

Author

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