Coverage for functions \ flipdare \ core \ proto_unwrapper.py: 67%
21 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
2#
3# This file is part of Flipdare's proprietary software and contains
4# confidential and copyrighted material. Unauthorised copying,
5# modification, distribution, or use of this file is strictly
6# prohibited without prior written permission from Flipdare Pty Ltd.
7#
8# This software includes third-party components licensed under MIT,
9# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
10#
12from typing import Any
15class ProtoUnwrapper:
16 def __init__(self, data: Any) -> None:
17 self.data = data
19 def unwrap(self) -> Any:
20 return self._unwrap(self.data)
22 @staticmethod
23 def _unwrap(data: Any) -> Any:
24 """
25 Recursively unwraps Proto3 JSON-wrapped types from Flutter/Firebase.
26 Handles Int64, Float, and Double.
27 """
28 if isinstance(data, dict):
29 # Check for the Proto3 wrapper pattern
30 if "@type" in data and "value" in data:
31 proto_type = data["@type"]
32 val = data["value"]
34 if "Int64Value" in proto_type:
35 return int(val)
36 if "FloatValue" in proto_type or "DoubleValue" in proto_type:
37 return float(val)
38 return val
40 return {k: ProtoUnwrapper._unwrap(v) for k, v in data.items()}
42 if isinstance(data, list):
43 return [ProtoUnwrapper._unwrap(i) for i in data]
45 return data