MCPcopy
hub / github.com/google/earthengine-api / _encode

Method _encode

python/ee/serializer.py:69–93  ·  view source on GitHub ↗

Encodes a top level object to be executed server-side. Args: obj: The object to encode. Returns: An encoded object ready for JSON serialization.

(self, obj: Any)

Source from the content-addressed store, hash-verified

67 self._hashcache = {}
68
69 def _encode(self, obj: Any) -> Any:
70 """Encodes a top level object to be executed server-side.
71
72 Args:
73 obj: The object to encode.
74
75 Returns:
76 An encoded object ready for JSON serialization.
77 """
78 if self._for_cloud_api:
79 return self._encode_for_cloud_api(obj)
80 value = self._encode_value(obj)
81 if self._is_compound:
82 if (isinstance(value, dict) and value['type'] == 'ValueRef' and
83 len(self._scope) == 1):
84 # Just one value. No need for complex structure.
85 value = self._scope[0][1]
86 else:
87 # Wrap the scopes and final value with a CompoundValue.
88 value = {'type': 'CompoundValue', 'scope': self._scope, 'value': value}
89 # Clear state in case of future encoding.
90 self._scope = []
91 self._encoded = {}
92 self._hashcache = {}
93 return value
94
95 def _encode_for_cloud_api(self, obj: Any) -> Any:
96 """Encodes an object as an Expression or quasi-Expression."""

Callers 4

encodeFunction · 0.95
toJSONFunction · 0.95
test_listMethod · 0.80
test_dictionaryMethod · 0.80

Calls 2

_encode_for_cloud_apiMethod · 0.95
_encode_valueMethod · 0.95

Tested by 2

test_listMethod · 0.64
test_dictionaryMethod · 0.64