oak-protobuf 0.0.11

High-performance incremental Protocol Buffers parser for the oak ecosystem with flexible configuration, optimized for structured data serialization.
Documentation
use oak_core::{ElementType, UniversalElementRole};

/// Element types for the Protobuf language.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ProtobufElementType {
    /// Root node.
    Root,
    /// Whitespace.
    Whitespace,
    /// Newline.
    Newline,
    /// Comment.
    Comment,
    /// Error node.
    Error,
    /// End of stream.
    Eof,

    /// Syntax definition.
    SyntaxDef,
    /// Package definition.
    PackageDef,
    /// Import definition.
    ImportDef,
    /// Option definition.
    OptionDef,
    /// Message definition.
    MessageDef,
    /// Enum definition.
    EnumDef,
    /// Service definition.
    ServiceDef,
    /// RPC definition.
    RpcDef,
    /// Field definition.
    FieldDef,
    /// Map field definition.
    MapFieldDef,
    /// Oneof definition.
    OneofDef,

    /// Identifier.
    Identifier,
    /// String literal.
    StringLiteral,
    /// Number literal.
    NumberLiteral,
    /// Boolean literal.
    BooleanLiteral,
}

impl ElementType for ProtobufElementType {
    type Role = UniversalElementRole;

    fn role(&self) -> Self::Role {
        match self {
            Self::Root => UniversalElementRole::Root,
            _ => UniversalElementRole::None,
        }
    }
}

impl From<crate::lexer::token_type::ProtobufTokenType> for ProtobufElementType {
    fn from(token: crate::lexer::token_type::ProtobufTokenType) -> Self {
        use crate::lexer::token_type::ProtobufTokenType as T;
        match token {
            T::Whitespace => Self::Whitespace,
            T::Newline => Self::Newline,
            T::Comment => Self::Comment,
            T::Identifier => Self::Identifier,
            T::StringLiteral => Self::StringLiteral,
            T::NumberLiteral => Self::NumberLiteral,
            T::BooleanLiteral => Self::BooleanLiteral,
            T::Error => Self::Error,
            _ => Self::Error,
        }
    }
}