Decoders #14

Merged
MartinKavik merged 17 commits from decoders into main 2024-07-08 18:02:16 +00:00
12 changed files with 124 additions and 0 deletions
Showing only changes of commit 8f351bd639 - Show all commits

View file

@ -0,0 +1 @@
https://component-model.bytecodealliance.org/

View file

@ -0,0 +1 @@
__pycache__

View file

@ -0,0 +1,11 @@
How to create and build the Python component:
1. `pip install componentize-py`
2. Create the `python_decoder` folder
3. `cd python_decoder`
4. Create `.gitignore` with content `__pycache__`
5. Create the `src` folder with the file `app.py`
6. Create the `wit` folder with the file `world.wit`
7. Update code as needed
8. `componentize-py --wit-path wit/world.wit bindings src/bindings`
9. `componentize-py --wit-path wit/world.wit componentize src.app --output python_decoder.wasm`

View file

@ -0,0 +1,14 @@
from .bindings.component import exports
from .bindings.component.imports import host
name = "Python Test Decoder"
class Decoder(exports.Decoder):
def init(self) -> None:
host.log(f"{name} initialized")
def name(self) -> str:
return name
def format_signal_value(self, value: str) -> str:
return str + "!"

View file

@ -0,0 +1,12 @@
from typing import TypeVar, Generic, Union, Optional, Protocol, Tuple, List, Any, Self
from enum import Flag, Enum, auto
from dataclasses import dataclass
from abc import abstractmethod
import weakref
from .types import Result, Ok, Err, Some
class Component(Protocol):
pass

View file

@ -0,0 +1,24 @@
from typing import TypeVar, Generic, Union, Optional, Protocol, Tuple, List, Any, Self
from enum import Flag, Enum, auto
from dataclasses import dataclass
from abc import abstractmethod
import weakref
from ..types import Result, Ok, Err, Some
class Decoder(Protocol):
@abstractmethod
def init(self) -> None:
raise NotImplementedError
@abstractmethod
def name(self) -> str:
raise NotImplementedError
@abstractmethod
def format_signal_value(self, value: str) -> str:
raise NotImplementedError

View file

@ -0,0 +1,9 @@
from typing import TypeVar, Generic, Union, Optional, Protocol, Tuple, List, Any, Self
from enum import Flag, Enum, auto
from dataclasses import dataclass
from abc import abstractmethod
import weakref
from ..types import Result, Ok, Err, Some

View file

@ -0,0 +1,13 @@
from typing import TypeVar, Generic, Union, Optional, Protocol, Tuple, List, Any, Self
from enum import Flag, Enum, auto
from dataclasses import dataclass
from abc import abstractmethod
import weakref
from ..types import Result, Ok, Err, Some
def log(message: str) -> None:
raise NotImplementedError

View file

@ -0,0 +1,23 @@
from typing import TypeVar, Generic, Union, Optional, Protocol, Tuple, List, Any, Self
from enum import Flag, Enum, auto
from dataclasses import dataclass
from abc import abstractmethod
import weakref
S = TypeVar('S')
@dataclass
class Some(Generic[S]):
value: S
T = TypeVar('T')
@dataclass
class Ok(Generic[T]):
value: T
E = TypeVar('E')
@dataclass(frozen=True)
class Err(Generic[E], Exception):
value: E
Result = Union[Ok[T], Err[E]]

View file

@ -0,0 +1,16 @@
package component:python-decoder;
interface host {
log: func(message: string);
}
interface decoder {
init: func();
name: func() -> string;
format-signal-value: func(value: string) -> string;
}
world component {
import host;
export decoder;
}