proxyApiBaseCodec top-level constant
String
const proxyApiBaseCodec
The base codec for ProxyApis.
All generated Dart proxy apis should use this codec or extend it. This codec
adds support to convert instances to their corresponding identifier from an
InstanceManager
and vice versa.
Implementation
const String proxyApiBaseCodec = '''
class $_proxyApiCodecName extends _PigeonCodec {
const $_proxyApiCodecName(this.instanceManager);
final $instanceManagerClassName instanceManager;
@override
void writeValue(WriteBuffer buffer, Object? value) {
if (value is $proxyApiBaseClassName) {
buffer.putUint8(128);
writeValue(buffer, instanceManager.getIdentifier(value));
} else {
super.writeValue(buffer, value);
}
}
@override
Object? readValueOfType(int type, ReadBuffer buffer) {
switch (type) {
case 128:
return instanceManager
.getInstanceWithWeakReference(readValue(buffer)! as int);
default:
return super.readValueOfType(type, buffer);
}
}
}
''';