根据IDL文件生成RUST文件
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

214 行
6.1KB

  1. // 综合测试IDL文件
  2. // 包含各种复杂情况:常量、枚举、结构体、接口、嵌套模块、参数方向、序列等
  3. module ComprehensiveTest {
  4. // 联合类型(移到前面)
  5. union MessagePayload switch(long) {
  6. case 0: string textMessage;
  7. case 1: ByteBuffer binaryMessage;
  8. case 2: long numericMessage;
  9. default: octet rawData;
  10. };
  11. // 使用联合类型的结构体(移到前面)
  12. struct Message {
  13. LimitedString sender;
  14. LimitedString recipient;
  15. long timestamp;
  16. MessagePayload payload;
  17. };
  18. // 基本类型定义
  19. typedef sequence<octet> ByteBuffer;
  20. typedef sequence<string> StringList;
  21. typedef sequence<long> IntegerArray;
  22. typedef string<128> LimitedString;
  23. // 基本常量定义
  24. const long MAX_ITEMS = 1000;
  25. const double PI_VALUE = 3.14159265359;
  26. const string VERSION_INFO = "2.0.0";
  27. const boolean FEATURE_ENABLED = TRUE;
  28. const octet MAGIC_BYTE = 0xFF;
  29. // 基本枚举
  30. enum StatusCode {
  31. OK,
  32. WARNING,
  33. ERROR,
  34. CRITICAL,
  35. UNKNOWN
  36. };
  37. // 事件监听接口(移到前面)
  38. interface EventListener {
  39. void onStatusChanged(in StatusCode newStatus);
  40. void onDataReceived(in ByteBuffer data);
  41. void onError(in string errorMessage, in long errorCode);
  42. };
  43. // 基本结构体
  44. struct Point2D {
  45. double x;
  46. double y;
  47. };
  48. struct Point3D {
  49. double x;
  50. double y;
  51. double z;
  52. };
  53. // 带有序列的结构体
  54. struct DataPacket {
  55. LimitedString name;
  56. ByteBuffer data;
  57. StatusCode status;
  58. long timestamp;
  59. };
  60. // 嵌套结构体
  61. struct ComplexData {
  62. Point3D position;
  63. Point3D velocity;
  64. ByteBuffer payload;
  65. StringList tags;
  66. };
  67. // 基本接口
  68. interface BasicOperations {
  69. // 基本方法,不同参数方向
  70. void noParams();
  71. long simpleMethod(in long value);
  72. boolean complexMethod(in string name, in long id, out string result);
  73. double calculateValue(in double x, in double y, inout double z);
  74. // 使用自定义类型
  75. StatusCode getStatus();
  76. void setPosition(in Point3D position);
  77. Point3D getPosition();
  78. // 使用序列
  79. ByteBuffer getData();
  80. void setData(in ByteBuffer data);
  81. long processData(in ByteBuffer input, out ByteBuffer output);
  82. };
  83. // 使用联合类型的接口(移到这里)
  84. interface MessageHandler {
  85. void sendMessage(in Message msg);
  86. Message receiveMessage(in long timeout);
  87. long getMessageCount();
  88. };
  89. // 嵌套模块 - 数学操作
  90. module Math {
  91. // 数学常量
  92. const double E_VALUE = 2.71828;
  93. const double GOLDEN_RATIO = 1.61803;
  94. // 向量结构体
  95. struct Vector {
  96. sequence<double> elements;
  97. };
  98. // 矩阵结构体
  99. struct Matrix {
  100. long rows;
  101. long cols;
  102. sequence<sequence<double>> elements;
  103. };
  104. // 数学操作接口
  105. interface VectorOperations {
  106. double dotProduct(in Vector a, in Vector b);
  107. Vector crossProduct(in Vector a, in Vector b);
  108. double magnitude(in Vector v);
  109. Vector normalize(in Vector v);
  110. };
  111. interface MatrixOperations {
  112. Matrix multiply(in Matrix a, in Matrix b);
  113. Matrix transpose(in Matrix m);
  114. Matrix inverse(in Matrix m);
  115. double determinant(in Matrix m);
  116. };
  117. // 更深层次的嵌套模块
  118. module Statistics {
  119. struct Dataset {
  120. sequence<double> values;
  121. };
  122. interface StatOperations {
  123. double mean(in Dataset data);
  124. double median(in Dataset data);
  125. double variance(in Dataset data);
  126. double standardDeviation(in Dataset data);
  127. };
  128. };
  129. };
  130. // 嵌套模块 - 网络操作
  131. module Network {
  132. // 网络相关结构体
  133. struct Address {
  134. string host;
  135. unsigned short port;
  136. };
  137. struct Packet {
  138. octet packet_type;
  139. unsigned long size;
  140. ByteBuffer payload;
  141. };
  142. // 网络接口
  143. interface Connection {
  144. boolean connect(in Address addr);
  145. void disconnect();
  146. StatusCode getConnectionStatus();
  147. };
  148. interface DataTransfer {
  149. long send(in Packet packet);
  150. Packet receive(in long timeout);
  151. long available();
  152. };
  153. // 单继承接口
  154. interface SecureConnection : Connection {
  155. boolean authenticate(in string username, in string password);
  156. boolean isSecure();
  157. };
  158. // 带有继承的接口
  159. interface AdvancedDataTransfer : DataTransfer {
  160. long sendBatch(in sequence<Packet> packets);
  161. sequence<Packet> receiveBatch(in long count, in long timeout);
  162. };
  163. };
  164. // 复杂接口,使用各种自定义类型
  165. interface DataProcessor {
  166. // 处理不同类型的数据
  167. StatusCode processTextData(in string data, out string result);
  168. StatusCode processBinaryData(in ByteBuffer data, out ByteBuffer result);
  169. StatusCode processStructuredData(in ComplexData data, out ComplexData result);
  170. // 批量处理
  171. long batchProcess(in sequence<ComplexData> inputs, out sequence<ComplexData> results);
  172. // 统计信息
  173. void getProcessingStats(out long processedCount, out long errorCount, out double averageTime);
  174. };
  175. // 带有回调的接口
  176. interface AsyncProcessor {
  177. long startProcessing(in ComplexData data);
  178. void cancelProcessing(in long processId);
  179. boolean registerCallback(in EventListener listener);
  180. boolean unregisterCallback(in EventListener listener);
  181. };
  182. };