@@ -594,21 +594,18 @@ func (w *ForwardedNPDU) Decode(bvlpdu Arg) error {
594
594
}
595
595
switch pduUserData := bvlpdu .GetPDUUserData ().(type ) {
596
596
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" )
611
605
}
606
+ w .bvlciAddress = address
607
+
608
+ w .setBVLC (pduUserData )
612
609
}
613
610
return nil
614
611
default :
@@ -744,28 +741,31 @@ type OriginalUnicastNPDU struct {
744
741
745
742
var _ BVLPDU = (* OriginalUnicastNPDU )(nil )
746
743
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 {}
749
746
for _ , opt := range opts {
750
- opt (b )
747
+ opt (o )
751
748
}
752
749
switch npdu := pdu .(type ) {
753
750
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 )
755
754
default :
756
755
// 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 )))
758
758
if err != nil {
759
759
return nil , errors .Wrap (err , "error re-encoding" )
760
760
}
761
- b ._BVLPDU = NewBVLPDU (parse ).(* _BVLPDU )
761
+ o ._BVLPDU = NewBVLPDU (readWriteModel . NewBVLCOriginalUnicastNPDU ( o . produceInnerNPDU ( parse )) ).(* _BVLPDU )
762
762
}
763
763
// Do a post construct for a bit more easy initialization
764
- for _ , f := range b ._postConstruct {
764
+ for _ , f := range o ._postConstruct {
765
765
f ()
766
766
}
767
- b ._postConstruct = nil
768
- return b , nil
767
+ o ._postConstruct = nil
768
+ return o , nil
769
769
}
770
770
771
771
func WithOriginalUnicastNPDUDestination (destination * Address ) func (* OriginalUnicastNPDU ) {
@@ -784,42 +784,45 @@ func WithOriginalUnicastNPDUUserData(userData spi.Message) func(*OriginalUnicast
784
784
}
785
785
}
786
786
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 {
788
793
switch bvlpdu := bvlpdu .(type ) {
789
794
case BVLPDU :
790
- if err := bvlpdu .Update (n ); err != nil {
795
+ if err := bvlpdu .Update (o ); err != nil {
791
796
return errors .Wrap (err , "error updating BVLPDU" )
792
797
}
793
- bvlpdu .setBVLC (n .bvlc )
794
- bvlpdu .PutData (n .getPDUData ()... )
798
+
799
+ bvlpdu .PutData (o .getPDUData ()... )
800
+
801
+ bvlpdu .setBVLC (o .bvlc )
795
802
return nil
796
803
default :
797
804
return errors .Errorf ("invalid BVLPDU type %T" , bvlpdu )
798
805
}
799
806
}
800
807
801
- func (n * OriginalUnicastNPDU ) Decode (bvlpdu Arg ) error {
808
+ func (o * OriginalUnicastNPDU ) Decode (bvlpdu Arg ) error {
802
809
switch bvlpdu := bvlpdu .(type ) {
803
810
case BVLPDU :
804
- if err := n .Update (bvlpdu ); err != nil {
811
+ if err := o .Update (bvlpdu ); err != nil {
805
812
return errors .Wrap (err , "error updating BVLPDU" )
806
813
}
807
814
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 )
814
817
}
815
818
return nil
816
819
default :
817
820
return errors .Errorf ("invalid BVLPDU type %T" , bvlpdu )
818
821
}
819
822
}
820
823
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 )
823
826
}
824
827
825
828
type OriginalBroadcastNPDU struct {
@@ -829,7 +832,7 @@ type OriginalBroadcastNPDU struct {
829
832
_postConstruct []func ()
830
833
}
831
834
832
- func NewOriginalBroadcastNPDU (pdu PDU , opts ... func (* OriginalBroadcastNPDU )) (BVLPDU , error ) {
835
+ func NewOriginalBroadcastNPDU (pdu PDU , opts ... func (* OriginalBroadcastNPDU )) (* OriginalBroadcastNPDU , error ) {
833
836
b := & OriginalBroadcastNPDU {}
834
837
for _ , opt := range opts {
835
838
opt (b )
0 commit comments