Skip to content

Commit 9efa711

Browse files
authored
Implement support int64 and uint64 field types (#147)
* Implement support `int64` and `uint64` field types * Refactor `get_destination_settings_if_any` to resolve typing errors
1 parent 278533c commit 9efa711

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ build-backend = "setuptools.build_meta"
2121
enabled = true
2222

2323
[project.optional-dependencies]
24-
fast = ["fig-kiwi==0.1.1"]
25-
dev = ["black==24.2.0", "mypy==0.991", "pytest==8.2.0", "fig-kiwi==0.1.1"]
24+
fast = ["fig-kiwi==0.1.2"]
25+
dev = ["black==24.2.0", "mypy==0.991", "pytest==8.2.0", "fig-kiwi==0.1.2"]
2626

2727
[tool.black]
2828
line-length = 99

src/converter/prototype.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,29 +142,30 @@ def get_destination_settings_if_any(
142142
overlay_settings = None
143143
destination: Optional[str]
144144

145-
match action["connectionType"], action.get("transitionNodeID", None):
146-
case "BACK", _:
147-
destination = "back"
148-
case "INTERNAL_NODE", None:
145+
connection_type = action.get("connectionType")
146+
transition_node_id = action.get("transitionNodeID", None)
147+
148+
if connection_type == "BACK":
149+
destination = "back"
150+
elif connection_type == "INTERNAL_NODE" and transition_node_id is None:
151+
destination = None
152+
elif connection_type == "INTERNAL_NODE" and transition_node_id is not None:
153+
if utils.is_invalid_ref(transition_node_id):
149154
destination = None
150-
case "INTERNAL_NODE", transition_node_id:
151-
if utils.is_invalid_ref(transition_node_id):
152-
destination = None
153-
else:
154-
destination = utils.gen_object_id(transition_node_id)
155-
transition_node = context.fig_node(transition_node_id)
156-
157-
if "overlayBackgroundInteraction" in transition_node:
158-
offset = action.get("overlayRelativePosition", {"x": 0, "y": 0})
159-
160-
overlay_settings = FlowOverlaySettings.Positioned(
161-
transition_node.get("overlayPositionType", "CENTER"),
162-
Point.from_dict(offset),
163-
)
164-
165-
case "NONE", _:
166-
destination = None
167-
case _:
168-
raise Fig2SketchWarning("PRT004")
155+
else:
156+
destination = utils.gen_object_id(transition_node_id)
157+
transition_node = context.fig_node(transition_node_id)
158+
159+
if "overlayBackgroundInteraction" in transition_node:
160+
offset = action.get("overlayRelativePosition", {"x": 0, "y": 0})
161+
162+
overlay_settings = FlowOverlaySettings.Positioned(
163+
transition_node.get("overlayPositionType", "CENTER"),
164+
Point.from_dict(offset),
165+
)
166+
elif connection_type == "NONE":
167+
destination = None
168+
else:
169+
raise Fig2SketchWarning("PRT004")
169170

170171
return destination, overlay_settings

src/figformat/kiwi.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ def uint(self):
2929

3030
return uint
3131

32+
def uint64(self):
33+
uint = 0
34+
shift = 0
35+
for shift in range(0, 64, 7):
36+
b = self.byte()
37+
uint |= (b & 127) << shift
38+
if b < 128:
39+
break
40+
41+
return uint
42+
43+
def int64(self):
44+
v = self.uint64()
45+
return ~(v >> 1) if v & 1 else v >> 1
46+
3247
def float(self):
3348
b = self.byte()
3449
if b == 0:
@@ -82,7 +97,7 @@ def _decode_field(kw):
8297

8398

8499
class KiwiDecoder:
85-
TYPES = ["bool", "byte", "int", "uint", "float", "string"]
100+
TYPES = ["bool", "byte", "int", "uint", "float", "string", "int64", "uint64"]
86101
KINDS = ["ENUM", "STRUCT", "MESSAGE"]
87102

88103
def __init__(self, schema, type_converters):

0 commit comments

Comments
 (0)