29 lines
1.2 KiB
Go
29 lines
1.2 KiB
Go
package bus
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/novox/mesh-tools/node-tools/internal/wire"
|
|
)
|
|
|
|
// An answer larger than the bus carries in one message (novox/hq issue 314).
|
|
//
|
|
// The bus carries one message of at most its max_payload, and the client library refuses a larger one
|
|
// before it leaves the process that sent it. A module's answer too large is refused here, loudly, in a
|
|
// message that fits, so its caller reads why instead of waiting out RequestTimeout.
|
|
|
|
// fits is an answer the bus can carry: the answer itself, or — when it is larger than one message —
|
|
// an error that says so, which is.
|
|
func (c *Conn) fits(subject string, body []byte) []byte {
|
|
limit := c.nc.MaxPayload()
|
|
if limit <= 0 || int64(len(body)) <= limit {
|
|
return body
|
|
}
|
|
c.Logf("[mesh-tools] the answer on %s is %d bytes, more than the bus carries in one message (%d): its caller "+
|
|
"is told so instead", subject, len(body), limit)
|
|
said, _ := wire.Marshal(reply{Node: c.node, Error: fmt.Sprintf("the answer is %d bytes, more than the bus "+
|
|
"carries in one message (%d), so it was not sent: ask for less — a narrower question, a shorter window, "+
|
|
"fewer lines", len(body), limit)})
|
|
return said
|
|
}
|