mirror of
https://github.com/fluencelabs/interface-types
synced 2025-07-06 01:51:46 +00:00
feat(interface-types) Introduce the record type.
This patch updates the `Type` type to be an enum with 2 variants: `Function` and `Record`, resp. to represent: 1. `(@interface type (func (param i32 i32) (result string)))` 2. `(@interface type (record string i32))` This patch updates the binary encoder and decoder, along with the WAT encoder and decoder.
This commit is contained in:
@ -112,6 +112,19 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Encode a `TypeKind` into bytes.
|
||||
impl<W> ToBytes<W> for TypeKind
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
fn to_bytes(&self, writer: &mut W) -> io::Result<()> {
|
||||
match self {
|
||||
TypeKind::Function => 0x00_u8.to_bytes(writer),
|
||||
TypeKind::Record => 0x01_u8.to_bytes(writer),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Encode an `InterfaceKind` into bytes.
|
||||
impl<W> ToBytes<W> for InterfaceKind
|
||||
where
|
||||
@ -136,8 +149,18 @@ where
|
||||
W: Write,
|
||||
{
|
||||
fn to_bytes(&self, writer: &mut W) -> io::Result<()> {
|
||||
self.inputs.to_bytes(writer)?;
|
||||
self.outputs.to_bytes(writer)?;
|
||||
match self {
|
||||
Type::Function { inputs, outputs } => {
|
||||
TypeKind::Function.to_bytes(writer)?;
|
||||
inputs.to_bytes(writer)?;
|
||||
outputs.to_bytes(writer)?;
|
||||
}
|
||||
|
||||
Type::Record { fields } => {
|
||||
TypeKind::Record.to_bytes(writer)?;
|
||||
fields.to_bytes(writer)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user