LayrzProtocolHttp constructor
LayrzProtocolHttp({
- required String ident,
- String password = '',
- required String server,
- LayrzProtocolVersion version = LayrzProtocolVersion.v2,
- @visibleForTesting Dio? testDio,
LayrzProtocolHttp is the class that contains the methods to interact with the Layrz ecosystem.
All of the methods are asynchronous and return a Future<void> that is a list of Command. Also, all of them may throw an exception if something goes wrong:
- ServerException if the server returns an error 500.
- MalformedException if the message is malformed, or when the server returns an unexpected response.
- ParseException if the message is not well formatted.
- CrcException if the CRC is not valid.
- CommandException if the command is not well formatted.
Implementation
LayrzProtocolHttp({
required this.ident,
this.password = '',
required this.server,
this.version = LayrzProtocolVersion.v2,
@visibleForTesting Dio? testDio,
}) : assert(ident.isNotEmpty) {
_baseUrl = server;
_dio =
testDio ??
Dio(
BaseOptions(
baseUrl: baseUrl,
headers: headers,
responseDecoder: (bytes, options, responseBody) => utf8.decode(bytes, allowMalformed: true),
requestEncoder: (data, options) => utf8.encode(data),
),
);
}