Current section
Files
Jump to
Current section
Files
src/chrobot_extra/protocol/io.gleam
//// > ⚙️ This module was generated from the Chrome DevTools Protocol version **1.3**
//// ## IO Domain
////
//// Input/Output operations for streams produced by DevTools.
////
//// [📖 View this domain on the DevTools Protocol API Docs](https://chromedevtools.github.io/devtools-protocol/1-3/IO/)
// ---------------------------------------------------------------------------
// | !!!!!! This is an autogenerated file - Do not edit manually !!!!!! |
// | Run `codegen.sh` to regenerate. |
// ---------------------------------------------------------------------------
import chrobot_extra/chrome
import chrobot_extra/internal/utils
import chrobot_extra/protocol/runtime
import gleam/dynamic/decode
import gleam/json
import gleam/option
import gleam/result
/// This is either obtained from another method or specified as `blob:<uuid>` where
/// `<uuid>` is an UUID of a Blob.
pub type StreamHandle {
StreamHandle(String)
}
@internal
pub fn encode__stream_handle(value__: StreamHandle) {
case value__ {
StreamHandle(inner_value__) -> json.string(inner_value__)
}
}
@internal
pub fn decode__stream_handle() {
{
use value__ <- decode.then(decode.string)
decode.success(StreamHandle(value__))
}
}
/// This type is not part of the protocol spec, it has been generated dynamically
/// to represent the response to the command `read`
pub type ReadResponse {
ReadResponse(
/// Set if the data is base64-encoded
base64_encoded: option.Option(Bool),
/// Data that were read.
data: String,
/// Set if the end-of-file condition occurred while reading.
eof: Bool,
)
}
@internal
pub fn decode__read_response() {
{
use base64_encoded <- decode.optional_field(
"base64Encoded",
option.None,
decode.optional(decode.bool),
)
use data <- decode.field("data", decode.string)
use eof <- decode.field("eof", decode.bool)
decode.success(ReadResponse(
base64_encoded: base64_encoded,
data: data,
eof: eof,
))
}
}
/// This type is not part of the protocol spec, it has been generated dynamically
/// to represent the response to the command `resolve_blob`
pub type ResolveBlobResponse {
ResolveBlobResponse(
/// UUID of the specified Blob.
uuid: String,
)
}
@internal
pub fn decode__resolve_blob_response() {
{
use uuid <- decode.field("uuid", decode.string)
decode.success(ResolveBlobResponse(uuid: uuid))
}
}
/// Close the stream, discard any temporary backing storage.
///
/// Parameters:
/// - `handle` : Handle of the stream to close.
///
/// Returns:
///
pub fn close(callback__, handle handle: StreamHandle) {
callback__(
"IO.close",
option.Some(
json.object([
#("handle", encode__stream_handle(handle)),
]),
),
)
}
/// Read a chunk of the stream
///
/// Parameters:
/// - `handle` : Handle of the stream to read.
/// - `offset` : Seek to the specified offset before reading (if not specified, proceed with offset
/// following the last read). Some types of streams may only support sequential reads.
/// - `size` : Maximum number of bytes to read (left upon the agent discretion if not specified).
///
/// Returns:
/// - `base64_encoded` : Set if the data is base64-encoded
/// - `data` : Data that were read.
/// - `eof` : Set if the end-of-file condition occurred while reading.
///
pub fn read(
callback__,
handle handle: StreamHandle,
offset offset: option.Option(Int),
size size: option.Option(Int),
) {
use result__ <- result.try(callback__(
"IO.read",
option.Some(json.object(
[
#("handle", encode__stream_handle(handle)),
]
|> utils.add_optional(offset, fn(inner_value__) {
#("offset", json.int(inner_value__))
})
|> utils.add_optional(size, fn(inner_value__) {
#("size", json.int(inner_value__))
}),
)),
))
decode.run(result__, decode__read_response())
|> result.replace_error(chrome.ProtocolError)
}
/// Return UUID of Blob object specified by a remote object id.
///
/// Parameters:
/// - `object_id` : Object id of a Blob object wrapper.
///
/// Returns:
/// - `uuid` : UUID of the specified Blob.
///
pub fn resolve_blob(callback__, object_id object_id: runtime.RemoteObjectId) {
use result__ <- result.try(callback__(
"IO.resolveBlob",
option.Some(
json.object([
#("objectId", runtime.encode__remote_object_id(object_id)),
]),
),
))
decode.run(result__, decode__resolve_blob_response())
|> result.replace_error(chrome.ProtocolError)
}