Write Node Code
Nodes contain code that processes data. This guide shows you how to write node code in Rust, Python, or C++ to implement your node’s logic.Prerequisites
Before you begin, make sure you have:Node Created
A node created in your graph with input and output ports configured.
Schemas Defined
Schemas created for the data types your node will use.
Language Knowledge
Basic familiarity with Rust, Python, or C++ (depending on your node’s language).
Graph Editor Open
Cerulion Graph Editor running with your graph open.
You can write node code in Rust, Python, or C++. Each language has its own syntax, but the concepts are the same.
What You’ll Do
You’ll write code that:- Receives data from input ports
- Processes the data (your business logic)
- Sends results through output ports
Step-by-Step Guide
1
Select the node
Click on the node you want to write code for.
The node should be selected, and the properties panel should show the node’s properties.
2
Open code editor
In the properties panel, click the Code button (or double-click the node).
The code editor should open, showing a template function based on your node’s ports.
3
Understand the template
The editor provides a template function with your ports as parameters:
The function signature matches your node’s ports. Input ports become function parameters for receiving data, and output ports become parameters for sending data.
4
Receive data from inputs
Read data from input ports:
The
receive() method blocks until data is available. For non-blocking reads, use try_receive() (if available in your language).5
Process the data
Write your business logic to process the received data:
6
Send data to outputs
Send the processed data through output ports:
The
send() method publishes data to the topic connected to that output port. All subscribers to that topic will receive the data.7
Handle errors
Add error handling for robustness:
8
Save the code
Click Save (or press
Ctrl+S / Cmd+S) to save your code.The code should save without errors. If there are syntax errors, the editor will highlight them.
Code Patterns
Publisher Node (No Inputs)
Nodes that generate data:Processor Node (Input and Output)
Nodes that transform data:Subscriber Node (No Outputs)
Nodes that consume data:Best Practices
Single Responsibility
Each node should do one thing well. If a node is doing too much, consider splitting it.
Error Handling
Always handle errors gracefully. Don’t let one bad message crash your pipeline.
Non-Blocking
Keep node code fast and non-blocking. Avoid long-running operations that block execution.
Clear Logic
Write clear, readable code. Future you (and your team) will appreciate it.
Troubleshooting
Syntax errors
Syntax errors
Problem: Code has syntax errors and won’t save.Solutions:
- Check language-specific syntax (Rust/Python/C++ have different rules)
- Verify brackets, parentheses, and semicolons are balanced
- Use the editor’s syntax highlighting to spot errors
- Check for typos in variable and function names
Type errors
Type errors
Problem: Code references types that don’t exist.Solutions:
- Verify schemas are defined and loaded
- Check that port types match schema names exactly
- Ensure schema files are saved and valid
- Try refreshing the project to reload schemas
Port not found
Port not found
Problem: Code references a port that doesn’t exist.Solutions:
- Verify the port exists on the node
- Check that port names match exactly (case-sensitive)
- Ensure ports are saved before writing code
- Check the function signature matches your ports