"""Typed D/OS objects preserve strong references across an immutable transfer."""
import dos


@dos.dobj("NODE", owner="442f4f532d4150503030303930303031")
class Node:
    count: dos.i32 = 0
    title: str = ""
    raw: bytes = b""
    next: "Node" = None


original = Node()
original.count = 42
original.title = "Hello, D/OS"
original.raw = b"\x00\xff"
original.next = original

# Encoding freezes the graph. Decoding creates new identities, preserving its
# internal references; constructors do not run during import.
payload = dos.dobj_encode(original)
copy = dos.dobj_decode(Node, payload)
copy.title = "Independent copy"
print("D/obj count:", copy.count)
print("Original:", original.title)
print("Copy:", copy.title)
print("Cycle preserved:", copy.next is copy)
print("Raw bytes:", repr(copy.raw))

# Clipboard and drag publication additionally require installed schema trust.
# See DOBJ.md, INTERCHANGE.md and DRAG_SESSION.md for those transaction APIs.
