Skip to content

Commit 7eef1ef

Browse files
committed
incoming value size returns a result
Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]>
1 parent 165dbbe commit 7eef1ef

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed

README.md

+2-1
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

+21-6
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,16 @@ to the output-stream defined in the `wasi-io` interface.
501501
#### <a name="incoming_value">`type incoming-value`</a>
502502
`u32`
503503
<p>A incoming-value is a wrapper around a value. It provides a way to read the value
504-
from the input-stream defined in the `wasi-io` interface.
504+
from the `input-stream` defined in the `wasi-io` interface.
505505
<p>The incoming-value provides two ways to consume the value:</p>
506506
<ol>
507507
<li><a href="#incoming_value_consume_sync"><code>incoming-value-consume-sync</code></a> consumes the value synchronously and returns the
508-
value as a list of bytes.</li>
508+
value as a <code>list&lt;u8&gt;</code>.</li>
509509
<li><a href="#incoming_value_consume_async"><code>incoming-value-consume-async</code></a> consumes the value asynchronously and returns the
510-
value as an input-stream.</li>
510+
value as an <a href="#input_stream"><code>input-stream</code></a>.
511+
In addition, it provides a <a href="#incoming_value_size"><code>incoming-value-size</code></a> function to get the size of the value.
512+
This is useful when the value is large and the caller wants to allocate a buffer of
513+
the right size to consume the value.</li>
511514
</ol>
512515
<h4><a name="incoming_value_async_body"><code>type incoming-value-async-body</code></a></h4>
513516
<p><a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a></p>
@@ -523,6 +526,8 @@ value as an input-stream.</li>
523526
<li><a name="drop_bucket.bucket"><a href="#bucket"><code>bucket</code></a></a>: <a href="#bucket"><a href="#bucket"><code>bucket</code></a></a></li>
524527
</ul>
525528
<h4><a name="open_bucket"><code>open-bucket: func</code></a></h4>
529+
<p>Opens a bucket with the given name.</p>
530+
<p>If any error occurs, including if the bucket does not exist, it returns an <code>Err(error)</code>.</p>
526531
<h5>Params</h5>
527532
<ul>
528533
<li><a name="open_bucket.name"><code>name</code></a>: <code>string</code></li>
@@ -542,6 +547,8 @@ value as an input-stream.</li>
542547
<li><a name="new_outgoing_value.0"></a> <a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a></li>
543548
</ul>
544549
<h4><a name="outgoing_value_write_body_async"><code>outgoing-value-write-body-async: func</code></a></h4>
550+
<p>Writes the value to the output-stream asynchronously.
551+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
545552
<h5>Params</h5>
546553
<ul>
547554
<li><a name="outgoing_value_write_body_async.outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>: <a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a></li>
@@ -551,6 +558,8 @@ value as an input-stream.</li>
551558
<li><a name="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;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
552559
</ul>
553560
<h4><a name="outgoing_value_write_body_sync"><code>outgoing-value-write-body-sync: func</code></a></h4>
561+
<p>Writes the value to the output-stream synchronously.
562+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
554563
<h5>Params</h5>
555564
<ul>
556565
<li><a name="outgoing_value_write_body_sync.outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>: <a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a></li>
@@ -566,6 +575,8 @@ value as an input-stream.</li>
566575
<li><a name="drop_incoming_value.incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>: <a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a></li>
567576
</ul>
568577
<h4><a name="incoming_value_consume_sync"><code>incoming-value-consume-sync: func</code></a></h4>
578+
<p>Consumes the value synchronously and returns the value as a list of bytes.
579+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
569580
<h5>Params</h5>
570581
<ul>
571582
<li><a name="incoming_value_consume_sync.incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>: <a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a></li>
@@ -575,6 +586,8 @@ value as an input-stream.</li>
575586
<li><a name="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>, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
576587
</ul>
577588
<h4><a name="incoming_value_consume_async"><code>incoming-value-consume-async: func</code></a></h4>
589+
<p>Consumes the value asynchronously and returns the value as an <a href="#input_stream"><code>input-stream</code></a>.
590+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
578591
<h5>Params</h5>
579592
<ul>
580593
<li><a name="incoming_value_consume_async.incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>: <a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a></li>
@@ -583,14 +596,16 @@ value as an input-stream.</li>
583596
<ul>
584597
<li><a name="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;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
585598
</ul>
586-
<h4><a name="size"><code>size: func</code></a></h4>
599+
<h4><a name="incoming_value_size"><code>incoming-value-size: func</code></a></h4>
600+
<p>The size of the value in bytes.
601+
If the size is unknown or unavailable, this function returns an <code>Err(error)</code>.</p>
587602
<h5>Params</h5>
588603
<ul>
589-
<li><a name="size.incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>: <a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a></li>
604+
<li><a name="incoming_value_size.incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>: <a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a></li>
590605
</ul>
591606
<h5>Return values</h5>
592607
<ul>
593-
<li><a name="size.0"></a> <code>u64</code></li>
608+
<li><a name="incoming_value_size.0"></a> result&lt;<code>u64</code>, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
594609
</ul>
595610
<h2><a name="wasi:keyvalue_readwrite">Import interface wasi:keyvalue/readwrite</a></h2>
596611
<p>A keyvalue interface that provides simple read and write operations.</p>

keyvalue.md

+21-6
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,16 @@ to the output-stream defined in the `wasi-io` interface.
504504
#### <a name="incoming_value">`type incoming-value`</a>
505505
`u32`
506506
<p>A incoming-value is a wrapper around a value. It provides a way to read the value
507-
from the input-stream defined in the `wasi-io` interface.
507+
from the `input-stream` defined in the `wasi-io` interface.
508508
<p>The incoming-value provides two ways to consume the value:</p>
509509
<ol>
510510
<li><a href="#incoming_value_consume_sync"><code>incoming-value-consume-sync</code></a> consumes the value synchronously and returns the
511-
value as a list of bytes.</li>
511+
value as a <code>list&lt;u8&gt;</code>.</li>
512512
<li><a href="#incoming_value_consume_async"><code>incoming-value-consume-async</code></a> consumes the value asynchronously and returns the
513-
value as an input-stream.</li>
513+
value as an <a href="#input_stream"><code>input-stream</code></a>.
514+
In addition, it provides a <a href="#incoming_value_size"><code>incoming-value-size</code></a> function to get the size of the value.
515+
This is useful when the value is large and the caller wants to allocate a buffer of
516+
the right size to consume the value.</li>
514517
</ol>
515518
<h4><a name="incoming_value_async_body"><code>type incoming-value-async-body</code></a></h4>
516519
<p><a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a></p>
@@ -526,6 +529,8 @@ value as an input-stream.</li>
526529
<li><a name="drop_bucket.bucket"><a href="#bucket"><code>bucket</code></a></a>: <a href="#bucket"><a href="#bucket"><code>bucket</code></a></a></li>
527530
</ul>
528531
<h4><a name="open_bucket"><code>open-bucket: func</code></a></h4>
532+
<p>Opens a bucket with the given name.</p>
533+
<p>If any error occurs, including if the bucket does not exist, it returns an <code>Err(error)</code>.</p>
529534
<h5>Params</h5>
530535
<ul>
531536
<li><a name="open_bucket.name"><code>name</code></a>: <code>string</code></li>
@@ -545,6 +550,8 @@ value as an input-stream.</li>
545550
<li><a name="new_outgoing_value.0"></a> <a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a></li>
546551
</ul>
547552
<h4><a name="outgoing_value_write_body_async"><code>outgoing-value-write-body-async: func</code></a></h4>
553+
<p>Writes the value to the output-stream asynchronously.
554+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
548555
<h5>Params</h5>
549556
<ul>
550557
<li><a name="outgoing_value_write_body_async.outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>: <a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a></li>
@@ -554,6 +561,8 @@ value as an input-stream.</li>
554561
<li><a name="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;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
555562
</ul>
556563
<h4><a name="outgoing_value_write_body_sync"><code>outgoing-value-write-body-sync: func</code></a></h4>
564+
<p>Writes the value to the output-stream synchronously.
565+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
557566
<h5>Params</h5>
558567
<ul>
559568
<li><a name="outgoing_value_write_body_sync.outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>: <a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a></li>
@@ -569,6 +578,8 @@ value as an input-stream.</li>
569578
<li><a name="drop_incoming_value.incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>: <a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a></li>
570579
</ul>
571580
<h4><a name="incoming_value_consume_sync"><code>incoming-value-consume-sync: func</code></a></h4>
581+
<p>Consumes the value synchronously and returns the value as a list of bytes.
582+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
572583
<h5>Params</h5>
573584
<ul>
574585
<li><a name="incoming_value_consume_sync.incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>: <a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a></li>
@@ -578,6 +589,8 @@ value as an input-stream.</li>
578589
<li><a name="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>, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
579590
</ul>
580591
<h4><a name="incoming_value_consume_async"><code>incoming-value-consume-async: func</code></a></h4>
592+
<p>Consumes the value asynchronously and returns the value as an <a href="#input_stream"><code>input-stream</code></a>.
593+
If any other error occurs, it returns an <code>Err(error)</code>.</p>
581594
<h5>Params</h5>
582595
<ul>
583596
<li><a name="incoming_value_consume_async.incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>: <a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a></li>
@@ -586,14 +599,16 @@ value as an input-stream.</li>
586599
<ul>
587600
<li><a name="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;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
588601
</ul>
589-
<h4><a name="size"><code>size: func</code></a></h4>
602+
<h4><a name="incoming_value_size"><code>incoming-value-size: func</code></a></h4>
603+
<p>The size of the value in bytes.
604+
If the size is unknown or unavailable, this function returns an <code>Err(error)</code>.</p>
590605
<h5>Params</h5>
591606
<ul>
592-
<li><a name="size.incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>: <a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a></li>
607+
<li><a name="incoming_value_size.incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a>: <a href="#incoming_value"><a href="#incoming_value"><code>incoming-value</code></a></a></li>
593608
</ul>
594609
<h5>Return values</h5>
595610
<ul>
596-
<li><a name="size.0"></a> <code>u64</code></li>
611+
<li><a name="incoming_value_size.0"></a> result&lt;<code>u64</code>, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
597612
</ul>
598613
<h2><a name="wasi:keyvalue_readwrite">Import interface wasi:keyvalue/readwrite</a></h2>
599614
<p>A keyvalue interface that provides simple read and write operations.</p>

wit/types.wit

+20-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ interface types {
1818
// Soon: switch to `resource bucket { ... }`
1919
type bucket = u32;
2020
drop-bucket: func(bucket: bucket);
21+
/// Opens a bucket with the given name.
22+
///
23+
/// If any error occurs, including if the bucket does not exist, it returns an `Err(error)`.
2124
open-bucket: func(name: string) -> result<bucket, error>;
2225

2326
/// A key is a unique identifier for a value in a bucket. The key is used to
@@ -35,23 +38,36 @@ interface types {
3538
type outgoing-value-body-sync = list<u8>;
3639
drop-outgoing-value: func(outgoing-value: outgoing-value);
3740
new-outgoing-value: func() -> outgoing-value;
41+
/// Writes the value to the output-stream asynchronously.
42+
/// If any other error occurs, it returns an `Err(error)`.
3843
outgoing-value-write-body-async: func(outgoing-value: outgoing-value) -> result<outgoing-value-body-async, error>;
44+
/// Writes the value to the output-stream synchronously.
45+
/// If any other error occurs, it returns an `Err(error)`.
3946
outgoing-value-write-body-sync: func(outgoing-value: outgoing-value, value: outgoing-value-body-sync) -> result<_, error>;
4047

4148
/// 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.
49+
/// from the `input-stream` defined in the `wasi-io` interface.
4350
///
4451
/// The incoming-value provides two ways to consume the value:
4552
/// 1. `incoming-value-consume-sync` consumes the value synchronously and returns the
46-
/// value as a list of bytes.
53+
/// value as a `list<u8>`.
4754
/// 2. `incoming-value-consume-async` consumes the value asynchronously and returns the
48-
/// value as an input-stream.
55+
/// value as an `input-stream`.
56+
/// In addition, it provides a `incoming-value-size` function to get the size of the value.
57+
/// This is useful when the value is large and the caller wants to allocate a buffer of
58+
/// the right size to consume the value.
4959
// Soon: switch to `resource incoming-value { ... }`
5060
type incoming-value = u32;
5161
type incoming-value-async-body = input-stream;
5262
type incoming-value-sync-body = list<u8>;
5363
drop-incoming-value: func(incoming-value: incoming-value);
64+
/// Consumes the value synchronously and returns the value as a list of bytes.
65+
/// If any other error occurs, it returns an `Err(error)`.
5466
incoming-value-consume-sync: func(incoming-value: incoming-value) -> result<incoming-value-sync-body, error>;
67+
/// Consumes the value asynchronously and returns the value as an `input-stream`.
68+
/// If any other error occurs, it returns an `Err(error)`.
5569
incoming-value-consume-async: func(incoming-value: incoming-value) -> result<incoming-value-async-body, error>;
56-
size: func(incoming-value: incoming-value) -> u64;
70+
/// The size of the value in bytes.
71+
/// If the size is unknown or unavailable, this function returns an `Err(error)`.
72+
incoming-value-size: func(incoming-value: incoming-value) -> result<u64, error>;
5773
}

0 commit comments

Comments
 (0)