@@ -594,21 +594,18 @@ func (w *ForwardedNPDU) Decode(bvlpdu Arg) error {
594594 }
595595 switch pduUserData := bvlpdu .GetPDUUserData ().(type ) {
596596 case readWriteModel.BVLCForwardedNPDUExactly :
597- switch bvlc := pduUserData .(type ) {
598- case readWriteModel.BVLCForwardedNPDU :
599- addr := bvlc .GetIp ()
600- port := bvlc .GetPort ()
601- var portArray = make ([]byte , 2 )
602- binary .BigEndian .PutUint16 (portArray , port )
603- var err error
604- address , err := NewAddress (zerolog .Nop (), append (addr , portArray ... ))
605- if err != nil {
606- return errors .Wrap (err , "error creating address" )
607- }
608- w .bvlciAddress = address
609-
610- w .setBVLC (bvlc )
597+ addr := pduUserData .GetIp ()
598+ port := pduUserData .GetPort ()
599+ var portArray = make ([]byte , 2 )
600+ binary .BigEndian .PutUint16 (portArray , port )
601+ var err error
602+ address , err := NewAddress (zerolog .Nop (), append (addr , portArray ... ))
603+ if err != nil {
604+ return errors .Wrap (err , "error creating address" )
611605 }
606+ w .bvlciAddress = address
607+
608+ w .setBVLC (pduUserData )
612609 }
613610 return nil
614611 default :
@@ -744,28 +741,31 @@ type OriginalUnicastNPDU struct {
744741
745742var _ BVLPDU = (* OriginalUnicastNPDU )(nil )
746743
747- func NewOriginalUnicastNPDU (pdu PDU , opts ... func (* OriginalUnicastNPDU )) (BVLPDU , error ) {
748- b := & OriginalUnicastNPDU {}
744+ func NewOriginalUnicastNPDU (pdu PDU , opts ... func (* OriginalUnicastNPDU )) (* OriginalUnicastNPDU , error ) {
745+ o := & OriginalUnicastNPDU {}
749746 for _ , opt := range opts {
750- opt (b )
747+ opt (o )
751748 }
752749 switch npdu := pdu .(type ) {
753750 case readWriteModel.NPDUExactly :
754- b ._BVLPDU = NewBVLPDU (readWriteModel .NewBVLCOriginalUnicastNPDU (npdu , npdu .GetLengthInBytes (context .Background ()))).(* _BVLPDU )
751+ o ._BVLPDU = NewBVLPDU (readWriteModel .NewBVLCOriginalUnicastNPDU (o .produceInnerNPDU (npdu ))).(* _BVLPDU )
752+ case nil :
753+ o ._BVLPDU = NewBVLPDU (nil ).(* _BVLPDU )
755754 default :
756755 // TODO: re-encode seems expensive... check if there is a better option (e.g. only do it on the message bridge)
757- parse , err := readWriteModel .BVLCParse (context .Background (), pdu .GetPduData ())
756+ data := pdu .GetPduData ()
757+ parse , err := readWriteModel .NPDUParse (context .Background (), data , uint16 (len (data )))
758758 if err != nil {
759759 return nil , errors .Wrap (err , "error re-encoding" )
760760 }
761- b ._BVLPDU = NewBVLPDU (parse ).(* _BVLPDU )
761+ o ._BVLPDU = NewBVLPDU (readWriteModel . NewBVLCOriginalUnicastNPDU ( o . produceInnerNPDU ( parse )) ).(* _BVLPDU )
762762 }
763763 // Do a post construct for a bit more easy initialization
764- for _ , f := range b ._postConstruct {
764+ for _ , f := range o ._postConstruct {
765765 f ()
766766 }
767- b ._postConstruct = nil
768- return b , nil
767+ o ._postConstruct = nil
768+ return o , nil
769769}
770770
771771func WithOriginalUnicastNPDUDestination (destination * Address ) func (* OriginalUnicastNPDU ) {
@@ -784,42 +784,45 @@ func WithOriginalUnicastNPDUUserData(userData spi.Message) func(*OriginalUnicast
784784 }
785785}
786786
787- func (n * OriginalUnicastNPDU ) Encode (bvlpdu Arg ) error {
787+ func (o * OriginalUnicastNPDU ) produceInnerNPDU (inNpdu readWriteModel.NPDU ) (npdu readWriteModel.NPDU , bvlcPayloadLength uint16 ) {
788+ npdu = inNpdu
789+ return
790+ }
791+
792+ func (o * OriginalUnicastNPDU ) Encode (bvlpdu Arg ) error {
788793 switch bvlpdu := bvlpdu .(type ) {
789794 case BVLPDU :
790- if err := bvlpdu .Update (n ); err != nil {
795+ if err := bvlpdu .Update (o ); err != nil {
791796 return errors .Wrap (err , "error updating BVLPDU" )
792797 }
793- bvlpdu .setBVLC (n .bvlc )
794- bvlpdu .PutData (n .getPDUData ()... )
798+
799+ bvlpdu .PutData (o .getPDUData ()... )
800+
801+ bvlpdu .setBVLC (o .bvlc )
795802 return nil
796803 default :
797804 return errors .Errorf ("invalid BVLPDU type %T" , bvlpdu )
798805 }
799806}
800807
801- func (n * OriginalUnicastNPDU ) Decode (bvlpdu Arg ) error {
808+ func (o * OriginalUnicastNPDU ) Decode (bvlpdu Arg ) error {
802809 switch bvlpdu := bvlpdu .(type ) {
803810 case BVLPDU :
804- if err := n .Update (bvlpdu ); err != nil {
811+ if err := o .Update (bvlpdu ); err != nil {
805812 return errors .Wrap (err , "error updating BVLPDU" )
806813 }
807814 switch pduUserData := bvlpdu .GetPDUUserData ().(type ) {
808- case readWriteModel.BVLCExactly :
809- switch bvlc := pduUserData .(type ) {
810- case readWriteModel.BVLCOriginalUnicastNPDU :
811- n .setBVLC (bvlc )
812- n .PutData (bvlpdu .GetPduData ()... )
813- }
815+ case readWriteModel.BVLCOriginalUnicastNPDUExactly :
816+ o .setBVLC (pduUserData )
814817 }
815818 return nil
816819 default :
817820 return errors .Errorf ("invalid BVLPDU type %T" , bvlpdu )
818821 }
819822}
820823
821- func (n * OriginalUnicastNPDU ) String () string {
822- return fmt .Sprintf ("OriginalUnicastNPDU{%s}" , n ._BVLPDU )
824+ func (o * OriginalUnicastNPDU ) String () string {
825+ return fmt .Sprintf ("OriginalUnicastNPDU{%s}" , o ._BVLPDU )
823826}
824827
825828type OriginalBroadcastNPDU struct {
@@ -829,7 +832,7 @@ type OriginalBroadcastNPDU struct {
829832 _postConstruct []func ()
830833}
831834
832- func NewOriginalBroadcastNPDU (pdu PDU , opts ... func (* OriginalBroadcastNPDU )) (BVLPDU , error ) {
835+ func NewOriginalBroadcastNPDU (pdu PDU , opts ... func (* OriginalBroadcastNPDU )) (* OriginalBroadcastNPDU , error ) {
833836 b := & OriginalBroadcastNPDU {}
834837 for _ , opt := range opts {
835838 opt (b )
0 commit comments