MCPcopy Create free account
hub / github.com/hashintel/hash / decode

Method decode

libs/@local/hashql/eval/src/orchestrator/codec/decode/mod.rs:158–388  ·  view source on GitHub ↗
(
        &self,
        type_id: TypeId,
        value: JsonValueRef<'_>,
    )

Source from the content-addressed store, hash-verified

156 /// [`Value`]: hashql_mir::interpret::value::Value
157 #[expect(clippy::too_many_lines)]
158 pub fn decode(
159 &self,
160 type_id: TypeId,
161 value: JsonValueRef<'_>,
162 ) -> Result<Value<'heap, A>, DecodeError<'heap>>
163 where
164 A: Clone,
165 {
166 let r#type = self.env.r#type(type_id);
167
168 match r#type.kind {
169 &TypeKind::Opaque(OpaqueType { name, repr }) => {
170 let value = self.decode(repr, value)?;
171
172 Ok(Value::Opaque(value::Opaque::new(
173 name,
174 Rc::new_in(value, self.alloc.clone()),
175 )))
176 }
177 TypeKind::Primitive(primitive_type) => match (primitive_type, value) {
178 (PrimitiveType::Number, JsonValueRef::Number(number)) => {
179 number.as_f64().map(From::from).map(Value::Number).ok_or(
180 DecodeError::NumberOutOfRange {
181 expected: Some(type_id),
182 },
183 )
184 }
185 (PrimitiveType::Integer, JsonValueRef::Number(number))
186 if let Some(value) = number.as_i128() =>
187 {
188 Ok(Value::Integer(value::Int::from(value)))
189 }
190 (PrimitiveType::String, JsonValueRef::String(string)) => {
191 let value = value::Str::from(Rc::from_in(string, self.alloc.clone()));
192 Ok(Value::String(value))
193 }
194 (PrimitiveType::Null, JsonValueRef::Null) => Ok(Value::Unit),
195 (PrimitiveType::Boolean, JsonValueRef::Bool(value)) => {
196 Ok(Value::Integer(value::Int::from(value)))
197 }
198 (
199 PrimitiveType::Number,
200 JsonValueRef::Null
201 | JsonValueRef::Bool(_)
202 | JsonValueRef::String(_)
203 | JsonValueRef::Array(_)
204 | JsonValueRef::Object(_),
205 )
206 | (
207 PrimitiveType::Integer,
208 JsonValueRef::Null
209 | JsonValueRef::Bool(_)
210 | JsonValueRef::Number(_)
211 | JsonValueRef::String(_)
212 | JsonValueRef::Array(_)
213 | JsonValueRef::Object(_),
214 )
215 | (

Callers 15

finish_inMethod · 0.45
try_decodeMethod · 0.45
primitive_stringFunction · 0.45
primitive_integerFunction · 0.45
primitive_numberFunction · 0.45
primitive_boolean_trueFunction · 0.45
primitive_boolean_falseFunction · 0.45
primitive_nullFunction · 0.45
primitive_type_mismatchFunction · 0.45
struct_matching_fieldsFunction · 0.45
struct_missing_fieldFunction · 0.45
struct_extra_fieldFunction · 0.45

Calls 15

OkInterface · 0.85
IntegerClass · 0.85
StringClass · 0.85
ErrInterface · 0.85
as_i128Method · 0.80
collect_inMethod · 0.80
intern_sliceMethod · 0.80
zipMethod · 0.80
push_backMethod · 0.80
decode_unknownMethod · 0.80
pushMethod · 0.65
OpaqueClass · 0.50

Tested by 15

primitive_stringFunction · 0.36
primitive_integerFunction · 0.36
primitive_numberFunction · 0.36
primitive_boolean_trueFunction · 0.36
primitive_boolean_falseFunction · 0.36
primitive_nullFunction · 0.36
primitive_type_mismatchFunction · 0.36
struct_matching_fieldsFunction · 0.36
struct_missing_fieldFunction · 0.36
struct_extra_fieldFunction · 0.36
tuple_correct_lengthFunction · 0.36
tuple_length_mismatchFunction · 0.36