-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement compression for advertisements
- Loading branch information
Showing
7 changed files
with
86 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
type t = | ||
{ profile_id : int | ||
; station_id : int | ||
; team_id : int | ||
; faction_id : int | ||
; race_id : int | ||
; rank_level : int | ||
; rank_match_type_id : int | ||
; time_per_frame_ms : int | ||
; is_ready : bool | ||
; status : int | ||
; metadata : string | ||
} | ||
|
||
let from_json json = | ||
let open Yojson.Basic.Util in | ||
{ profile_id = json |> member "profileInfo.id" |> to_int | ||
; station_id = json |> member "stationID" |> to_int | ||
; team_id = json |> member "teamID" |> to_int | ||
; faction_id = json |> member "factionID" |> to_int | ||
; race_id = json |> member "raceID" |> to_int | ||
; rank_level = json |> member "rankLevel" |> to_int | ||
; rank_match_type_id = json |> member "rankMatchTypeID" |> to_int | ||
; time_per_frame_ms = json |> member "timePerFrameMS" |> to_int | ||
; is_ready = json |> member "isReady" |> to_bool | ||
; status = json |> member "status" |> to_int | ||
; metadata = json |> member "metaData" |> to_string | ||
} | ||
;; | ||
|
||
let to_json = | ||
(* TODO we need to re-encode and compress *) | ||
"" | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
type t = | ||
{ id : int | ||
; slots : Slot.t list | ||
} | ||
|
||
let from_zlib_b64_str compressed_input = | ||
let open Yojson.Basic.Util in | ||
match Compression.Domain.decompress_base64_str compressed_input with | ||
| None -> None | ||
| Some input -> | ||
(try | ||
match Str.split (Str.regexp ",") input with | ||
| id_str :: json_array_str :: _ -> | ||
let id = int_of_string id_str in | ||
let json_list = Yojson.Basic.from_string json_array_str |> to_list in | ||
Some { id; slots = List.map Slot.from_json json_list } | ||
| _ -> None | ||
with | ||
| _ -> None) | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,27 @@ | ||
let () = | ||
let x = | ||
Relic_sdk.Compression.Domain.decompress_base64 | ||
"eNrVkF1PwjAUhv0tvR6GMjYniTeDVWfcgLJ2gvGibl0o3QduEyHG/y6dgUiMF8YLs6uevufknCcP7GkPb2BdFolIuZsnxbmIwcCyTN0yLzVQ1awWRe6OwABqoOYsU2VXAwmLDo39r2QRP5a5vOMbnh5/HqujZbBbNxMdtUZkfMJLVLKMe7NmTlSYs3jXXFE3X6omznjNRqxmYABceWtjguwpQf1pGKvXCe6XNmkybM+6TW+MHQkDiUtPGuYsoGMiocqHFMkdzekidNav8xUaRjCdP11vV6y3haGMQ9/x8/2cjREyAoixT4znuZ5OKKJI5VO6uKHZUhBC1T7bE+4VeNe+u+vAE22dL97giTfVOYj7rP9krvuTud9S9lpBqbeCst8KSqMVlGYrKC/+ifLx7APyMc1P" | ||
in | ||
match x with | ||
| Some data -> Printf.printf "Decompressed data: %s\n" data | ||
| None -> | ||
Printf.printf "Decompression failed.\n"; | ||
Lwt_main.run | ||
@@ Alcotest_lwt.run | ||
"Relic SDK" | ||
[ ( "api" | ||
, [ Alcotest_lwt.test_case "/community/advertisement/findAdvertisements" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_advertisements ()) | ||
; Alcotest_lwt.test_case "/community/news/getNews" `Quick (fun _ () -> Test_cases.Api.test_get_news ()) | ||
; Alcotest_lwt.test_case "/community/achievement/getAchievements" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_achievements ()) | ||
; Alcotest_lwt.test_case "/community/achievement/getAvailableAchievements" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_available_achievements ()) | ||
; Alcotest_lwt.test_case "/community/clan/find" `Quick (fun _ () -> Test_cases.Api.test_find_clans ()) | ||
; Alcotest_lwt.test_case "/community/clan/getClanInfoFull" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_clan_info ()) | ||
; Alcotest_lwt.test_case "/community/CommunityEvent/getAvailableCommunityEvents" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_community_events ()) | ||
; Alcotest_lwt.test_case "/community/leaderboard/GetAvailableLeaderboards" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_leaderboards ()) | ||
; Alcotest_lwt.test_case "/community/leaderboard/GetAvatarStatForProfile" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_avatar_stat ()) | ||
; Alcotest_lwt.test_case "/community/leaderboard/getLeaderBoard2.json" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_leaderboard2 ()) | ||
; Alcotest_lwt.test_case "invalid json" `Quick (fun _ () -> Test_cases.Api.test_invalid ()) | ||
] ) | ||
] | ||
Lwt_main.run | ||
@@ Alcotest_lwt.run | ||
"Relic SDK" | ||
[ ( "api" | ||
, [ Alcotest_lwt.test_case "/community/advertisement/findAdvertisements" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_advertisements ()) | ||
; Alcotest_lwt.test_case "/community/news/getNews" `Quick (fun _ () -> Test_cases.Api.test_get_news ()) | ||
; Alcotest_lwt.test_case "/community/achievement/getAchievements" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_achievements ()) | ||
; Alcotest_lwt.test_case "/community/achievement/getAvailableAchievements" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_available_achievements ()) | ||
; Alcotest_lwt.test_case "/community/clan/find" `Quick (fun _ () -> Test_cases.Api.test_find_clans ()) | ||
; Alcotest_lwt.test_case "/community/clan/getClanInfoFull" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_clan_info ()) | ||
; Alcotest_lwt.test_case "/community/CommunityEvent/getAvailableCommunityEvents" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_community_events ()) | ||
; Alcotest_lwt.test_case "/community/leaderboard/GetAvailableLeaderboards" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_leaderboards ()) | ||
; Alcotest_lwt.test_case "/community/leaderboard/GetAvatarStatForProfile" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_avatar_stat ()) | ||
; Alcotest_lwt.test_case "/community/leaderboard/getLeaderBoard2.json" `Quick (fun _ () -> | ||
Test_cases.Api.test_get_leaderboard2 ()) | ||
; Alcotest_lwt.test_case "invalid json" `Quick (fun _ () -> Test_cases.Api.test_invalid ()) | ||
] ) | ||
] | ||
;; |