use std::collections::HashMap;
use prost::Message;
pub fn decode_geosite(buf: &[u8]) -> Result<SiteGroupList, prost::DecodeError> {
SiteGroupList::decode(buf)
}
pub fn encode_geosite(sg: SiteGroupList) -> Vec<u8> {
sg.encode_to_vec()
}
pub fn decode_geoip(buf: &[u8]) -> Result<GeoIpList, prost::DecodeError> {
GeoIpList::decode(buf)
}
pub fn encode_geoip(sg: GeoIpList) -> Vec<u8> {
sg.encode_to_vec()
}
pub fn to_hashmap(site_group_list: &SiteGroupList) -> HashMap<String, Vec<Vec<String>>> {
let mut map: HashMap<String, Vec<Vec<String>>> = HashMap::new();
for group in &site_group_list.site_group {
for domain in &group.domain {
let key = match domain.r#type {
0 => "DOMAIN-KEYWORD", 1 => "DOMAIN-SUFFIX", 2 => "DOMAIN", 3 => "DOMAIN-REGEX", _ => continue, };
let v = vec![domain.value.clone(), group.tag.clone()];
map.entry(key.to_string()).or_default().push(v);
}
}
map
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Domain {
#[prost(enumeration = "domain::Type", tag = "1")]
pub r#type: i32,
#[prost(string, tag = "2")]
pub value: ::prost::alloc::string::String,
#[prost(message, repeated, tag = "3")]
pub attribute: ::prost::alloc::vec::Vec<domain::Attribute>,
}
pub mod domain {
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Attribute {
#[prost(string, tag = "1")]
pub key: ::prost::alloc::string::String,
#[prost(oneof = "attribute::TypedValue", tags = "2, 3")]
pub typed_value: ::core::option::Option<attribute::TypedValue>,
}
pub mod attribute {
#[derive(Clone, Copy, PartialEq, ::prost::Oneof)]
pub enum TypedValue {
#[prost(bool, tag = "2")]
BoolValue(bool),
#[prost(int64, tag = "3")]
IntValue(i64),
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum Type {
Plain = 0,
Regex = 1,
Domain = 2,
Full = 3,
}
impl Type {
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Plain => "Plain",
Self::Regex => "Regex",
Self::Domain => "Domain",
Self::Full => "Full",
}
}
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"Plain" => Some(Self::Plain),
"Regex" => Some(Self::Regex),
"Domain" => Some(Self::Domain),
"Full" => Some(Self::Full),
_ => None,
}
}
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SiteGroup {
#[prost(string, tag = "1")]
pub tag: ::prost::alloc::string::String,
#[prost(message, repeated, tag = "2")]
pub domain: ::prost::alloc::vec::Vec<Domain>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SiteGroupList {
#[prost(message, repeated, tag = "1")]
pub site_group: ::prost::alloc::vec::Vec<SiteGroup>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Cidr {
#[prost(bytes = "vec", tag = "1")]
pub ip: ::prost::alloc::vec::Vec<u8>,
#[prost(uint32, tag = "2")]
pub prefix: u32,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GeoIp {
#[prost(string, tag = "1")]
pub country_code: ::prost::alloc::string::String,
#[prost(message, repeated, tag = "2")]
pub cidr: ::prost::alloc::vec::Vec<Cidr>,
#[prost(bool, tag = "3")]
pub reverse_match: bool,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GeoIpList {
#[prost(message, repeated, tag = "1")]
pub entry: ::prost::alloc::vec::Vec<GeoIp>,
}