mirror of
https://github.com/servo/servo
synced 2026-04-26 01:25:32 +02:00
Make the `start` and `end` parameters in `getBreakpointPositionsCompressed` optional. Send a resource array even if it is empty. Testing: Ran `mach test-devtools`. --------- Signed-off-by: eri <eri@igalia.com>
54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
use serde::Serialize;
|
|
|
|
use crate::protocol::JsonPacketStream;
|
|
|
|
pub enum ResourceArrayType {
|
|
Available,
|
|
Updated,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub(crate) struct ResourceAvailableReply<T: Serialize> {
|
|
from: String,
|
|
#[serde(rename = "type")]
|
|
type_: String,
|
|
array: Vec<(String, Vec<T>)>,
|
|
}
|
|
|
|
pub(crate) trait ResourceAvailable {
|
|
fn actor_name(&self) -> String;
|
|
|
|
fn resource_array<T: Serialize, S: JsonPacketStream>(
|
|
&self,
|
|
resource: T,
|
|
resource_type: String,
|
|
array_type: ResourceArrayType,
|
|
stream: &mut S,
|
|
) {
|
|
self.resources_array(vec![resource], resource_type, array_type, stream);
|
|
}
|
|
|
|
fn resources_array<T: Serialize, S: JsonPacketStream>(
|
|
&self,
|
|
resources: Vec<T>,
|
|
resource_type: String,
|
|
array_type: ResourceArrayType,
|
|
stream: &mut S,
|
|
) {
|
|
let msg = ResourceAvailableReply::<T> {
|
|
from: self.actor_name(),
|
|
type_: match array_type {
|
|
ResourceArrayType::Available => "resources-available-array".to_string(),
|
|
ResourceArrayType::Updated => "resources-updated-array".to_string(),
|
|
},
|
|
array: vec![(resource_type, resources)],
|
|
};
|
|
|
|
let _ = stream.write_json_packet(&msg);
|
|
}
|
|
}
|