Skip to content

Commit

Permalink
Address comment in PR hashicorp#260
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinlin123 committed Jul 2, 2022
1 parent dcc908e commit cc22049
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,17 @@ func makeCompoundMessages(msgs [][]byte) []*bytes.Buffer {

// Do not add to a compound message any message bigger than the max message length
// we can store.
r, w := 0, 0
for r < len(msgs) {
if len(msgs[r]) <= maxMsgLength {
smallMsgs := msgs[:0]
for _, msg := range msgs {
if len(msg) <= maxMsgLength {
// Keep it.
msgs[w] = msgs[r]
r++
w++
continue
smallMsgs = append(smallMsgs, msg)
} else {
// This message is a large one, so we send it alone.
bufs = append(bufs, bytes.NewBuffer(msg))
}

// This message is a large one, so we send it alone.
bufs = append(bufs, bytes.NewBuffer(msgs[r]))
r++
}
msgs = msgs[:w]
msgs = smallMsgs

// Group remaining messages in compound message(s).
for ; len(msgs) > maxMsgs; msgs = msgs[maxMsgs:] {
Expand Down

0 comments on commit cc22049

Please sign in to comment.