Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions Sources/RSocketCore/Extensions/RequestExamples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

/**
This file contains examples of the `Coder`, `Encoder` and `Decoder` API.
All those examples should eventually be moved to documentation and/or tests.
This file contains examples of the `Coder`, `Encoder` and `Decoder` API.
All those examples should eventually be moved to documentation and/or tests.
For now they are here to make sure we do not accidentally break any public API during development.
*/

Expand Down Expand Up @@ -51,8 +51,8 @@ fileprivate enum Requests {
.encodeStaticMetadata("metrics", using: RoutingEncoder())
.encodeData(using: JSONDataEncoder(type: Metrics.self))
}
/// Same as above but gives the call site the option to encode additional dynamic metadata
static let metrics3 = FireAndForget<([CompositeMetadata], Metrics)> {
/// Same as above but gives the call site the option to encode additional dynamic metadata
static let metrics3 = FireAndForget<((),Metrics)> {
Encoder()
.useCompositeMetadata()
.encodeStaticMetadata("metrics", using: RoutingEncoder())
Expand All @@ -67,7 +67,6 @@ fileprivate enum Requests {
static let priceRequest1 = RequestResponse<String, Double> {
Encoder()
.useCompositeMetadata()
.encodeStaticMetadata("price", using: RoutingEncoder())
.encodeStaticMetadata([.applicationJson], using: AcceptableDataMIMETypeEncoder())
.encodeData(using: JSONDataEncoder(type: Stock.self))
.mapData(Stock.init(isin:))
Expand All @@ -76,7 +75,7 @@ fileprivate enum Requests {
.decodeData(using: JSONDataDecoder(type: Price.self))
.mapData(\.price)
}
/// Same as above but we do no longer need to explicitly encode the Acceptable Data MIME Type.
/// Same as above but we do no longer need to explicitly encode the Acceptable Data MIME Type.
/// This is because we use the `Coder` convenience API which is a thin wrapper around an `Encoder` and `Decoder`.
/// `Coder.decodeData(decoder:)` takes multiple decoders and automatically encodes their MIME Type as Acceptable Data MIME Type Metadata.
/// It also looks for Data MIME Type and the Connection MIME Type and choose the correct decoder during decoding.
Expand All @@ -85,23 +84,21 @@ fileprivate enum Requests {
.useCompositeMetadata()
.encodeStaticMetadata("price", using: RoutingEncoder())
.encodeData(using: JSONDataEncoder(type: ISIN.self).map(ISIN.init(isin:)))
.decodeData {
JSONDataDecoder(type: Price.self).map(\.price)
}
.decodeData (using:JSONDataDecoder(type: Price.self).map(\.price))
}

/// Same as above but this time the encoder also encodes the MIME Type of the data as Date MIME Type Metadata because we use the `encodeData(encoder:)` method which can take multiple encoders. The call side need to specify which encoding it wants to use.
static let priceRequest3 = RequestResponse<(MIMEType, String), Double> {
static let priceRequest3 = RequestResponse<(String), Double> {
Coder()
.useCompositeMetadata()
.encodeStaticMetadata("price", using: RoutingEncoder())
.encodeData {
.encodeData (using:
JSONDataEncoder(type: ISIN.self).map(ISIN.init(isin:))
}
.decodeData {
)
.decodeData (using:
JSONDataDecoder(type: Price.self)
.map(\.price)
}
)
}
/// Works with `RequestStream` and `RequestChannel` too
static let priceStream1 = RequestStream<ISIN, Price> {
Expand Down
Loading