Skip to content

Commit

Permalink
fix conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Skycoder42 committed Mar 24, 2024
1 parent 502a84f commit 2cf74b0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions serverpod_json_rpc_2_shared/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.1] - 2024-03-24
### Fixed
- Add chunked conversion support to RpcStreamChannelTransformer codecs

## [1.0.0] - 2024-03-23
### Changed
- Initial release

[1.0.1]: https://github.com/Skycoder42/serverpod_json_rpc_2/compare/serverpod_json_rpc_2_shared-v1.0.0...serverpod_json_rpc_2_shared-v1.0.1
[1.0.0]: https://github.com/Skycoder42/serverpod_json_rpc_2/releases/tag/serverpod_json_rpc_2_shared-v1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,28 @@ import 'package:stream_channel/stream_channel.dart';

import 'json_rpc_2_message.dart';

class _ProxySink<TIn, TOut> implements Sink<TIn> {
final Sink<TOut> sink;
final TOut Function(TIn data) converter;

const _ProxySink(this.sink, this.converter);

@override
void add(TIn data) => sink.add(converter(data));

@override
void close() => sink.close();
}

class _RpcEncoder extends Converter<dynamic, SerializableEntity> {
const _RpcEncoder();

@override
SerializableEntity convert(dynamic input) => JsonRpc2Message(input);

@override
Sink startChunkedConversion(Sink<SerializableEntity> sink) =>
_ProxySink(sink, convert);
}

class _RpcDecoder extends Converter<SerializableEntity, dynamic> {
Expand All @@ -18,6 +35,10 @@ class _RpcDecoder extends Converter<SerializableEntity, dynamic> {
@override
dynamic convert(SerializableEntity input) =>
input is JsonRpc2Message ? input.raw : input;

@override
Sink<SerializableEntity> startChunkedConversion(Sink sink) =>
_ProxySink(sink, convert);
}

class _RpcCodec extends Codec<dynamic, SerializableEntity> {
Expand Down
2 changes: 1 addition & 1 deletion serverpod_json_rpc_2_shared/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: serverpod_json_rpc_2_shared
description: A helper package that contains shared code the for serverpod_json_rpc_2 module.
version: 1.0.0
version: 1.0.1
homepage: https://github.com/Skycoder42/serverpod_json_rpc_2

environment:
Expand Down

0 comments on commit 2cf74b0

Please sign in to comment.