Use msgpack for API

This commit is contained in:
Joe 2026-01-27 07:13:02 -06:00
parent 3d328c1d42
commit bda2af3dfb
12 changed files with 264 additions and 172 deletions

View file

@ -1,5 +1,6 @@
local HttpService = game:GetService("HttpService")
local JSON5Decoder = require(script.Parent.Parent.json5.JSON5Decoder)
local msgpack = require(script.Parent.Parent.msgpack)
local stringTemplate = [[
Http.Response {
@ -29,13 +30,11 @@ function Response:isSuccess()
end
function Response:json()
-- Try fast native decode first, fallback to JSON5 for NaN/Infinity
local success, result = pcall(HttpService.JSONDecode, HttpService, self.body)
if success then
return result
end
print("[HTTP Response:json()] Native decode failed, using JSON5 for size:", #self.body)
return JSON5Decoder.Decode(self.body)
return HttpService:JSONDecode(self.body)
end
function Response:msgpack()
return msgpack.decode(self.body)
end
return Response

View file

@ -1,9 +1,8 @@
local HttpService = game:GetService("HttpService")
local Promise = require(script.Parent.Promise)
local Log = require(script.Parent.Log)
local JSON5Decoder = require(script.Parent.json5.JSON5Decoder)
local JSONEncoder = require(script.Parent.json5.JSONEncoder)
local msgpack = require(script.Parent.msgpack)
local Promise = require(script.Parent.Promise)
local HttpError = require(script.Error)
local HttpResponse = require(script.Response)
@ -63,17 +62,19 @@ function Http.post(url, body)
end
function Http.jsonEncode(object)
return JSONEncoder.Compact5(object)
return HttpService:JSONEncode(object)
end
function Http.jsonDecode(source)
-- Try fast native decode first, fallback to JSON5 for NaN/Infinity
local success, result = pcall(HttpService.JSONDecode, HttpService, source)
if success then
return result
end
print("[Http.jsonDecode] Native decode failed, using JSON5 for size:", #source)
return JSON5Decoder.Decode(source)
return HttpService:JSONDecode(source)
end
function Http.msgpackEncode(object)
return msgpack.encode(object)
end
function Http.msgpackDecode(source)
return msgpack.decode(source)
end
return Http