Stores internal metadata used for parsing & serialization.
| 174 | |
| 175 | @dataclasses.dataclass(frozen=True) |
| 176 | class FieldMetadata: |
| 177 | """Stores internal metadata used for parsing & serialization.""" |
| 178 | |
| 179 | # Protobuf field number |
| 180 | number: int |
| 181 | # Protobuf type name |
| 182 | proto_type: str |
| 183 | # Map information if the proto_type is a map |
| 184 | map_types: Optional[Tuple[str, str]] = None |
| 185 | # Groups several "one-of" fields together |
| 186 | group: Optional[str] = None |
| 187 | # Describes the wrapped type (e.g. when using google.protobuf.BoolValue) |
| 188 | wraps: Optional[str] = None |
| 189 | # Is the field optional |
| 190 | optional: Optional[bool] = False |
| 191 | |
| 192 | @staticmethod |
| 193 | def get(field: dataclasses.Field) -> "FieldMetadata": |
| 194 | """Returns the field metadata for a dataclass field.""" |
| 195 | return field.metadata["betterproto"] |
| 196 | |
| 197 | |
| 198 | def dataclass_field( |