Skip to content

Commit

Permalink
Merge pull request #292 from Raisul191491/main
Browse files Browse the repository at this point in the history
fix: unify receiver methods to avoid conflicts between value and pointer types
  • Loading branch information
Zerpet authored Jan 16, 2025
2 parents cc2fe97 + cf0d910 commit c2f3338
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 6 additions & 6 deletions allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package amqp091

import (
"bytes"
"fmt"
"math/big"
"strings"
)

const (
Expand Down Expand Up @@ -42,9 +42,9 @@ func newAllocator(low, high int) *allocator {
// "allocator[low..high] reserved..until"
//
// O(N) where N is high-low
func (a allocator) String() string {
b := &bytes.Buffer{}
fmt.Fprintf(b, "allocator[%d..%d]", a.low, a.high)
func (a *allocator) String() string {
var b strings.Builder
fmt.Fprintf(&b, "allocator[%d..%d]", a.low, a.high)

for low := a.low; low <= a.high; low++ {
high := low
Expand All @@ -53,9 +53,9 @@ func (a allocator) String() string {
}

if high > low+1 {
fmt.Fprintf(b, " %d..%d", low, high-1)
fmt.Fprintf(&b, " %d..%d", low, high-1)
} else if high > low {
fmt.Fprintf(b, " %d", high-1)
fmt.Fprintf(&b, " %d", high-1)
}

low = high
Expand Down
13 changes: 10 additions & 3 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"math"
"time"
Expand Down Expand Up @@ -409,17 +410,23 @@ func writeField(w io.Writer, value interface{}) (err error) {
return
}

// writeTable serializes a Table to the given writer.
// It writes each key-value pair and returns the serialized data as a longstr.
func writeTable(w io.Writer, table Table) (err error) {
var buf bytes.Buffer

for key, val := range table {
if err = writeShortstr(&buf, key); err != nil {
return
return fmt.Errorf("writing key %q: %w", key, err)
}
if err = writeField(&buf, val); err != nil {
return
return fmt.Errorf("writing value for key %q: %w", key, err)
}
}

return writeLongstr(w, buf.String())
if err := writeLongstr(w, buf.String()); err != nil {
return fmt.Errorf("writing final long string: %w", err)
}

return nil
}

0 comments on commit c2f3338

Please sign in to comment.