diff --git a/metadapta.go b/metadapta.go index 20074b3..503e8af 100644 --- a/metadapta.go +++ b/metadapta.go @@ -103,7 +103,7 @@ func (this *a) unlistTransactionSafe(id int64) { func (this *a) sendMessageSafe(trans int64, method uint16, data []byte) error { this.sendLock.Lock() defer this.sendLock.Unlock() - return encodeMessageA(this.underlying, trans, method, data) + return encodeMessageA(this.underlying, this.sizeLimit, trans, method, data) } func (this *a) receive() { @@ -269,7 +269,16 @@ type incomingMessage struct { payload []byte } -func encodeMessageA(writer io.Writer, trans int64, method uint16, data []byte) error { +func encodeMessageA( + writer io.Writer, + sizeLimit int64, + trans int64, + method uint16, + data []byte, +) error { + if int64(len(data)) > sizeLimit { + return ErrPayloadTooLarge + } buffer := make([]byte, 18 + len(data)) tape.EncodeI64(buffer[:8], trans) tape.EncodeI16(buffer[8:10], method)