Skip to content

Commit 6c10182

Browse files
committed
incoming value size returns a result
Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com>
1 parent d77574e commit 6c10182

File tree

4 files changed

+64
-18
lines changed

4 files changed

+64
-18
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ This proposal was inspired by Dapr's [State API]
112112
[State API](https://docs.dapr.io/developing-applications/building-blocks/state-management/)
113113

114114
### Change log
115-
115+
- 2023-12-19:
116+
- Changed the `size` to `incoming-value-size` and it's signature
116117
- 2023-11-30:
117118
- Changed the `get` and `get-many` and `keys` signatures
118119
- Updated comments in all the interfaces.

keyvalue-handle-watch.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,16 @@ to the output-stream defined in the <code>wasi-io</code> interface.</p>
491491
<p>
492492
#### <a name="incoming_value">`resource incoming-value`</a>
493493
<p>A incoming-value is a wrapper around a value. It provides a way to read the value
494-
from the input-stream defined in the <code>wasi-io</code> interface.</p>
494+
from the <a href="#input_stream"><code>input-stream</code></a> defined in the <code>wasi-io</code> interface.</p>
495495
<p>The incoming-value provides two ways to consume the value:</p>
496496
<ol>
497497
<li><code>incoming-value-consume-sync</code> consumes the value synchronously and returns the
498-
value as a list of bytes.</li>
498+
value as a <code>list&lt;u8&gt;</code>.</li>
499499
<li><code>incoming-value-consume-async</code> consumes the value asynchronously and returns the
500-
value as an input-stream.</li>
500+
value as an <a href="#input_stream"><code>input-stream</code></a>.
501+
In addition, it provides a <code>incoming-value-size</code> function to get the size of the value.
502+
This is useful when the value is large and the caller wants to allocate a buffer of
503+
the right size to consume the value.</li>
501504
</ol>
502505
<h4><a name="incoming_value_async_body"><code>type incoming-value-async-body</code></a></h4>
503506
<p><a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a></p>
@@ -508,6 +511,8 @@ value as an input-stream.</li>
508511
----
509512
<h3>Functions</h3>
510513
<h4><a name="static_bucket.open_bucket"><code>[static]bucket.open-bucket: func</code></a></h4>
514+
<p>Opens a bucket with the given name.</p>
515+
<p>If any error occurs, including if the bucket does not exist, it returns an <code>Err(error)</code>.</p>
511516
<h5>Params</h5>
512517
<ul>
513518
<li><a name="static_bucket.open_bucket.name"><code>name</code></a>: <code>string</code></li>
@@ -522,6 +527,8 @@ value as an input-stream.</li>
522527
<li><a name="static_outgoing_value.new_outgoing_value.0"></a> own&lt;<a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>&gt;</li>
523528
</ul>
524529
<h4><a name="method_outgoing_value.outgoing_value_write_body_async"><code>[method]outgoing-value.outgoing-value-write-body-async: func</code></a></h4>
530+
<p>Writes the value to the output-stream asynchronously.
531+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
525532
<h5>Params</h5>
526533
<ul>
527534
<li><a name="method_outgoing_value.outgoing_value_write_body_async.self"><code>self</code></a>: borrow&lt;<a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>&gt;</li>
@@ -531,6 +538,8 @@ value as an input-stream.</li>
531538
<li><a name="method_outgoing_value.outgoing_value_write_body_async.0"></a> result&lt;own&lt;<a href="#outgoing_value_body_async"><a href="#outgoing_value_body_async"><code>outgoing-value-body-async</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
532539
</ul>
533540
<h4><a name="method_outgoing_value.outgoing_value_write_body_sync"><code>[method]outgoing-value.outgoing-value-write-body-sync: func</code></a></h4>
541+
<p>Writes the value to the output-stream synchronously.
542+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
534543
<h5>Params</h5>
535544
<ul>
536545
<li><a name="method_outgoing_value.outgoing_value_write_body_sync.self"><code>self</code></a>: borrow&lt;<a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>&gt;</li>
@@ -541,6 +550,8 @@ value as an input-stream.</li>
541550
<li><a name="method_outgoing_value.outgoing_value_write_body_sync.0"></a> result&lt;_, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
542551
</ul>
543552
<h4><a name="method_incoming_value.incoming_value_consume_sync"><code>[method]incoming-value.incoming-value-consume-sync: func</code></a></h4>
553+
<p>Consumes the value synchronously and returns the value as a list of bytes.
554+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
544555
<h5>Params</h5>
545556
<ul>
546557
<li><a name="method_incoming_value.incoming_value_consume_sync.self"><code>self</code></a>: borrow&lt;<a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>&gt;</li>
@@ -550,6 +561,8 @@ value as an input-stream.</li>
550561
<li><a name="method_incoming_value.incoming_value_consume_sync.0"></a> result&lt;<a href="#incoming_value_sync_body"><a href="#incoming_value_sync_body"><code>incoming-value-sync-body</code></a></a>, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
551562
</ul>
552563
<h4><a name="method_incoming_value.incoming_value_consume_async"><code>[method]incoming-value.incoming-value-consume-async: func</code></a></h4>
564+
<p>Consumes the value asynchronously and returns the value as an <a href="#input_stream"><code>input-stream</code></a>.
565+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
553566
<h5>Params</h5>
554567
<ul>
555568
<li><a name="method_incoming_value.incoming_value_consume_async.self"><code>self</code></a>: borrow&lt;<a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>&gt;</li>
@@ -558,14 +571,16 @@ value as an input-stream.</li>
558571
<ul>
559572
<li><a name="method_incoming_value.incoming_value_consume_async.0"></a> result&lt;own&lt;<a href="#incoming_value_async_body"><a href="#incoming_value_async_body"><code>incoming-value-async-body</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
560573
</ul>
561-
<h4><a name="method_incoming_value.size"><code>[method]incoming-value.size: func</code></a></h4>
574+
<h4><a name="method_incoming_value.incoming_value_size"><code>[method]incoming-value.incoming-value-size: func</code></a></h4>
575+
<p>The size of the value in bytes.
576+
If the size is unknown or unavailable, this function returns an <code>Err(error)</code>.</p>
562577
<h5>Params</h5>
563578
<ul>
564-
<li><a name="method_incoming_value.size.self"><code>self</code></a>: borrow&lt;<a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>&gt;</li>
579+
<li><a name="method_incoming_value.incoming_value_size.self"><code>self</code></a>: borrow&lt;<a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>&gt;</li>
565580
</ul>
566581
<h5>Return values</h5>
567582
<ul>
568-
<li><a name="method_incoming_value.size.0"></a> <code>u64</code></li>
583+
<li><a name="method_incoming_value.incoming_value_size.0"></a> result&lt;<code>u64</code>, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
569584
</ul>
570585
<h2><a name="wasi:keyvalue_readwrite">Import interface wasi:keyvalue/readwrite</a></h2>
571586
<p>A keyvalue interface that provides simple read and write operations.</p>

keyvalue.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,16 @@ to the output-stream defined in the <code>wasi-io</code> interface.</p>
494494
<p>
495495
#### <a name="incoming_value">`resource incoming-value`</a>
496496
<p>A incoming-value is a wrapper around a value. It provides a way to read the value
497-
from the input-stream defined in the <code>wasi-io</code> interface.</p>
497+
from the <a href="#input_stream"><code>input-stream</code></a> defined in the <code>wasi-io</code> interface.</p>
498498
<p>The incoming-value provides two ways to consume the value:</p>
499499
<ol>
500500
<li><code>incoming-value-consume-sync</code> consumes the value synchronously and returns the
501-
value as a list of bytes.</li>
501+
value as a <code>list&lt;u8&gt;</code>.</li>
502502
<li><code>incoming-value-consume-async</code> consumes the value asynchronously and returns the
503-
value as an input-stream.</li>
503+
value as an <a href="#input_stream"><code>input-stream</code></a>.
504+
In addition, it provides a <code>incoming-value-size</code> function to get the size of the value.
505+
This is useful when the value is large and the caller wants to allocate a buffer of
506+
the right size to consume the value.</li>
504507
</ol>
505508
<h4><a name="incoming_value_async_body"><code>type incoming-value-async-body</code></a></h4>
506509
<p><a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a></p>
@@ -511,6 +514,8 @@ value as an input-stream.</li>
511514
----
512515
<h3>Functions</h3>
513516
<h4><a name="static_bucket.open_bucket"><code>[static]bucket.open-bucket: func</code></a></h4>
517+
<p>Opens a bucket with the given name.</p>
518+
<p>If any error occurs, including if the bucket does not exist, it returns an <code>Err(error)</code>.</p>
514519
<h5>Params</h5>
515520
<ul>
516521
<li><a name="static_bucket.open_bucket.name"><code>name</code></a>: <code>string</code></li>
@@ -525,6 +530,8 @@ value as an input-stream.</li>
525530
<li><a name="static_outgoing_value.new_outgoing_value.0"></a> own&lt;<a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>&gt;</li>
526531
</ul>
527532
<h4><a name="method_outgoing_value.outgoing_value_write_body_async"><code>[method]outgoing-value.outgoing-value-write-body-async: func</code></a></h4>
533+
<p>Writes the value to the output-stream asynchronously.
534+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
528535
<h5>Params</h5>
529536
<ul>
530537
<li><a name="method_outgoing_value.outgoing_value_write_body_async.self"><code>self</code></a>: borrow&lt;<a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>&gt;</li>
@@ -534,6 +541,8 @@ value as an input-stream.</li>
534541
<li><a name="method_outgoing_value.outgoing_value_write_body_async.0"></a> result&lt;own&lt;<a href="#outgoing_value_body_async"><a href="#outgoing_value_body_async"><code>outgoing-value-body-async</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
535542
</ul>
536543
<h4><a name="method_outgoing_value.outgoing_value_write_body_sync"><code>[method]outgoing-value.outgoing-value-write-body-sync: func</code></a></h4>
544+
<p>Writes the value to the output-stream synchronously.
545+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
537546
<h5>Params</h5>
538547
<ul>
539548
<li><a name="method_outgoing_value.outgoing_value_write_body_sync.self"><code>self</code></a>: borrow&lt;<a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>&gt;</li>
@@ -544,6 +553,8 @@ value as an input-stream.</li>
544553
<li><a name="method_outgoing_value.outgoing_value_write_body_sync.0"></a> result&lt;_, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
545554
</ul>
546555
<h4><a name="method_incoming_value.incoming_value_consume_sync"><code>[method]incoming-value.incoming-value-consume-sync: func</code></a></h4>
556+
<p>Consumes the value synchronously and returns the value as a list of bytes.
557+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
547558
<h5>Params</h5>
548559
<ul>
549560
<li><a name="method_incoming_value.incoming_value_consume_sync.self"><code>self</code></a>: borrow&lt;<a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>&gt;</li>
@@ -553,6 +564,8 @@ value as an input-stream.</li>
553564
<li><a name="method_incoming_value.incoming_value_consume_sync.0"></a> result&lt;<a href="#incoming_value_sync_body"><a href="#incoming_value_sync_body"><code>incoming-value-sync-body</code></a></a>, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
554565
</ul>
555566
<h4><a name="method_incoming_value.incoming_value_consume_async"><code>[method]incoming-value.incoming-value-consume-async: func</code></a></h4>
567+
<p>Consumes the value asynchronously and returns the value as an <a href="#input_stream"><code>input-stream</code></a>.
568+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
556569
<h5>Params</h5>
557570
<ul>
558571
<li><a name="method_incoming_value.incoming_value_consume_async.self"><code>self</code></a>: borrow&lt;<a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>&gt;</li>
@@ -561,14 +574,16 @@ value as an input-stream.</li>
561574
<ul>
562575
<li><a name="method_incoming_value.incoming_value_consume_async.0"></a> result&lt;own&lt;<a href="#incoming_value_async_body"><a href="#incoming_value_async_body"><code>incoming-value-async-body</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
563576
</ul>
564-
<h4><a name="method_incoming_value.size"><code>[method]incoming-value.size: func</code></a></h4>
577+
<h4><a name="method_incoming_value.incoming_value_size"><code>[method]incoming-value.incoming-value-size: func</code></a></h4>
578+
<p>The size of the value in bytes.
579+
If the size is unknown or unavailable, this function returns an <code>Err(error)</code>.</p>
565580
<h5>Params</h5>
566581
<ul>
567-
<li><a name="method_incoming_value.size.self"><code>self</code></a>: borrow&lt;<a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>&gt;</li>
582+
<li><a name="method_incoming_value.incoming_value_size.self"><code>self</code></a>: borrow&lt;<a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>&gt;</li>
568583
</ul>
569584
<h5>Return values</h5>
570585
<ul>
571-
<li><a name="method_incoming_value.size.0"></a> <code>u64</code></li>
586+
<li><a name="method_incoming_value.incoming_value_size.0"></a> result&lt;<code>u64</code>, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
572587
</ul>
573588
<h2><a name="wasi:keyvalue_readwrite">Import interface wasi:keyvalue/readwrite</a></h2>
574589
<p>A keyvalue interface that provides simple read and write operations.</p>

wit/types.wit

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ interface types {
1717
/// In this interface, we use the term `bucket` to refer to a collection of key-value
1818
// Soon: switch to `resource bucket { ... }`
1919
resource bucket {
20+
/// Opens a bucket with the given name.
21+
///
22+
/// If any error occurs, including if the bucket does not exist, it returns an `Err(error)`.
2023
open-bucket: static func(name: string) -> result<bucket, error>;
2124
}
2225
/// A key is a unique identifier for a value in a bucket. The key is used to
@@ -31,26 +34,38 @@ interface types {
3134
// Soon: switch to `resource value { ... }`
3235
resource outgoing-value {
3336
new-outgoing-value: static func() -> outgoing-value;
37+
/// Writes the value to the output-stream asynchronously.
38+
/// If any other error occurs, it returns an `Err(error)`.
3439
outgoing-value-write-body-async: func() -> result<outgoing-value-body-async, error>;
40+
/// Writes the value to the output-stream synchronously.
41+
/// If any other error occurs, it returns an `Err(error)`.
3542
outgoing-value-write-body-sync: func(value: outgoing-value-body-sync) -> result<_, error>;
3643
}
3744
type outgoing-value-body-async = output-stream;
3845
type outgoing-value-body-sync = list<u8>;
3946

40-
4147
/// A incoming-value is a wrapper around a value. It provides a way to read the value
42-
/// from the input-stream defined in the `wasi-io` interface.
48+
/// from the `input-stream` defined in the `wasi-io` interface.
4349
///
4450
/// The incoming-value provides two ways to consume the value:
4551
/// 1. `incoming-value-consume-sync` consumes the value synchronously and returns the
46-
/// value as a list of bytes.
52+
/// value as a `list<u8>`.
4753
/// 2. `incoming-value-consume-async` consumes the value asynchronously and returns the
48-
/// value as an input-stream.
54+
/// value as an `input-stream`.
55+
/// In addition, it provides a `incoming-value-size` function to get the size of the value.
56+
/// This is useful when the value is large and the caller wants to allocate a buffer of
57+
/// the right size to consume the value.
4958
// Soon: switch to `resource incoming-value { ... }`
5059
resource incoming-value {
60+
/// Consumes the value synchronously and returns the value as a list of bytes.
61+
/// If any other error occurs, it returns an `Err(error)`.
5162
incoming-value-consume-sync: func() -> result<incoming-value-sync-body, error>;
63+
/// Consumes the value asynchronously and returns the value as an `input-stream`.
64+
/// If any other error occurs, it returns an `Err(error)`.
5265
incoming-value-consume-async: func() -> result<incoming-value-async-body, error>;
53-
size: func() -> u64;
66+
/// The size of the value in bytes.
67+
/// If the size is unknown or unavailable, this function returns an `Err(error)`.
68+
incoming-value-size: func() -> result<u64, error>;
5469
}
5570
type incoming-value-async-body = input-stream;
5671
type incoming-value-sync-body = list<u8>;

0 commit comments

Comments
 (0)