import { jspack } from "jspack" ; import { range } from "lodash" ; export class OutgoingSSNResetRequestParam { static type = 13 ; constructor ( public requestSequence , public responseSequence , public lastTsn , public streams ) { } get type ( ) { return OutgoingSSNResetRequestParam . type ; } get bytes ( ) { const data = Buffer . from ( jspack . Pack ( "!LLL" , [ this . requestSequence , this . responseSequence , this . lastTsn , ] ) ) ; return Buffer . concat ( [ data , ... this . streams . map ( ( stream ) => Buffer . from ( jspack . Pack ( "!H" , [ stream ] ) ) ) , ] ) ; } static parse ( data ) { const [ requestSequence , responseSequence , lastTsn ] = jspack . Unpack ( "!LLL" , data ) ; const stream = range ( 12 , data . length , 2 ) . map ( ( pos ) => jspack . Unpack ( "!H" , data . slice ( pos ) ) [ 0 ] ) ; return new OutgoingSSNResetRequestParam ( requestSequence , responseSequence , lastTsn , stream ) ; } } export class StreamAddOutgoingParam { static type = 17 ; constructor ( public requestSequence , public newStreams ) { } get type ( ) { return StreamAddOutgoingParam . type ; } get bytes ( ) { return Buffer . from ( jspack . Pack ( "!LHH" , [ this . requestSequence , this . newStreams , 0 ] ) ) ; } static parse ( data ) { const [ requestSequence , newStreams ] = jspack . Unpack ( "!LHH" , data ) ; return new StreamAddOutgoingParam ( requestSequence , newStreams ) ; } } export const reconfigResult = { ReconfigResultSuccessPerformed : 1 , BadSequenceNumber : 5 , } as const ; type ReconfigResult = typeof reconfigResult [ keyof typeof reconfigResult ] ; export class ReconfigResponseParam { static type = 16 ; constructor ( public responseSequence , public result ) { } get type ( ) { return ReconfigResponseParam . type ; } get bytes ( ) { return Buffer . from ( jspack . Pack ( "!LL" , [ this . responseSequence , this . result ] ) ) ; } static parse ( data ) { const [ requestSequence , result ] = jspack . Unpack ( "!LL" , data ) ; return new ReconfigResponseParam ( requestSequence , result as ReconfigResult ) ; } } export type StreamParam = OutgoingSSNResetRequestParam | StreamAddOutgoingParam | ReconfigResponseParam ; export type StreamParamType = typeof OutgoingSSNResetRequestParam | typeof StreamAddOutgoingParam | typeof ReconfigResponseParam ; export const RECONFIG_PARAM_BY_TYPES = { 13 : OutgoingSSNResetRequestParam , 16 : ReconfigResponseParam , 17 : StreamAddOutgoingParam , } ;