From d61b730cb7892f7405fecf40adfb348139053cd7 Mon Sep 17 00:00:00 2001 From: Shlomi Amit Date: Sat, 29 Jun 2024 12:10:11 +0300 Subject: [PATCH] Lint fixes --- application_packet.go | 5 +---- application_packet_test.go | 15 +++++++++------ errors.go | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/application_packet.go b/application_packet.go index ec70333..ef9ca7a 100644 --- a/application_packet.go +++ b/application_packet.go @@ -45,7 +45,7 @@ func (a ApplicationDefined) Marshal() ([]byte, error) { } rawPacket := make([]byte, packetSize) - copy(rawPacket[:], headerBytes) + copy(rawPacket, headerBytes) binary.BigEndian.PutUint32(rawPacket[4:8], a.SSRC) copy(rawPacket[8:12], a.Name[:]) copy(rawPacket[12:], a.Data) @@ -62,7 +62,6 @@ func (a ApplicationDefined) Marshal() ([]byte, error) { // Unmarshal parses the given raw packet into an AppPacket, handling padding. func (a *ApplicationDefined) Unmarshal(rawPacket []byte) error { - /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 @@ -114,7 +113,5 @@ func (a *ApplicationDefined) MarshalSize() int { if paddingSize == 4 { paddingSize = 0 } - return 12 + dataLength + paddingSize - } diff --git a/application_packet_test.go b/application_packet_test.go index 4204573..5ed0cb3 100644 --- a/application_packet_test.go +++ b/application_packet_test.go @@ -33,7 +33,8 @@ func TestTApplicationPacketUnmarshal(t *testing.T) { Name: [4]byte{0x53, 0x55, 0x49, 0x54}, Data: []byte{0x41, 0x42, 0x43, 0x44}, }, - }, { + }, + { Name: "validWithPadding", Data: []byte{ // Application Packet Type + Length(0x0002) (0xA0 has padding bit set) @@ -52,7 +53,8 @@ func TestTApplicationPacketUnmarshal(t *testing.T) { Name: [4]byte{0x53, 0x55, 0x49, 0x54}, Data: []byte{0x41, 0x42, 0x43, 0x44, 0x45}, }, - }, { + }, + { Name: "invalidAppPacketLengthField", Data: []byte{ // Application Packet Type + invalid Length(0x00FF) @@ -65,7 +67,8 @@ func TestTApplicationPacketUnmarshal(t *testing.T) { 0x41, 0x42, 0x43, 0x44, }, WantError: errAppDefinedInvalidLength, - }, { + }, + { Name: "invalidPacketLengthTooShort", Data: []byte{ // Application Packet Type + Length(0x0002). Total packet length is less than 12 bytes @@ -119,9 +122,9 @@ func TestTApplicationPacketUnmarshal(t *testing.T) { if apk.SSRC != 0x4baae1ab { t.Fatalf("SSRC %q result: got packet SSRC %x instead of %x", test.Name, apk.SSRC, 0x4baae1ab) } - } } + func TestTApplicationPacketMarshal(t *testing.T) { for _, test := range []struct { Name string @@ -185,12 +188,12 @@ func TestTApplicationPacketMarshal(t *testing.T) { continue } - // Check for expected succesful result + // Check for expected successful result if got, want := rawPacket, test.Want; !reflect.DeepEqual(got, want) { t.Fatalf("Unmarshal %q result: got %v, want %v", test.Name, got, want) } - // Check if MarshalSize() is matching the marshalled bytes + // Check if MarshalSize() is matching the marshaled bytes marshalSize := test.Packet.MarshalSize() if marshalSize != len(rawPacket) { t.Fatalf("MarshalSize %q result: got %d bytes instead of %d", test.Name, len(rawPacket), marshalSize) diff --git a/errors.go b/errors.go index 4334572..a2f36ce 100644 --- a/errors.go +++ b/errors.go @@ -37,5 +37,4 @@ var ( errBadReadParameter = errors.New("rtcp: cannot read into non-pointer") errAppDefinedInvalidLength = errors.New("rtcp: application defined packet type invalid length") errAppDefinedDataTooLarge = errors.New("rtcp: application defined packet data is too large") - )