Skip to content
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

Use msgpack for API #908

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "plugin/Packages/Highlighter"]
path = plugin/Packages/Highlighter
url = https://github.com/boatbomber/highlighter.git
[submodule "plugin/Packages/msgpack-luau"]
path = plugin/Packages/msgpack-luau
url = https://github.com/cipharius/msgpack-luau
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
| `ignore` | None! |

**All** sync rules are reset between project files, so they must be specified in each one when nesting them. This is to ensure that nothing can break other projects by changing how files are synced!
* `inf` and `nan` values in properties are now synced ([#908])

[#813]: https://github.com/rojo-rbx/rojo/pull/813
[#834]: https://github.com/rojo-rbx/rojo/pull/834
Expand All @@ -62,6 +63,7 @@
[#883]: https://github.com/rojo-rbx/rojo/pull/883
[#893]: https://github.com/rojo-rbx/rojo/pull/893
[#903]: https://github.com/rojo-rbx/rojo/pull/903
[#908]: https://github.com/rojo-rbx/rojo/pull/908
[#911]: https://github.com/rojo-rbx/rojo/pull/911

## [7.4.1] - February 20, 2024
Expand Down
19 changes: 15 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ tokio = { version = "1.36.0", features = ["rt", "rt-multi-thread"] }
uuid = { version = "1.7.0", features = ["v4", "serde"] }
clap = { version = "3.2.25", features = ["derive"] }
profiling = "1.0.15"
rmp-serde = "1.3.0"
float-cmp = "0.9.0"

[target.'cfg(windows)'.dependencies]
winreg = "0.10.1"
Expand Down
6 changes: 3 additions & 3 deletions aftman.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tools]
rojo = "rojo-rbx/rojo@7.3.0"
selene = "Kampfkarren/selene@0.26.1"
stylua = "JohnnyMorganz/stylua@0.18.2"
rojo = "rojo-rbx/rojo@7.4.1"
selene = "Kampfkarren/selene@0.27.1"
stylua = "JohnnyMorganz/stylua@0.20.0"
run-in-roblox = "rojo-rbx/run-in-roblox@0.3.0"
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ fn snapshot_from_fs_path(path: &Path) -> io::Result<VfsSnapshot> {
continue;
}

// Ignore images in msgpack-luau because they aren't UTF-8 encoded.
if file_name.ends_with(".png") {
continue;
}

let child_snapshot = snapshot_from_fs_path(&entry.path())?;
children.push((file_name, child_snapshot));
}
Expand Down
1 change: 1 addition & 0 deletions plugin/Packages/msgpack-luau
Submodule msgpack-luau added at 0754b1
8 changes: 7 additions & 1 deletion plugin/http/Response.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local HttpService = game:GetService("HttpService")

local msgpack = require(script.Parent.Parent.msgpack)

local stringTemplate = [[
Http.Response {
code: %d
Expand Down Expand Up @@ -31,4 +33,8 @@ function Response:json()
return HttpService:JSONDecode(self.body)
end

return Response
function Response:msgpack()
return msgpack.decode(self.body)
end

return Response
5 changes: 5 additions & 0 deletions plugin/http/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local HttpService = game:GetService("HttpService")

local Promise = require(script.Parent.Promise)
local Log = require(script.Parent.Log)
local msgpack = require(script.Parent.msgpack)

local HttpError = require(script.Error)
local HttpResponse = require(script.Response)
Expand Down Expand Up @@ -68,4 +69,8 @@ function Http.jsonDecode(source)
return HttpService:JSONDecode(source)
end

function Http.msgpackEncode(object)
return msgpack.encode(object)
end

return Http
21 changes: 12 additions & 9 deletions plugin/src/ApiContext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function ApiContext:connect()

return Http.get(url)
:andThen(rejectFailedRequests)
:andThen(Http.Response.json)
:andThen(Http.Response.msgpack)
:andThen(rejectWrongProtocolVersion)
:andThen(function(body)
assert(validateApiInfo(body))
Expand All @@ -140,7 +140,7 @@ end
function ApiContext:read(ids)
local url = ("%s/api/read/%s"):format(self.__baseUrl, table.concat(ids, ","))

return Http.get(url):andThen(rejectFailedRequests):andThen(Http.Response.json):andThen(function(body)
return Http.get(url):andThen(rejectFailedRequests):andThen(Http.Response.msgpack):andThen(function(body)
if body.sessionId ~= self.__sessionId then
return Promise.reject("Server changed ID")
end
Expand Down Expand Up @@ -183,13 +183,16 @@ function ApiContext:write(patch)
added = added,
}

body = Http.jsonEncode(body)
body = Http.msgpackEncode(body)

return Http.post(url, body):andThen(rejectFailedRequests):andThen(Http.Response.json):andThen(function(responseBody)
Log.info("Write response: {:?}", responseBody)
return Http.post(url, body)
:andThen(rejectFailedRequests)
:andThen(Http.Response.msgpack)
:andThen(function(responseBody)
Log.info("Write response: {:?}", responseBody)

return responseBody
end)
return responseBody
end)
end

function ApiContext:retrieveMessages()
Expand All @@ -214,7 +217,7 @@ function ApiContext:retrieveMessages()
end)
end

return sendRequest():andThen(rejectFailedRequests):andThen(Http.Response.json):andThen(function(body)
return sendRequest():andThen(rejectFailedRequests):andThen(Http.Response.msgpack):andThen(function(body)
if body.sessionId ~= self.__sessionId then
return Promise.reject("Server changed ID")
end
Expand All @@ -230,7 +233,7 @@ end
function ApiContext:open(id)
local url = ("%s/api/open/%s"):format(self.__baseUrl, id)

return Http.post(url, ""):andThen(rejectFailedRequests):andThen(Http.Response.json):andThen(function(body)
return Http.post(url, ""):andThen(rejectFailedRequests):andThen(Http.Response.msgpack):andThen(function(body)
if body.sessionId ~= self.__sessionId then
return Promise.reject("Server changed ID")
end
Expand Down
4 changes: 4 additions & 0 deletions plugin/src/Reconciler/diff.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ local function trueEquals(a, b): boolean
end
return true

-- For NaN, check if both values are not equal to themselves
elseif a ~= a and b ~= b then
return true

-- For numbers, compare with epsilon of 0.0001 to avoid floating point inequality
elseif typeA == "number" and typeB == "number" then
return fuzzyEq(a, b, 0.0001)
Expand Down
2 changes: 1 addition & 1 deletion plugin/watch-build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Continously build the rojo plugin into the local plugin directory on Windows
rojo build plugin/default.project.json -o $LOCALAPPDATA/Roblox/Plugins/Rojo.rbxm --watch
rojo build plugin/default.project.json -p Rojo.rbxm --watch
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod serve_session;
mod session_id;
mod snapshot;
mod snapshot_middleware;
mod variant_eq;
mod web;

pub use project::*;
Expand Down
8 changes: 5 additions & 3 deletions src/snapshot/patch_compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::{

use rbx_dom_weak::types::{Ref, Variant};

use crate::variant_eq::variant_eq;

use super::{
patch::{PatchAdd, PatchSet, PatchUpdate},
InstanceSnapshot, InstanceWithMeta, RojoTree,
Expand Down Expand Up @@ -122,7 +124,7 @@ fn compute_property_patches(

match instance.properties().get(&name) {
Some(instance_value) => {
if &snapshot_value != instance_value {
if !variant_eq(&snapshot_value, instance_value) {
changed_properties.insert(name, Some(snapshot_value));
}
}
Expand Down Expand Up @@ -246,7 +248,7 @@ mod test {
// addition of a prop named Self, which is a self-referential Ref.
let snapshot_id = Ref::new();
let snapshot = InstanceSnapshot {
snapshot_id: snapshot_id,
snapshot_id,
properties: hashmap! {
"Self".to_owned() => Variant::Ref(snapshot_id),
},
Expand Down Expand Up @@ -288,7 +290,7 @@ mod test {
// This patch describes the existing instance with a new child added.
let snapshot_id = Ref::new();
let snapshot = InstanceSnapshot {
snapshot_id: snapshot_id,
snapshot_id,
children: vec![InstanceSnapshot {
properties: hashmap! {
"Self".to_owned() => Variant::Ref(snapshot_id),
Expand Down
Loading
Loading