什么是“注释"?在 Apache Thrift 中,它有什么用途? [英] What is an "annotation" in Apache Thrift, and what is it used for?

查看:31
本文介绍了什么是“注释"?在 Apache Thrift 中,它有什么用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Thrift 解析器有一个注释"的定义:

The Thrift parser has a definition for an "annotation":

https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob;f=compiler/cpp/thrifty.yy;h=da5c562f9d7adf87b21e4c3ae30fbb9657e0c8b3;hb=HEAD#l85

它们的用途是什么,它们包含的信息可以在生成的客户端和/或服务器代码中访问吗?

What are these meant to be used for, and can the information that they contain be accessed in the generated client and/or server code?

推荐答案

注解用于将元数据与 Thrift 定义 (".thrift") 文件中定义的类型相关联.源代码分发中的 AnnotationThrift.test 文件 有示例.

Annotations are used to associate metadata with types defined in the Thrift definition (".thrift") file. The AnnotationThrift.test file in the source distribution has examples.

例如,这是一个带有注释(在括号中)的 struct:

Here, for instance, is a struct with annotations (in parentheses):

struct foo {
  1: i32 bar ( presence = "required" );
  2: i32 baz ( presence = "manual", cpp.use_pointer = "", );
  3: i32 qux;
  4: i32 bop;
} (
  cpp.type = "DenseFoo",
  python.type = "DenseFoo",
  java.final = "",
  annotation.without.value,
)

看代码,注解似乎只用于向编译器提供指令——例如,C++ 编译器使用 cpp.type 注释(如果存在)在生成的代码中覆盖类型名称.

Looking at the code, it seems annotations are only ever used to provide directives to the compiler—for instance the C++ compiler uses the cpp.type annotation, if it's present, to override a type's name in the generated code.

我看不到任何迹象表明注释本身曾在生成的代码中复制或可访问,但如果此类代码确实存在,它将位于 compiler/cpp/src/generate/.

I see nothing that suggests the annotations themselves are ever reproduced in or accessible to the generated code, though if such code does exist it'd be located in compiler/cpp/src/generate/.

这篇关于什么是“注释"?在 Apache Thrift 中,它有什么用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆