You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-12Lines changed: 11 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,11 +15,10 @@ This project was initially forked from [filecoin's CborDecode.sol](https://githu
15
15
16
16
## Usage
17
17
18
-
Most methods accept parameters `bytes` of CBOR data and `uint32` index, and return an updated index (and one or more values if appropriate). Since the data parameter is always first, you may sugar calls via `using` directive.
18
+
Most methods accept parameters `bytes` of CBOR data and `uint256` index, and return an updated index (and one or more values if appropriate). Since the data parameter is always first, you may sugar calls via `using` directive.
19
19
20
20
CBOR natively supports values up to `uint64`, so the typical values returned are `uint64`. Some methods return other types.
21
21
22
-
23
22
Deserialization methods are a capitalized name of the type like `UInt`, `NInt`, `Text`, `Map`, and so on for every CBOR type. These return a value of the equivalent solidity type when possible.
24
23
25
24
When specific format constraints exist, some optimized method variants are available, such as `String1` when the next should be a 1-byte string.
@@ -28,38 +27,38 @@ You can peek at the type of the next item with `isBytes` and so on.
28
27
29
28
The caller is responsible for handling the index and using it to index the appropriate data. No 'cursor' metaphor is provided, but the example below demonstrates how a caller may define and use a cursor for convenience.
30
29
31
-
32
30
```solidity
33
31
using ReadCbor for bytes;
34
32
35
33
bytes constant someBytes = hex"84616103616102";
36
34
37
35
struct Cursor {
38
36
bytes b;
39
-
uint32 i;
37
+
uint256 i;
40
38
}
41
39
42
40
function example() pure {
43
41
Cursor memory c = Cursor(someBytes, 0);
44
-
uint32 len;
45
-
46
-
(c.i, len) = c.b.Array(c.i);
42
+
uint32 arrayLen;
47
43
48
-
assert(len == 4);
44
+
(c.i, arrayLen) = c.b.Array(c.i);
49
45
50
-
string[] memory arrayStrs = new string[](len / 2);
51
-
uint64[] memory arrayNums = new uint64[](len / 2);
46
+
// In this example, we know the array length.
47
+
assert(arrayLen == 4);
48
+
string[] memory arrayStrs = new string[](2);
49
+
uint64[] memory arrayNums = new uint64[](2);
52
50
53
51
// CBOR arrays may contain items of any type.
54
-
for (uint32 arrayIdx = 0; arrayIdx < len; arrayIdx++) {
52
+
for (uint32 arrayIdx = 0; arrayIdx < arrayLen; arrayIdx++) {
0 commit comments