Module: nintendo.nex.streams

Extends generic memory streams with useful nex related methods.

class StreamOut(anynet.StreamOut)
An output stream that supports various nex structures.

class StreamIn(anynet.StreamIn)
An input stream that supports various nex structures.

StreamOut

def __init__(settings: Settings)
Creates a new output stream.

def pid(value: int) -> None
Writes a user id into the stream.

def result(value: Result) -> None
Writes a result into the stream.

def list(value: list, func: Callable) -> None
Writes a list into the stream. For example: stream.list([1, 2, 3], stream.u8).

def map(value: dict, keyfunc: Callable, valuefunc: Callable) -> None
Writes a map into the stream. For example: stream.map({"a": 1, "b": 2}, stream.string, stream.u8).

def string(value: str) -> None
Writes an UTF-8 string into the stream. Automatically adds a null terminator.

def stationurl(value: StationURL) -> None
Writes a StationURL into the stream.

def datetime(value: DateTime) -> None
Writes a DateTime object into the stream.

def buffer(value: bytes) -> None
Writes a buffer into the stream with a 32-bit length field.

def qbuffer(value: bytes) -> None
Writes a buffer into the stream with a 16-bit length field.

def add(value: Structure) -> None
Writes a nex structure into the stream.

def anydata(value: object) -> None
Wraps a structure in a data holder and writes it into the stream.

def variant(value: object) -> None
Writes a variant into the stream. value must be either None or an instance of int, float, bool, str or DateTime.

StreamIn

def __init__(data: bytes, settings: Settings)
Creates a new input stream.

def pid() -> int
Reads a user id from the stream.

def result() -> Result
Reads a result from the stream.

def repeat(func: Callable, num: int) -> list
Extracts a fixed number of copies of a given type from the stream. For convenience, func may also be a subclass of Structure instead of a function. For example: stream.repeat(stream.u8, 5) or stream.repeat(ResultRange, 2).

def list(func: Callable) -> list
Reads a list from the stream. For convenience, func may also be a subclass of Structure instead of a function. For example: stream.list(stream.u8) or stream.list(ResultRange).

def map(keyfunc: Callable, valuefunc: Callable) -> dict
Reads a map from the stream. For convenience, keyfunc and valuefunc may also be a subclass of Structure instead of a function. For example: stream.map(stream.string, ResultRange).

def string() -> str
Reads a UTF-8 string from the stream. Automatically removes the null terminator.

def stationurl() -> StationURL
Reads a station url from the stream.

def datetime() -> DateTime
Reads a DateTime object from the stream.

def buffer() -> bytes
Reads a buffer from the stream with a 32-bit length field.

def qbuffer() -> bytes
Reads a buffer from the stream with a 16-bit length field.

def substream() -> StreamIn
Reads a buffer from the stream with a 32-bit length field and returns an input stream.

def extract(cls: Type[Structure]) -> Structure
Reads a nex structure from the stream.

def anydata() -> object
Reads a data holder from the stream and returns its content, which is usually a subclass of Data.

def variant() -> object
Reads a variant from the stream.