public final class SurfaceSerializer

  1. Object
  2. SurfaceSerializer

Serializes surface descriptors to the canonical wire format shared by every port: a compact JSON document plus PNG blobs named by content hash. This class is an internal seam between the core API and the platform bridges – it is public only because ports live in separate artifacts; apps never call it.

The wire format is versioned ("v": 1) and deterministic: node maps preserve build order, state maps are emitted with sorted keys, timeline entries are sorted ascending by date and image names derive from a hash of the PNG bytes (identical art always gets the same name).

Methods

public static String serializeTimeline(String kindId, WidgetTimeline timeline, Map<String, byte[]> imagesOut)Serializes a widget timeline.
public static String serializeLiveActivity(LiveActivityDescriptor descriptor, Map<String, Object> state, Map<String, byte[]> imagesOut)Serializes a live activity descriptor together with its initial state.
public static String serializeState(Map<String, Object> state)Serializes a state map with sorted keys.
public static String serializeKind(WidgetKind kind)Serializes a widget kind declaration.
public static Map<String, Object> serializeNodeToMap(SurfaceNode node, Map<String, byte[]> imagesOut)Serializes a bare node tree, with no timeline or activity wrapped around it, collecting any imagery it references.

Inherited methods

Method details

serializeTimeline

public static String serializeTimeline(String kindId, WidgetTimeline timeline, Map<String, byte[]> imagesOut)
Serializes a widget timeline.

Parameters

kindId String
the widget kind id the timeline belongs to
timeline WidgetTimeline
the timeline to serialize
imagesOut Map<String, byte[]>
receives PNG blobs keyed by registered name

Returns

the timeline JSON

serializeLiveActivity

public static String serializeLiveActivity(LiveActivityDescriptor descriptor, Map<String, Object> state, Map<String, byte[]> imagesOut)
Serializes a live activity descriptor together with its initial state.

Parameters

descriptor LiveActivityDescriptor
the descriptor to serialize
state Map<String, Object>
the initial state map, may be null
imagesOut Map<String, byte[]>
receives PNG blobs keyed by registered name

Returns

the descriptor JSON

serializeState

public static String serializeState(Map<String, Object> state)
Serializes a state map with sorted keys.

Parameters

state Map<String, Object>
the state map, may be null

Returns

the state JSON

serializeKind

public static String serializeKind(WidgetKind kind)
Serializes a widget kind declaration.

Parameters

kind WidgetKind
the kind to serialize

Returns

the kind JSON

serializeNodeToMap

public static Map<String, Object> serializeNodeToMap(SurfaceNode node, Map<String, byte[]> imagesOut)

Serializes a bare node tree, with no timeline or activity wrapped around it, collecting any imagery it references.

The node catalog is the layout vocabulary for anything the platform renders while this app may be off screen. Widgets and live activities are two such things; an intent result snippet is a third, and it reuses this descriptor and the native renderer that already reads it rather than introducing a parallel one. That is the whole reason this method is public: SurfaceNode#toMap is package-private, and com.codename1.intents needs the same encoding without being handed the node internals.

Parameters

node SurfaceNode
the node tree to serialize
imagesOut Map<String, byte[]>
receives PNG blobs keyed by the name used in the document

Returns

the node descriptor, or null when node is null