Masterarbeit Richard Stern. Flutter App, sich mit einem Bluetooth-Gerät verbindet und Berührungen auf einem Sensor visualisiert.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FlutterCodecs.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. // Copyright 2013 The Flutter Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef FLUTTER_FLUTTERCODECS_H_
  5. #define FLUTTER_FLUTTERCODECS_H_
  6. #import <Foundation/Foundation.h>
  7. #include "FlutterMacros.h"
  8. NS_ASSUME_NONNULL_BEGIN
  9. /**
  10. A message encoding/decoding mechanism.
  11. */
  12. FLUTTER_EXPORT
  13. @protocol FlutterMessageCodec
  14. /**
  15. * Returns a shared instance of this `FlutterMessageCodec`.
  16. */
  17. + (instancetype)sharedInstance;
  18. /**
  19. * Encodes the specified message into binary.
  20. *
  21. * @param message The message.
  22. * @return The binary encoding, or `nil`, if `message` was `nil`.
  23. */
  24. - (NSData* _Nullable)encode:(id _Nullable)message;
  25. /**
  26. * Decodes the specified message from binary.
  27. *
  28. * @param message The message.
  29. * @return The decoded message, or `nil`, if `message` was `nil`.
  30. */
  31. - (id _Nullable)decode:(NSData* _Nullable)message;
  32. @end
  33. /**
  34. * A `FlutterMessageCodec` using unencoded binary messages, represented as
  35. * `NSData` instances.
  36. *
  37. * This codec is guaranteed to be compatible with the corresponding
  38. * [BinaryCodec](https://docs.flutter.io/flutter/services/BinaryCodec-class.html)
  39. * on the Dart side. These parts of the Flutter SDK are evolved synchronously.
  40. *
  41. * On the Dart side, messages are represented using `ByteData`.
  42. */
  43. FLUTTER_EXPORT
  44. @interface FlutterBinaryCodec : NSObject <FlutterMessageCodec>
  45. @end
  46. /**
  47. * A `FlutterMessageCodec` using UTF-8 encoded `NSString` messages.
  48. *
  49. * This codec is guaranteed to be compatible with the corresponding
  50. * [StringCodec](https://docs.flutter.io/flutter/services/StringCodec-class.html)
  51. * on the Dart side. These parts of the Flutter SDK are evolved synchronously.
  52. */
  53. FLUTTER_EXPORT
  54. @interface FlutterStringCodec : NSObject <FlutterMessageCodec>
  55. @end
  56. /**
  57. * A `FlutterMessageCodec` using UTF-8 encoded JSON messages.
  58. *
  59. * This codec is guaranteed to be compatible with the corresponding
  60. * [JSONMessageCodec](https://docs.flutter.io/flutter/services/JSONMessageCodec-class.html)
  61. * on the Dart side. These parts of the Flutter SDK are evolved synchronously.
  62. *
  63. * Supports values accepted by `NSJSONSerialization` plus top-level
  64. * `nil`, `NSNumber`, and `NSString`.
  65. *
  66. * On the Dart side, JSON messages are handled by the JSON facilities of the
  67. * [`dart:convert`](https://api.dartlang.org/stable/dart-convert/JSON-constant.html)
  68. * package.
  69. */
  70. FLUTTER_EXPORT
  71. @interface FlutterJSONMessageCodec : NSObject <FlutterMessageCodec>
  72. @end
  73. /**
  74. * A writer of the Flutter standard binary encoding.
  75. *
  76. * See `FlutterStandardMessageCodec` for details on the encoding.
  77. *
  78. * The encoding is extensible via subclasses overriding `writeValue`.
  79. */
  80. FLUTTER_EXPORT
  81. @interface FlutterStandardWriter : NSObject
  82. - (instancetype)initWithData:(NSMutableData*)data;
  83. - (void)writeByte:(UInt8)value;
  84. - (void)writeBytes:(const void*)bytes length:(NSUInteger)length;
  85. - (void)writeData:(NSData*)data;
  86. - (void)writeSize:(UInt32)size;
  87. - (void)writeAlignment:(UInt8)alignment;
  88. - (void)writeUTF8:(NSString*)value;
  89. - (void)writeValue:(id)value;
  90. @end
  91. /**
  92. * A reader of the Flutter standard binary encoding.
  93. *
  94. * See `FlutterStandardMessageCodec` for details on the encoding.
  95. *
  96. * The encoding is extensible via subclasses overriding `readValueOfType`.
  97. */
  98. FLUTTER_EXPORT
  99. @interface FlutterStandardReader : NSObject
  100. - (instancetype)initWithData:(NSData*)data;
  101. - (BOOL)hasMore;
  102. - (UInt8)readByte;
  103. - (void)readBytes:(void*)destination length:(NSUInteger)length;
  104. - (NSData*)readData:(NSUInteger)length;
  105. - (UInt32)readSize;
  106. - (void)readAlignment:(UInt8)alignment;
  107. - (NSString*)readUTF8;
  108. - (nullable id)readValue;
  109. - (nullable id)readValueOfType:(UInt8)type;
  110. @end
  111. /**
  112. * A factory of compatible reader/writer instances using the Flutter standard
  113. * binary encoding or extensions thereof.
  114. */
  115. FLUTTER_EXPORT
  116. @interface FlutterStandardReaderWriter : NSObject
  117. - (FlutterStandardWriter*)writerWithData:(NSMutableData*)data;
  118. - (FlutterStandardReader*)readerWithData:(NSData*)data;
  119. @end
  120. /**
  121. * A `FlutterMessageCodec` using the Flutter standard binary encoding.
  122. *
  123. * This codec is guaranteed to be compatible with the corresponding
  124. * [StandardMessageCodec](https://docs.flutter.io/flutter/services/StandardMessageCodec-class.html)
  125. * on the Dart side. These parts of the Flutter SDK are evolved synchronously.
  126. *
  127. * Supported messages are acyclic values of these forms:
  128. *
  129. * - `nil` or `NSNull`
  130. * - `NSNumber` (including their representation of Boolean values)
  131. * - `NSString`
  132. * - `FlutterStandardTypedData`
  133. * - `NSArray` of supported values
  134. * - `NSDictionary` with supported keys and values
  135. *
  136. * On the Dart side, these values are represented as follows:
  137. *
  138. * - `nil` or `NSNull`: null
  139. * - `NSNumber`: `bool`, `int`, or `double`, depending on the contained value.
  140. * - `NSString`: `String`
  141. * - `FlutterStandardTypedData`: `Uint8List`, `Int32List`, `Int64List`, or `Float64List`
  142. * - `NSArray`: `List`
  143. * - `NSDictionary`: `Map`
  144. */
  145. FLUTTER_EXPORT
  146. @interface FlutterStandardMessageCodec : NSObject <FlutterMessageCodec>
  147. + (instancetype)codecWithReaderWriter:(FlutterStandardReaderWriter*)readerWriter;
  148. @end
  149. /**
  150. Command object representing a method call on a `FlutterMethodChannel`.
  151. */
  152. FLUTTER_EXPORT
  153. @interface FlutterMethodCall : NSObject
  154. /**
  155. * Creates a method call for invoking the specified named method with the
  156. * specified arguments.
  157. *
  158. * @param method the name of the method to call.
  159. * @param arguments the arguments value.
  160. */
  161. + (instancetype)methodCallWithMethodName:(NSString*)method arguments:(id _Nullable)arguments;
  162. /**
  163. * The method name.
  164. */
  165. @property(readonly, nonatomic) NSString* method;
  166. /**
  167. * The arguments.
  168. */
  169. @property(readonly, nonatomic, nullable) id arguments;
  170. @end
  171. /**
  172. * Error object representing an unsuccessful outcome of invoking a method
  173. * on a `FlutterMethodChannel`, or an error event on a `FlutterEventChannel`.
  174. */
  175. FLUTTER_EXPORT
  176. @interface FlutterError : NSObject
  177. /**
  178. * Creates a `FlutterError` with the specified error code, message, and details.
  179. *
  180. * @param code An error code string for programmatic use.
  181. * @param message A human-readable error message.
  182. * @param details Custom error details.
  183. */
  184. + (instancetype)errorWithCode:(NSString*)code
  185. message:(NSString* _Nullable)message
  186. details:(id _Nullable)details;
  187. /**
  188. The error code.
  189. */
  190. @property(readonly, nonatomic) NSString* code;
  191. /**
  192. The error message.
  193. */
  194. @property(readonly, nonatomic, nullable) NSString* message;
  195. /**
  196. The error details.
  197. */
  198. @property(readonly, nonatomic, nullable) id details;
  199. @end
  200. /**
  201. * Type of numeric data items encoded in a `FlutterStandardDataType`.
  202. *
  203. * - FlutterStandardDataTypeUInt8: plain bytes
  204. * - FlutterStandardDataTypeInt32: 32-bit signed integers
  205. * - FlutterStandardDataTypeInt64: 64-bit signed integers
  206. * - FlutterStandardDataTypeFloat64: 64-bit floats
  207. */
  208. typedef NS_ENUM(NSInteger, FlutterStandardDataType) {
  209. FlutterStandardDataTypeUInt8,
  210. FlutterStandardDataTypeInt32,
  211. FlutterStandardDataTypeInt64,
  212. FlutterStandardDataTypeFloat64,
  213. };
  214. /**
  215. * A byte buffer holding `UInt8`, `SInt32`, `SInt64`, or `Float64` values, used
  216. * with `FlutterStandardMessageCodec` and `FlutterStandardMethodCodec`.
  217. *
  218. * Two's complement encoding is used for signed integers. IEEE754
  219. * double-precision representation is used for floats. The platform's native
  220. * endianness is assumed.
  221. */
  222. FLUTTER_EXPORT
  223. @interface FlutterStandardTypedData : NSObject
  224. /**
  225. * Creates a `FlutterStandardTypedData` which interprets the specified data
  226. * as plain bytes.
  227. *
  228. * @param data the byte data.
  229. */
  230. + (instancetype)typedDataWithBytes:(NSData*)data;
  231. /**
  232. * Creates a `FlutterStandardTypedData` which interprets the specified data
  233. * as 32-bit signed integers.
  234. *
  235. * @param data the byte data. The length must be divisible by 4.
  236. */
  237. + (instancetype)typedDataWithInt32:(NSData*)data;
  238. /**
  239. * Creates a `FlutterStandardTypedData` which interprets the specified data
  240. * as 64-bit signed integers.
  241. *
  242. * @param data the byte data. The length must be divisible by 8.
  243. */
  244. + (instancetype)typedDataWithInt64:(NSData*)data;
  245. /**
  246. * Creates a `FlutterStandardTypedData` which interprets the specified data
  247. * as 64-bit floats.
  248. *
  249. * @param data the byte data. The length must be divisible by 8.
  250. */
  251. + (instancetype)typedDataWithFloat64:(NSData*)data;
  252. /**
  253. * The raw underlying data buffer.
  254. */
  255. @property(readonly, nonatomic) NSData* data;
  256. /**
  257. * The type of the encoded values.
  258. */
  259. @property(readonly, nonatomic) FlutterStandardDataType type;
  260. /**
  261. * The number of value items encoded.
  262. */
  263. @property(readonly, nonatomic) UInt32 elementCount;
  264. /**
  265. * The number of bytes used by the encoding of a single value item.
  266. */
  267. @property(readonly, nonatomic) UInt8 elementSize;
  268. @end
  269. /**
  270. * An arbitrarily large integer value, used with `FlutterStandardMessageCodec`
  271. * and `FlutterStandardMethodCodec`.
  272. */
  273. FLUTTER_EXPORT
  274. FLUTTER_UNAVAILABLE("Unavailable on 2018-08-31. Deprecated on 2018-01-09. "
  275. "FlutterStandardBigInteger was needed because the Dart 1.0 int type had no "
  276. "size limit. With Dart 2.0, the int type is a fixed-size, 64-bit signed "
  277. "integer. If you need to communicate larger integers, use NSString encoding "
  278. "instead.")
  279. @interface FlutterStandardBigInteger : NSObject
  280. @end
  281. /**
  282. * A codec for method calls and enveloped results.
  283. *
  284. * Method calls are encoded as binary messages with enough structure that the
  285. * codec can extract a method name `NSString` and an arguments `NSObject`,
  286. * possibly `nil`. These data items are used to populate a `FlutterMethodCall`.
  287. *
  288. * Result envelopes are encoded as binary messages with enough structure that
  289. * the codec can determine whether the result was successful or an error. In
  290. * the former case, the codec can extract the result `NSObject`, possibly `nil`.
  291. * In the latter case, the codec can extract an error code `NSString`, a
  292. * human-readable `NSString` error message (possibly `nil`), and a custom
  293. * error details `NSObject`, possibly `nil`. These data items are used to
  294. * populate a `FlutterError`.
  295. */
  296. FLUTTER_EXPORT
  297. @protocol FlutterMethodCodec
  298. /**
  299. * Provides access to a shared instance this codec.
  300. *
  301. * @return The shared instance.
  302. */
  303. + (instancetype)sharedInstance;
  304. /**
  305. * Encodes the specified method call into binary.
  306. *
  307. * @param methodCall The method call. The arguments value
  308. * must be supported by this codec.
  309. * @return The binary encoding.
  310. */
  311. - (NSData*)encodeMethodCall:(FlutterMethodCall*)methodCall;
  312. /**
  313. * Decodes the specified method call from binary.
  314. *
  315. * @param methodCall The method call to decode.
  316. * @return The decoded method call.
  317. */
  318. - (FlutterMethodCall*)decodeMethodCall:(NSData*)methodCall;
  319. /**
  320. * Encodes the specified successful result into binary.
  321. *
  322. * @param result The result. Must be a value supported by this codec.
  323. * @return The binary encoding.
  324. */
  325. - (NSData*)encodeSuccessEnvelope:(id _Nullable)result;
  326. /**
  327. * Encodes the specified error result into binary.
  328. *
  329. * @param error The error object. The error details value must be supported
  330. * by this codec.
  331. * @return The binary encoding.
  332. */
  333. - (NSData*)encodeErrorEnvelope:(FlutterError*)error;
  334. /**
  335. * Deccodes the specified result envelope from binary.
  336. *
  337. * @param envelope The error object.
  338. * @return The result value, if the envelope represented a successful result,
  339. * or a `FlutterError` instance, if not.
  340. */
  341. - (id _Nullable)decodeEnvelope:(NSData*)envelope;
  342. @end
  343. /**
  344. * A `FlutterMethodCodec` using UTF-8 encoded JSON method calls and result
  345. * envelopes.
  346. *
  347. * This codec is guaranteed to be compatible with the corresponding
  348. * [JSONMethodCodec](https://docs.flutter.io/flutter/services/JSONMethodCodec-class.html)
  349. * on the Dart side. These parts of the Flutter SDK are evolved synchronously.
  350. *
  351. * Values supported as methods arguments and result payloads are
  352. * those supported as top-level or leaf values by `FlutterJSONMessageCodec`.
  353. */
  354. FLUTTER_EXPORT
  355. @interface FlutterJSONMethodCodec : NSObject <FlutterMethodCodec>
  356. @end
  357. /**
  358. * A `FlutterMethodCodec` using the Flutter standard binary encoding.
  359. *
  360. * This codec is guaranteed to be compatible with the corresponding
  361. * [StandardMethodCodec](https://docs.flutter.io/flutter/services/StandardMethodCodec-class.html)
  362. * on the Dart side. These parts of the Flutter SDK are evolved synchronously.
  363. *
  364. * Values supported as method arguments and result payloads are those supported by
  365. * `FlutterStandardMessageCodec`.
  366. */
  367. FLUTTER_EXPORT
  368. @interface FlutterStandardMethodCodec : NSObject <FlutterMethodCodec>
  369. + (instancetype)codecWithReaderWriter:(FlutterStandardReaderWriter*)readerWriter;
  370. @end
  371. NS_ASSUME_NONNULL_END
  372. #endif // FLUTTER_FLUTTERCODECS_H_