mirror of
https://github.com/fluencelabs/aquavm
synced 2025-04-24 14:52:15 +00:00
Merge branch 'master' into feat/VM-454-rkyv-json-value
This commit is contained in:
commit
343b58f65f
@ -85,7 +85,8 @@ impl ExecutionCidState {
|
||||
&mut self,
|
||||
canon_value: &ValueAggregate,
|
||||
) -> Result<CID<CanonCidAggregate>, UncatchableError> {
|
||||
let value_cid = self.value_tracker.track_value(canon_value.get_result().clone())?;
|
||||
let value = canon_value.get_result().clone();
|
||||
let value_cid = self.value_tracker.track_value(value)?;
|
||||
let tetraplet = self.tetraplet_tracker.track_value(canon_value.get_tetraplet())?;
|
||||
|
||||
let canon_value_aggregate = CanonCidAggregate::new(value_cid, tetraplet, canon_value.get_provenance());
|
||||
@ -97,8 +98,8 @@ impl ExecutionCidState {
|
||||
pub(crate) fn get_value_by_cid(&self, cid: &CID<JValue>) -> Result<JValue, UncatchableError> {
|
||||
self.value_tracker
|
||||
.get(cid)
|
||||
.map(|v| (*v).clone())
|
||||
.ok_or_else(|| UncatchableError::ValueForCidNotFound("value", cid.get_inner()))
|
||||
.map(|rc_value| (*rc_value).clone())
|
||||
}
|
||||
|
||||
pub(crate) fn get_tetraplet_by_cid(
|
||||
|
@ -331,9 +331,9 @@ fn fold_merge() {
|
||||
};
|
||||
|
||||
let service_result_agg = data.cid_info.service_result_store.get(cid).unwrap();
|
||||
let value = data.cid_info.value_store.get(&service_result_agg.value_cid).unwrap();
|
||||
let value = &*data.cid_info.value_store.get(&service_result_agg.value_cid).unwrap();
|
||||
|
||||
if let JValue::String(ref var_name) = *value {
|
||||
if let JValue::String(ref var_name) = value {
|
||||
let current_count: usize = calls_count.get(var_name).copied().unwrap_or_default();
|
||||
calls_count.insert(var_name.to_owned(), current_count + 1);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
use super::{JValue, Object};
|
||||
use crate::{JsonString, Map};
|
||||
use crate::{JsonString, Map, Number};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
@ -168,6 +168,22 @@ impl<'a> From<Cow<'a, str>> for JValue {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Number> for JValue {
|
||||
/// Convert `Number` to `JValue::Number`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use air_interpreter_value::{JValue, Number};
|
||||
///
|
||||
/// let n = Number::from(7);
|
||||
/// let x: JValue = n.into();
|
||||
/// ```
|
||||
fn from(f: Number) -> Self {
|
||||
JValue::Number(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Map<JsonString, JValue>> for JValue {
|
||||
/// Convert map (with string keys) to `JValue::Object`.
|
||||
///
|
||||
|
@ -301,7 +301,10 @@ impl JValue {
|
||||
/// return the integer value.
|
||||
#[inline]
|
||||
pub fn is_i64(&self) -> bool {
|
||||
matches!(self, JValue::Number(_))
|
||||
match self {
|
||||
JValue::Number(n) => n.is_i64(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the `JValue` is an integer between zero and `u64::MAX`.
|
||||
@ -310,7 +313,10 @@ impl JValue {
|
||||
/// return the integer value.
|
||||
#[inline]
|
||||
pub fn is_u64(&self) -> bool {
|
||||
false
|
||||
match self {
|
||||
JValue::Number(n) => n.is_u64(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the `JValue` is a number that can be represented by f64.
|
||||
@ -322,7 +328,10 @@ impl JValue {
|
||||
/// `is_u64` return false but this is not a guarantee in the future.
|
||||
#[inline]
|
||||
pub fn is_f64(&self) -> bool {
|
||||
false
|
||||
match self {
|
||||
JValue::Number(n) => n.is_f64(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// If the `JValue` is an integer, represent it as i64 if possible. Returns
|
||||
@ -339,14 +348,20 @@ impl JValue {
|
||||
/// None otherwise.
|
||||
#[inline]
|
||||
pub fn as_u64(&self) -> Option<u64> {
|
||||
None
|
||||
match self {
|
||||
JValue::Number(n) => n.as_u64(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// If the `JValue` is a number, represent it as f64 if possible. Returns
|
||||
/// None otherwise.
|
||||
#[inline]
|
||||
pub fn as_f64(&self) -> Option<f64> {
|
||||
None
|
||||
match self {
|
||||
JValue::Number(n) => n.as_f64(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the `JValue` is a Boolean. Returns false otherwise.
|
||||
|
@ -33,7 +33,7 @@ fn eq_u64(value: &JValue, other: u64) -> bool {
|
||||
fn eq_f32(value: &JValue, other: f32) -> bool {
|
||||
match value {
|
||||
// NB: is not same as the original version
|
||||
JValue::Number(n) => n.as_f64() == Some(other as f64),
|
||||
JValue::Number(n) => n.as_f64().map_or(false, |i| i == other as f64),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use air_interpreter_value::{JValue, Map};
|
||||
// use serde_json::Number;
|
||||
use air_interpreter_value::{JValue, Map, Number};
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_null() {
|
||||
@ -52,12 +51,12 @@ fn test_deserialize_i64_2() {
|
||||
assert_eq!(val, JValue::Number((-42).into()));
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn test_deserialize_f64() {
|
||||
// let inp = "-3140000000000000.0";
|
||||
// let val: JValue = serde_json::from_str(inp).unwrap();
|
||||
// assert_eq!(val, JValue::Number(Number::from_f64(-3.14e15).unwrap()));
|
||||
// }
|
||||
#[test]
|
||||
fn test_deserialize_f64() {
|
||||
let inp = "-3140000000000000.0";
|
||||
let val: JValue = serde_json::from_str(inp).unwrap();
|
||||
assert_eq!(val, JValue::Number(Number::from_f64(-3.14e15).unwrap()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_string_simple() {
|
||||
|
@ -14,8 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use air_interpreter_value::JValue;
|
||||
// use serde_json::Number;
|
||||
use air_interpreter_value::{JValue, Number};
|
||||
|
||||
#[test]
|
||||
fn test_serialize_null() {
|
||||
@ -52,12 +51,12 @@ fn test_serialize_i64_2() {
|
||||
assert_eq!(res, "-42");
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn test_serialize_f64() {
|
||||
// let val = JValue::Number(Number::from_f64(-3.14e15).unwrap());
|
||||
// let res = serde_json::to_string(&val).unwrap();
|
||||
// assert_eq!(res, "-3140000000000000.0");
|
||||
// }
|
||||
#[test]
|
||||
fn test_serialize_f64() {
|
||||
let val = JValue::Number(Number::from_f64(-3.14e15).unwrap());
|
||||
let res = serde_json::to_string(&val).unwrap();
|
||||
assert_eq!(res, "-3140000000000000.0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_string_simple() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user