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: schemas/representations.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,7 @@ Link is also not described in this section, as it's a rather unique business.)
43
43
- `kinded` representation -- transcribes to varying (!) kinds in the Data Model.
44
44
- `envelope` representation -- transcribes to a dual-entry `map` in the Data Model.
45
45
- `inline` representation -- transcribes to a `map` in the Data Model (and has additional limitations).
46
+
- `byteprefix` representation -- transcribes to `bytes` in the Data Model, only usable for unions of `bytes`.
46
47
- Struct
47
48
- `map` representation -- the default -- transcribes to `map` in the Data Model.
48
49
- `tuple` representation -- transcribes to `list` in the Data Model.
@@ -291,3 +292,19 @@ This is because inline unions are only a defined concept when working with types
291
292
that have a map representation -- so, our `Bar` type in the previously examples,
292
293
which was of `int` kind, doesn't work for this example. We replaced it with
293
294
another struct type, which -- since it has a `map` representation -- works.
295
+
296
+
#### union byteprefix representation example
297
+
298
+
```ipldsch
299
+
type Signature union {
300
+
| Secp256k1Signature 0
301
+
| Bls12_381Signature 1
302
+
} representation byteprefix
303
+
304
+
type Secp256k1Signature bytes
305
+
type Bls12_381Signature bytes
306
+
```
307
+
308
+
At the block level, this presents as a byte array, where the first byte is the discriminator (`0x00` or `0x01`) and the remainder is sliced to form either of the two types depending on the discriminator.
309
+
310
+
`byteprefix` is not valid for unions where any of the constitutive types are _not_`Bytes`.
0 commit comments