Add public function for enabling internal serialization
This commit is contained in:
parent
34dd96efb9
commit
e1797d6170
2 changed files with 31 additions and 1 deletions
|
@ -42,7 +42,6 @@ pub(crate) mod query;
|
||||||
pub(crate) mod range;
|
pub(crate) mod range;
|
||||||
pub(crate) mod regex;
|
pub(crate) mod regex;
|
||||||
pub(crate) mod script;
|
pub(crate) mod script;
|
||||||
pub(crate) mod serde;
|
|
||||||
pub(crate) mod split;
|
pub(crate) mod split;
|
||||||
pub(crate) mod start;
|
pub(crate) mod start;
|
||||||
pub(crate) mod statement;
|
pub(crate) mod statement;
|
||||||
|
@ -59,6 +58,7 @@ pub(crate) mod view;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod test;
|
pub(crate) mod test;
|
||||||
|
|
||||||
|
pub mod serde;
|
||||||
pub mod statements;
|
pub mod statements;
|
||||||
|
|
||||||
pub use self::parser::*;
|
pub use self::parser::*;
|
||||||
|
|
|
@ -5,14 +5,44 @@ thread_local! {
|
||||||
static INTERNAL_SERIALIZATION: AtomicBool = AtomicBool::new(false);
|
static INTERNAL_SERIALIZATION: AtomicBool = AtomicBool::new(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// *Advanced use only*. Enables a function to be run, whilst ensuring
|
||||||
|
/// that internal serialization is enabled for [`Value`](crate::sql::Value)
|
||||||
|
/// types. When using internal serialization the non-simplified
|
||||||
|
/// [`Value`](crate::sql::Value) type information is used, for
|
||||||
|
/// serialization to storage or for use in the binary WebSocket protocol.
|
||||||
|
pub fn serialize_internal<T, F: FnOnce() -> T>(f: F) -> T {
|
||||||
|
beg_internal_serialization();
|
||||||
|
let out = f();
|
||||||
|
end_internal_serialization();
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
/// *Advanced use only*. Checks if internal serialization is enabled for
|
||||||
|
/// [`Value`](crate::sql::Value) types. When using internal serialization
|
||||||
|
/// the non-simplified [`Value`](crate::sql::Value) type information is
|
||||||
|
/// used, for serialization to storage or for use in the binary WebSocket
|
||||||
|
/// protocol.
|
||||||
|
#[inline]
|
||||||
pub(crate) fn is_internal_serialization() -> bool {
|
pub(crate) fn is_internal_serialization() -> bool {
|
||||||
INTERNAL_SERIALIZATION.with(|v| v.load(Ordering::Relaxed))
|
INTERNAL_SERIALIZATION.with(|v| v.load(Ordering::Relaxed))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// *Advanced use only*. Marks the beginning of internal serialization for
|
||||||
|
/// [`Value`](crate::sql::Value) types. When using internal serialization
|
||||||
|
/// the non-simplified [`Value`](crate::sql::Value) type information is
|
||||||
|
/// used, for serialization to storage or for use in the binary WebSocket
|
||||||
|
/// protocol.
|
||||||
|
#[inline]
|
||||||
pub(crate) fn beg_internal_serialization() {
|
pub(crate) fn beg_internal_serialization() {
|
||||||
INTERNAL_SERIALIZATION.with(|v| v.store(true, Ordering::Relaxed))
|
INTERNAL_SERIALIZATION.with(|v| v.store(true, Ordering::Relaxed))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// *Advanced use only*. Marks the end of internal serialization for
|
||||||
|
/// [`Value`](crate::sql::Value) types. When using internal serialization
|
||||||
|
/// the non-simplified [`Value`](crate::sql::Value) type information is
|
||||||
|
/// used, for serialization to storage or for use in the binary WebSocket
|
||||||
|
/// protocol.
|
||||||
|
#[inline]
|
||||||
pub(crate) fn end_internal_serialization() {
|
pub(crate) fn end_internal_serialization() {
|
||||||
INTERNAL_SERIALIZATION.with(|v| v.store(false, Ordering::Relaxed))
|
INTERNAL_SERIALIZATION.with(|v| v.store(false, Ordering::Relaxed))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue