Skip to content

refactor: directly serialise Request structs #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/placeos-driver/protocol/management.cr
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,12 @@ class PlaceOS::Driver::Protocol::Management
io.flush
end

private def exec(module_id : String, payload : String, seq : UInt64) : Nil
if (io = @io) && modules[module_id]?
json = %({"id":"#{module_id}","cmd":"exec","seq":#{seq},"payload":#{payload.to_json}})
io.write_bytes json.bytesize
io.write json.to_slice
private def exec(request : Request) : Nil
if (io = @io) && modules[request.id]?
request.to_json(io)
io.flush
elsif promise = request_lock.synchronize { @requests.delete(seq) }
promise.reject Exception.new("module #{module_id} not running on this host")
elsif promise = request_lock.synchronize { @requests.delete(request.seq) }
promise.reject Exception.new("module #{request.id} not running on this host")
end
end

Expand Down
6 changes: 6 additions & 0 deletions src/placeos-driver/protocol/request.cr
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ module PlaceOS
property seq : UInt64?

# For driver to driver comms to route the request back to the originating module
@[JSON::Field(emit_null: false)]
property reply : String?

@[JSON::Field(converter: String::RawConverter)]
property payload : String?

@[JSON::Field(emit_null: false)]
property error : String?

@[JSON::Field(emit_null: false)]
property backtrace : Array(String)?

def set_error(error)
Expand Down