-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SunDoge
committed
Aug 25, 2023
1 parent
440347a
commit 4ef4b84
Showing
11 changed files
with
220 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#[derive(Debug, PartialEq)] | ||
pub enum JsonType { | ||
Array = 1, | ||
Object, | ||
Number, | ||
String, | ||
Boolean, | ||
Null, | ||
} | ||
|
||
impl From<i32> for JsonType { | ||
fn from(value: i32) -> Self { | ||
match value { | ||
1 => JsonType::Array, | ||
2 => JsonType::Object, | ||
3 => JsonType::Number, | ||
4 => JsonType::String, | ||
5 => JsonType::Boolean, | ||
6 => JsonType::Null, | ||
_ => panic!("Invalid JsonType value: {}", value), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum NumberType { | ||
FloatingPointNumber = 1, | ||
SignedInteger, | ||
UnsignedInteger, | ||
} | ||
|
||
impl From<i32> for NumberType { | ||
fn from(value: i32) -> Self { | ||
match value { | ||
1 => NumberType::FloatingPointNumber, | ||
2 => NumberType::SignedInteger, | ||
3 => NumberType::UnsignedInteger, | ||
_ => panic!("Invalid NumberType value: {}", value), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::{marker::PhantomData, ptr::NonNull}; | ||
|
||
use simdjson_sys as ffi; | ||
|
||
use super::{Document, NumberType}; | ||
use crate::macros::impl_drop; | ||
|
||
pub struct Number<'a> { | ||
ptr: NonNull<ffi::SJ_OD_number>, | ||
_doc: PhantomData<&'a mut Document<'a, 'a>>, | ||
} | ||
|
||
impl<'a> Number<'a> { | ||
pub fn new(ptr: NonNull<ffi::SJ_OD_number>) -> Self { | ||
Self { | ||
ptr, | ||
_doc: PhantomData, | ||
} | ||
} | ||
|
||
pub fn get_uint64(&mut self) -> u64 { | ||
unsafe { ffi::SJ_OD_number_get_uint64(self.ptr.as_mut()) } | ||
} | ||
|
||
pub fn get_int64(&mut self) -> i64 { | ||
unsafe { ffi::SJ_OD_number_get_int64(self.ptr.as_mut()) } | ||
} | ||
|
||
pub fn get_double(&mut self) -> f64 { | ||
unsafe { ffi::SJ_OD_number_get_double(self.ptr.as_mut()) } | ||
} | ||
|
||
pub fn get_number_type(&mut self) -> NumberType { | ||
unsafe { ffi::SJ_OD_number_get_number_type(self.ptr.as_mut()) }.into() | ||
} | ||
} | ||
|
||
impl_drop!(Number<'a>, ffi::SJ_OD_number_free); |
Oops, something went wrong.