MCPcopy Create free account
hub / github.com/StackStorm/st2 / _serialize_field_value

Method _serialize_field_value

st2common/st2common/fields.py:457–491  ·  view source on GitHub ↗

Serialize and encode the provided field value.

(self, value: dict)

Source from the content-addressed store, hash-verified

455 return data
456
457 def _serialize_field_value(self, value: dict) -> bytes:
458 """
459 Serialize and encode the provided field value.
460 """
461 # Orquesta workflows support toSet() YAQL operator which returns a set which used to get
462 # serialized to list by mongoengine DictField.
463 #
464 # For backward compatibility reasons, we need to support serializing set to a list as
465 # well.
466 #
467 # Based on micro benchmarks, using default function adds very little overhead (1%) so it
468 # should be safe to use default for every operation.
469 #
470 # If this turns out to be not true or it adds more overhead in other scenarios, we should
471 # revisit this decision and only use "default" argument where needed (aka Workflow models).
472 def default(obj):
473 if isinstance(obj, set):
474 return list(obj)
475 raise TypeError
476
477 if not self.use_header:
478 return orjson.dumps(value, default=default)
479
480 data = orjson.dumps(value, default=default)
481
482 if self.compression_algorithm == "zstandard":
483 # NOTE: At this point zstandard is only test dependency
484 import zstandard
485
486 compression_header = JSONDictFieldCompressionAlgorithmEnum.ZSTANDARD
487 data = zstandard.ZstdCompressor().compress(data)
488 else:
489 compression_header = JSONDictFieldCompressionAlgorithmEnum.NONE
490
491 return compression_header.value + b":" + b"o:" + data
492
493 def __get__(self, instance, owner):
494 """

Callers 4

to_mongoMethod · 0.95
to_mongoMethod · 0.80
update_executionFunction · 0.80
migrate_executionsFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected