Skip to content

Commit

Permalink
[values][primitives] Add immutable parameter to deserialization fun…
Browse files Browse the repository at this point in the history
…ctions [#68]
  • Loading branch information
cipriancraciun committed Jun 9, 2018
1 parent 0ba4d08 commit 9955028
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions sources/builtins_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub fn cache_select_serde (cache : &Value, namespace : Option<&Value>, key : &Va
let busting = option_map! (busting, try! (hash_value_with_blake2b (busting, CACHE_BUSTING_SIZE * 8, partition_key, HashMode::ValuesCoerceMutable)));
let busting = option_ref_map! (busting, busting.deref ());

let value = try! (cache_backend_select (database, key, time_to_live, busting, integrity_key, |value| serde_deserialize_from_buffer (value)));
let value = try! (cache_backend_select (database, key, time_to_live, busting, integrity_key, |value| serde_deserialize_from_buffer (value, None)));
let value = value.unwrap_or (FALSE_VALUE);

succeed! (value);
Expand Down Expand Up @@ -436,7 +436,7 @@ pub fn cache_resolve_serde (cache : &Value, namespace : Option<&Value>, key : &V
let busting = option_ref_map! (busting, busting.deref ());

{
let value = try! (cache_backend_select (database, key, time_to_live, busting, integrity_key, |value| serde_deserialize_from_buffer (value)));
let value = try! (cache_backend_select (database, key, time_to_live, busting, integrity_key, |value| serde_deserialize_from_buffer (value, None)));
if let Some (value) = value {
succeed! (value);
}
Expand Down
32 changes: 16 additions & 16 deletions sources/builtins_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ pub fn serde_serialize_into_bytes (value : &Value, immutable : Option<bool>) ->

#[ cfg ( feature = "vonuvoli_values_bytes" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn serde_deserialize_from_bytes (bytes : &Value) -> (Outcome<Value>) {
pub fn serde_deserialize_from_bytes (bytes : &Value, immutable : Option<bool>) -> (Outcome<Value>) {
let buffer = try_as_bytes_ref! (bytes);
let buffer = buffer.bytes_as_slice ();
let value = try! (serde_deserialize_from_buffer (buffer));
let value = try! (serde_deserialize_from_buffer (buffer, immutable));
succeed! (value);
}

Expand All @@ -68,10 +68,10 @@ pub fn serde_serialize_into_buffer (value : &Value) -> (Outcome<StdBox<[u8]>>) {


#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn serde_deserialize_from_buffer (buffer : &[u8]) -> (Outcome<Value>) {
pub fn serde_deserialize_from_buffer (buffer : &[u8], immutable : Option<bool>) -> (Outcome<Value>) {
let config = serde_bincode_config ();
let value = try_or_fail! (config.deserialize (buffer), 0x9664c785);
let value = try! (serde_ast_to_value (value));
let value = try! (serde_ast_to_value (value, immutable));
succeed! (value);
}

Expand Down Expand Up @@ -262,7 +262,7 @@ pub fn serde_value_to_ast (value : &Value) -> (Outcome<ValueSerde>) {


#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn serde_ast_to_value (value : ValueSerde) -> (Outcome<Value>) {
pub fn serde_ast_to_value (value : ValueSerde, immutable : Option<bool>) -> (Outcome<Value>) {
match value {

ValueSerde::Null =>
Expand Down Expand Up @@ -290,32 +290,32 @@ pub fn serde_ast_to_value (value : ValueSerde) -> (Outcome<Value>) {

#[ cfg ( feature = "vonuvoli_values_string" ) ]
ValueSerde::String (value) =>
succeed! (string_new (value, None) .into ()),
succeed! (string_new (value, immutable) .into ()),
#[ cfg ( feature = "vonuvoli_values_bytes" ) ]
ValueSerde::Bytes (value) =>
succeed! (bytes_new (value, None) .into ()),
succeed! (bytes_new (value, immutable) .into ()),

ValueSerde::Pair (left, right) => {
let left = try! (serde_ast_to_value (*left));
let right = try! (serde_ast_to_value (*right));
succeed! (pair_new (left, right, None) .into ());
let left = try! (serde_ast_to_value (*left, immutable));
let right = try! (serde_ast_to_value (*right, immutable));
succeed! (pair_new (left, right, immutable) .into ());
},
ValueSerde::List (values, dotted) => {
let values = try_vec_map_into! (values, value, serde_ast_to_value (value));
let dotted = try_option_map! (dotted, serde_ast_to_value (*dotted));
let list = list_collect_dotted (values, dotted, None);
let values = try_vec_map_into! (values, value, serde_ast_to_value (value, immutable));
let dotted = try_option_map! (dotted, serde_ast_to_value (*dotted, immutable));
let list = list_collect_dotted (values, dotted, immutable);
succeed! (list);
},


#[ cfg ( feature = "vonuvoli_values_array" ) ]
ValueSerde::Array (values) => {
let values = try_vec_map_into! (values, value, serde_ast_to_value (value));
succeed! (array_new (values, None) .into ());
let values = try_vec_map_into! (values, value, serde_ast_to_value (value, immutable));
succeed! (array_new (values, immutable) .into ());
},
#[ cfg ( feature = "vonuvoli_values_values" ) ]
ValueSerde::Values (values) => {
let values = try_vec_map_into! (values, value, serde_ast_to_value (value));
let values = try_vec_map_into! (values, value, serde_ast_to_value (value, immutable));
succeed! (values_new (values.into_boxed_slice ()) .into ());
},

Expand Down
2 changes: 1 addition & 1 deletion sources/primitives_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ pub fn runtime_primitive_1_evaluate (primitive : RuntimePrimitive1, input_1 : &V
#[ cfg ( feature = "vonuvoli_builtins_serde" ) ]
#[ cfg ( feature = "vonuvoli_values_bytes" ) ]
RuntimePrimitive1::SerdeDeserializeBytes =>
return serde_deserialize_from_bytes (input_1),
return serde_deserialize_from_bytes (input_1, None),

#[ cfg ( feature = "vonuvoli_builtins_hashes" ) ]
RuntimePrimitive1::DefaultHash =>
Expand Down

0 comments on commit 9955028

Please sign in to comment.