use crate::field_descriptor_proto::Type as ProtoType;
#[derive(Clone, Debug, PartialEq, Eq, Copy)]
#[non_exhaustive]
pub enum FieldType {
Double,
Float,
Int64,
Uint64,
Int32,
Fixed64,
Fixed32,
Bool,
String,
Bytes,
Uint32,
Enum,
Sfixed32,
Sfixed64,
Sint32,
Sint64,
Group,
Message,
Duration,
Timestamp,
Any,
FieldMask,
}
impl FieldType {
#[must_use]
#[inline]
pub const fn is_scalar(&self) -> bool {
matches!(
self,
Self::Double
| Self::Float
| Self::Int64
| Self::Uint64
| Self::Int32
| Self::Fixed32
| Self::Fixed64
| Self::Bool | Self::String
| Self::Bytes
| Self::Uint32
| Self::Sfixed32
| Self::Sfixed64
| Self::Sint32
| Self::Sint64
)
}
#[must_use]
#[inline]
pub const fn name(&self) -> &'static str {
match self {
Self::Double => "double",
Self::Float => "float",
Self::Int64 => "int64",
Self::Uint64 => "uint64",
Self::Int32 => "int32",
Self::Fixed64 => "fixed64",
Self::Fixed32 => "fixed32",
Self::Bool => "bool",
Self::String => "string",
Self::Bytes => "bytes",
Self::Uint32 => "uint32",
Self::Enum => "enum",
Self::Sfixed32 => "sfixed32",
Self::Sfixed64 => "sfixed64",
Self::Sint32 => "sint32",
Self::Sint64 => "sint64",
Self::Group => "group",
Self::Message => "message",
Self::Duration => "Duration",
Self::Timestamp => "Timestamp",
Self::Any => "Any",
Self::FieldMask => "FieldMask",
}
}
#[must_use]
#[inline]
pub const fn full_name(&self) -> &'static str {
match self {
Self::Duration => "google.protobuf.Duration",
Self::Timestamp => "google.protobuf.Timestamp",
Self::Any => "google.protobuf.Any",
Self::FieldMask => "google.protobuf.FieldMask",
_ => self.name(),
}
}
}
impl From<FieldType> for ProtoType {
#[inline]
fn from(value: FieldType) -> Self {
match value {
FieldType::Double => Self::Double,
FieldType::Float => Self::Float,
FieldType::Int32 => Self::Int32,
FieldType::Int64 => Self::Int64,
FieldType::Uint32 => Self::Uint32,
FieldType::Uint64 => Self::Uint64,
FieldType::Sint32 => Self::Sint32,
FieldType::Sint64 => Self::Sint64,
FieldType::Fixed32 => Self::Fixed32,
FieldType::Fixed64 => Self::Fixed64,
FieldType::Sfixed32 => Self::Sfixed32,
FieldType::Sfixed64 => Self::Sfixed64,
FieldType::Bool => Self::Bool,
FieldType::String => Self::String,
FieldType::Bytes => Self::Bytes,
FieldType::Message
| FieldType::Duration
| FieldType::Timestamp
| FieldType::Any
| FieldType::FieldMask => Self::Message,
FieldType::Enum => Self::Enum,
FieldType::Group => Self::Group,
}
}
}
impl From<ProtoType> for FieldType {
#[inline]
fn from(value: ProtoType) -> Self {
match value {
ProtoType::Double => Self::Double,
ProtoType::Float => Self::Float,
ProtoType::Int32 => Self::Int32,
ProtoType::Int64 => Self::Int64,
ProtoType::Uint32 => Self::Uint32,
ProtoType::Uint64 => Self::Uint64,
ProtoType::Sint32 => Self::Sint32,
ProtoType::Sint64 => Self::Sint64,
ProtoType::Fixed32 => Self::Fixed32,
ProtoType::Fixed64 => Self::Fixed64,
ProtoType::Sfixed32 => Self::Sfixed32,
ProtoType::Sfixed64 => Self::Sfixed64,
ProtoType::Bool => Self::Bool,
ProtoType::String => Self::String,
ProtoType::Bytes => Self::Bytes,
ProtoType::Message => Self::Message,
ProtoType::Enum => Self::Enum,
ProtoType::Group => Self::Group,
}
}
}