Skip to content

Commit

Permalink
deploy: ed40d3b
Browse files Browse the repository at this point in the history
  • Loading branch information
github-merge-queue[bot] committed Nov 18, 2024
1 parent daa7fce commit 851aae2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 100 deletions.
12 changes: 2 additions & 10 deletions examples/batch-to-frames.html
Original file line number Diff line number Diff line change
Expand Up @@ -294,23 +294,15 @@ <h2 id="walkthrough"><a class="header" href="#walkthrough">Walkthrough</a></h2>
the <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/enum.Batch.html"><code>Batch</code></a> itself, handling encoding and compression, but
this method is not available yet.</p>
</div>
<p>Once compressed using the helper <code>compress_brotli</code> method, the compressed
bytes can be added to a newly constructed <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html"><code>ChannelOut</code></a>.
<p>Once compressed using the <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/fn.compress_brotli.html"><code>compress_brotli</code></a> method, the
compressed bytes can be added to a newly constructed <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html"><code>ChannelOut</code></a>.
As long as the <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html"><code>ChannelOut</code></a> has <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html#method.ready_bytes"><code>ready_bytes()</code></a>,
<a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.Frame.html"><code>Frame</code></a>s can be constructed using the
<a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html#method.output_frame"><code>ChannelOut::output_frame()</code></a> method, specifying the maximum
frame size.</p>
<p>Once <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.Frame.html"><code>Frame</code></a>s are returned from the <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html"><code>ChannelOut</code></a>,
they can be <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.Frame.html#method.encode"><code>Frame::encode</code></a> into raw, serialized data
ready to be batch-submitted to the data-availability layer.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>In the example below, the additional <code>example_transactions()</code> and <code>compress_brotli()</code>
methods are helper functions that can be ignored for the sake of the example.</p>
</div>
<h2 id="running-this-example"><a class="header" href="#running-this-example">Running this example:</a></h2>
<ul>
<li>Clone the examples repository: <code>git clone git@github.com:alloy-rs/op-alloy.git</code></li>
Expand Down
43 changes: 4 additions & 39 deletions examples/frames-to-batch.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,6 @@ <h2 id="walkthrough"><a class="header" href="#walkthrough">Walkthrough</a></h2>
<code>brotli</code> is used (which was activated in the <a href="https://specs.optimism.io/protocol/fjord/overview.html">Fjord hardfork</a>). Decompressed
brotli bytes can then be passed right into <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.SingleBatch.html#method.decode"><code>Batch::decode</code></a>
to wind up with the example's desired <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/enum.Batch.html"><code>Batch</code></a>.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>In the example below, the additional <code>example_transactions()</code> and <code>decompress_brotli()</code>
methods are helper functions that can be ignored for the sake of the example.</p>
</div>
<h2 id="running-this-example"><a class="header" href="#running-this-example">Running this example:</a></h2>
<ul>
<li>Clone the examples repository: <code>git clone git@github.com:alloy-rs/op-alloy.git</code></li>
Expand All @@ -320,8 +312,7 @@ <h2 id="running-this-example"><a class="header" href="#running-this-example">Run
use alloy_primitives::{hex, Address, BlockHash, Bytes, PrimitiveSignature, U256};
use op_alloy_consensus::OpTxEnvelope;
use op_alloy_genesis::RollupConfig;
use op_alloy_protocol::{Batch, BlockInfo, Channel, Frame, SingleBatch};
use std::io::Read;
use op_alloy_protocol::{decompress_brotli, Batch, BlockInfo, Channel, Frame, SingleBatch};

fn main() {
// Raw frame data taken from the `encode_channel` example.
Expand All @@ -347,11 +338,12 @@ <h2 id="running-this-example"><a class="header" href="#running-this-example">Run
println!("Frame data: {}", hex::encode(&amp;frame_data));

// Decompress the frame data with brotli.
let decompressed = decompress_brotli(&amp;frame_data);
let config = RollupConfig::default();
let max = config.max_rlp_bytes_per_channel(open_block.timestamp) as usize;
let decompressed = decompress_brotli(&amp;frame_data, max).expect("decompresses brotli");
println!("Decompressed frame data: {}", hex::encode(&amp;decompressed));

// Decode the single batch from the decompressed data.
let config = RollupConfig::default();
let batch = Batch::decode(&amp;mut decompressed.as_slice(), &amp;config).expect("batch decodes");
assert_eq!(
batch,
Expand All @@ -367,33 +359,6 @@ <h2 id="running-this-example"><a class="header" href="#running-this-example">Run
println!("Successfully decoded frames into a Batch");
}

/// Decompresses the given bytes data using the Brotli decompressor implemented
/// in the [`brotli`](https://crates.io/crates/brotli) crate.
pub fn decompress_brotli(data: &amp;[u8]) -&gt; Vec&lt;u8&gt; {
let mut reader = brotli::Decompressor::new(data, 4096);
let mut buf = [0u8; 4096];
let mut written = 0;
loop {
match reader.read(&amp;mut buf[..]) {
Err(e) =&gt; {
panic!("{}", e);
}
Ok(size) =&gt; {
if size == 0 {
break;
}
written += size;
// Re-size the buffer if needed
}
}
}

// Truncate the output buffer to the written bytes
let mut output: Vec&lt;u8&gt; = buf.into();
output.truncate(written);
output
}

fn example_transactions() -&gt; Vec&lt;Bytes&gt; {
let mut transactions = Vec::new();

Expand Down
55 changes: 6 additions & 49 deletions print.html
Original file line number Diff line number Diff line change
Expand Up @@ -1904,14 +1904,6 @@ <h2 id="walkthrough"><a class="header" href="#walkthrough">Walkthrough</a></h2>
<code>brotli</code> is used (which was activated in the <a href="https://specs.optimism.io/protocol/fjord/overview.html">Fjord hardfork</a>). Decompressed
brotli bytes can then be passed right into <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.SingleBatch.html#method.decode"><code>Batch::decode</code></a>
to wind up with the example's desired <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/enum.Batch.html"><code>Batch</code></a>.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>In the example below, the additional <code>example_transactions()</code> and <code>decompress_brotli()</code>
methods are helper functions that can be ignored for the sake of the example.</p>
</div>
<h2 id="running-this-example"><a class="header" href="#running-this-example">Running this example:</a></h2>
<ul>
<li>Clone the examples repository: <code>git clone git@github.com:alloy-rs/op-alloy.git</code></li>
Expand All @@ -1924,8 +1916,7 @@ <h2 id="running-this-example"><a class="header" href="#running-this-example">Run
use alloy_primitives::{hex, Address, BlockHash, Bytes, PrimitiveSignature, U256};
use op_alloy_consensus::OpTxEnvelope;
use op_alloy_genesis::RollupConfig;
use op_alloy_protocol::{Batch, BlockInfo, Channel, Frame, SingleBatch};
use std::io::Read;
use op_alloy_protocol::{decompress_brotli, Batch, BlockInfo, Channel, Frame, SingleBatch};

fn main() {
// Raw frame data taken from the `encode_channel` example.
Expand All @@ -1951,11 +1942,12 @@ <h2 id="running-this-example"><a class="header" href="#running-this-example">Run
println!("Frame data: {}", hex::encode(&amp;frame_data));

// Decompress the frame data with brotli.
let decompressed = decompress_brotli(&amp;frame_data);
let config = RollupConfig::default();
let max = config.max_rlp_bytes_per_channel(open_block.timestamp) as usize;
let decompressed = decompress_brotli(&amp;frame_data, max).expect("decompresses brotli");
println!("Decompressed frame data: {}", hex::encode(&amp;decompressed));

// Decode the single batch from the decompressed data.
let config = RollupConfig::default();
let batch = Batch::decode(&amp;mut decompressed.as_slice(), &amp;config).expect("batch decodes");
assert_eq!(
batch,
Expand All @@ -1971,33 +1963,6 @@ <h2 id="running-this-example"><a class="header" href="#running-this-example">Run
println!("Successfully decoded frames into a Batch");
}

/// Decompresses the given bytes data using the Brotli decompressor implemented
/// in the [`brotli`](https://crates.io/crates/brotli) crate.
pub fn decompress_brotli(data: &amp;[u8]) -&gt; Vec&lt;u8&gt; {
let mut reader = brotli::Decompressor::new(data, 4096);
let mut buf = [0u8; 4096];
let mut written = 0;
loop {
match reader.read(&amp;mut buf[..]) {
Err(e) =&gt; {
panic!("{}", e);
}
Ok(size) =&gt; {
if size == 0 {
break;
}
written += size;
// Re-size the buffer if needed
}
}
}

// Truncate the output buffer to the written bytes
let mut output: Vec&lt;u8&gt; = buf.into();
output.truncate(written);
output
}

fn example_transactions() -&gt; Vec&lt;Bytes&gt; {
let mut transactions = Vec::new();

Expand Down Expand Up @@ -2160,23 +2125,15 @@ <h2 id="walkthrough-1"><a class="header" href="#walkthrough-1">Walkthrough</a></
the <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/enum.Batch.html"><code>Batch</code></a> itself, handling encoding and compression, but
this method is not available yet.</p>
</div>
<p>Once compressed using the helper <code>compress_brotli</code> method, the compressed
bytes can be added to a newly constructed <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html"><code>ChannelOut</code></a>.
<p>Once compressed using the <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/fn.compress_brotli.html"><code>compress_brotli</code></a> method, the
compressed bytes can be added to a newly constructed <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html"><code>ChannelOut</code></a>.
As long as the <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html"><code>ChannelOut</code></a> has <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html#method.ready_bytes"><code>ready_bytes()</code></a>,
<a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.Frame.html"><code>Frame</code></a>s can be constructed using the
<a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html#method.output_frame"><code>ChannelOut::output_frame()</code></a> method, specifying the maximum
frame size.</p>
<p>Once <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.Frame.html"><code>Frame</code></a>s are returned from the <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.ChannelOut.html"><code>ChannelOut</code></a>,
they can be <a href="https://docs.rs/op-alloy-protocol/latest/op_alloy_protocol/struct.Frame.html#method.encode"><code>Frame::encode</code></a> into raw, serialized data
ready to be batch-submitted to the data-availability layer.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>In the example below, the additional <code>example_transactions()</code> and <code>compress_brotli()</code>
methods are helper functions that can be ignored for the sake of the example.</p>
</div>
<h2 id="running-this-example-1"><a class="header" href="#running-this-example-1">Running this example:</a></h2>
<ul>
<li>Clone the examples repository: <code>git clone git@github.com:alloy-rs/op-alloy.git</code></li>
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion searchindex.json

Large diffs are not rendered by default.

0 comments on commit 851aae2

Please sign in to comment.