use std::sync::Mutex;
use once_cell::sync::Lazy;
use prost::bytes::Buf;
use prost_types::FileDescriptorProto;
use crate::{reflect::WELL_KNOWN_TYPES_BYTES, DescriptorError, DescriptorPool};
static INSTANCE: Lazy<Mutex<DescriptorPool>> =
Lazy::new(|| Mutex::new(DescriptorPool::decode(WELL_KNOWN_TYPES_BYTES).unwrap()));
impl DescriptorPool {
pub fn global() -> DescriptorPool {
INSTANCE.lock().unwrap().clone()
}
pub fn decode_global_file_descriptor_set<B>(bytes: B) -> Result<(), DescriptorError>
where
B: Buf,
{
let mut instance = INSTANCE.lock().unwrap();
instance.decode_file_descriptor_set(bytes)?;
Ok(())
}
pub fn add_global_file_descriptor_proto<B>(
file: FileDescriptorProto,
) -> Result<(), DescriptorError>
where
B: Buf,
{
let mut instance = INSTANCE.lock().unwrap();
instance.add_file_descriptor_proto(file)?;
Ok(())
}
}