11import { Logger , MessageMetadata } from '../../logging' ;
22import { TelemetryInfo } from '../../tracing' ;
33import {
4+ EncodedTransportMessage ,
45 OpaqueTransportMessage ,
56 OpaqueTransportMessageSchema ,
67 PartialTransportMessage ,
78 ProtocolVersion ,
89 TransportClientId ,
9- TransportMessage ,
1010} from '../message' ;
1111import { Value } from '@sinclair/typebox/value' ;
1212import { Codec } from '../../codec' ;
@@ -204,7 +204,7 @@ export interface IdentifiedSessionProps extends CommonSessionProps {
204204 to : TransportClientId ;
205205 seq : number ;
206206 ack : number ;
207- sendBuffer : Array < OpaqueTransportMessage > ;
207+ sendBuffer : Array < EncodedTransportMessage > ;
208208 telemetry : TelemetryInfo ;
209209 protocolVersion : ProtocolVersion ;
210210}
@@ -224,7 +224,7 @@ export abstract class IdentifiedSession extends CommonSession {
224224 * Number of unique messages we've received this session (excluding handshake)
225225 */
226226 ack : number ;
227- sendBuffer : Array < OpaqueTransportMessage > ;
227+ sendBuffer : Array < EncodedTransportMessage > ;
228228
229229 constructor ( props : IdentifiedSessionProps ) {
230230 const { id, to, seq, ack, sendBuffer, telemetry, log, protocolVersion } =
@@ -258,9 +258,9 @@ export abstract class IdentifiedSession extends CommonSession {
258258 return metadata ;
259259 }
260260
261- constructMsg < Payload > (
261+ encodeMsg < Payload > (
262262 partialMsg : PartialTransportMessage < Payload > ,
263- ) : TransportMessage < Payload > {
263+ ) : EncodedTransportMessage {
264264 const msg = {
265265 ...partialMsg ,
266266 id : generateId ( ) ,
@@ -270,19 +270,24 @@ export abstract class IdentifiedSession extends CommonSession {
270270 ack : this . ack ,
271271 } ;
272272
273+ const encodedMsg = {
274+ id : msg . id ,
275+ seq : msg . seq ,
276+ data : this . options . codec . toBuffer ( msg ) ,
277+ } ;
278+
273279 this . seq ++ ;
274280
275- return msg ;
281+ return encodedMsg ;
276282 }
277283
278284 nextSeq ( ) : number {
279285 return this . sendBuffer . length > 0 ? this . sendBuffer [ 0 ] . seq : this . seq ;
280286 }
281287
282288 send ( msg : PartialTransportMessage ) : string {
283- const constructedMsg = this . constructMsg ( msg ) ;
289+ const constructedMsg = this . encodeMsg ( msg ) ;
284290 this . sendBuffer . push ( constructedMsg ) ;
285-
286291 return constructedMsg . id ;
287292 }
288293
0 commit comments