-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SerializationWriterProxyFactory
- Loading branch information
1 parent
46133cf
commit 038091e
Showing
3 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
lib/src/serialization/serialization_writer_proxy_factory.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
part of '../../kiota_abstractions.dart'; | ||
|
||
abstract class SerializationWriterProxyFactory | ||
implements SerializationWriterFactory { | ||
SerializationWriterProxyFactory({ | ||
required SerializationWriterFactory concrete, | ||
ParsableHook? onBefore, | ||
ParsableHook? onAfter, | ||
void Function(Parsable, SerializationWriter)? onStart, | ||
}) : _concrete = concrete, | ||
_onBefore = onBefore, | ||
_onAfter = onAfter, | ||
_onStart = onStart; | ||
|
||
final SerializationWriterFactory _concrete; | ||
final ParsableHook? _onBefore; | ||
final ParsableHook? _onAfter; | ||
final void Function(Parsable, SerializationWriter)? _onStart; | ||
|
||
@override | ||
String get validContentType => _concrete.validContentType; | ||
|
||
@override | ||
SerializationWriter getSerializationWriter(String contentType) { | ||
final writer = _concrete.getSerializationWriter(contentType); | ||
|
||
final originalBefore = writer.onBeforeObjectSerialization; | ||
writer.onBeforeObjectSerialization = (p) { | ||
_onBefore?.call(p); | ||
originalBefore?.call(p); | ||
}; | ||
|
||
final originalAfter = writer.onAfterObjectSerialization; | ||
writer.onAfterObjectSerialization = (p) { | ||
_onAfter?.call(p); | ||
originalAfter?.call(p); | ||
}; | ||
|
||
final originalStart = writer.onStartObjectSerialization; | ||
writer.onStartObjectSerialization = (p, w) { | ||
_onStart?.call(p, w); | ||
originalStart?.call(p, w); | ||
}; | ||
|
||
return writer; | ||
} | ||
} |