Commit graph

14 commits

Author SHA1 Message Date
David Hill
805ce37d31 Use the stack for most known sizes.
By using the stack for known sizes, there is less pressure on the
garbage collector.
2014-04-08 15:55:21 -04:00
David Hill
b6e6fc25db Preallocate memory for the message header in WriteMessageN and the
serialization buffer in MsgTx's TxSha().

Benchmarking shows this is slightly faster due to avoiding the extra
garbage collection in addition to less peak memory usage.

Before: BenchmarkTxShaOld  500000         5626 ns/op
After:  BenchmarkTxShaNew  500000         5457 ns/op
2014-03-20 14:33:44 -04:00
Dave Collins
ff783faf53 Add Read/WriteMessageN to return number of bytes.
This commit adds two new funtions named ReadMessageN and WriteMessageN
which return an additional paramter for the number of bytes read or written,
respectively.

It also adds tests to ensure the number of bytes read and written are the
expected values both for successful reads/writes and unsuccessful ones.

Closes #6.
2014-02-03 23:12:43 -06:00
Dave Collins
6c7f45fdb7 Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
Dave Collins
14a1da417f Enforce max block payload size of 1MB.
This commit changes MsgBlock to enforce a 1MB max payload per the spec.
Previously it was only limited to the max overall message size.  While
here, also enforce max payloads per message type (instead of only the max
overall message payload) when writing messages.
2013-05-16 09:07:04 -05:00
Dave Collins
0400d0cec3 Remove dead error check in WriteMessage.
The io.Writer.Write function always returns an error if the bytes written
is less than provided, so there is no reason to further check if the
payload length matches after a successful write.
2013-05-11 23:22:09 -05:00
Dave Collins
20bebc13a5 Convert WriteMessage errors to MessgeError type. 2013-05-11 02:29:29 -05:00
Dave Collins
2aee754448 Add test for discarding invalid large messages. 2013-05-09 22:25:21 -05:00
Dave Collins
ec6ebb3916 Add initial implementation of MessageError type.
This commit adds a new MessageError type that is intended to allow the
caller to differentiate between general io errors and and errors that
resulted from malformed messages.
2013-05-09 20:58:17 -05:00
Dave Collins
6286a39378 Combine readMessage with ReadMessage.
These functions used to be split into multiple files, but since the code
was reorganized there is no longer any reason to split them.
2013-05-09 20:16:46 -05:00
Dave Collins
970b9c129d Remove dead error check.
The io.ReadFull function always returns an error if the full payload can't
be read, so there is no reason to further check if the payload length
matches after a successful read.
2013-05-09 15:23:31 -05:00
Dave Collins
c369c0c16e Correct discardInput comment for buffer size.
This was pointed out by kaptin on IRC.
2013-05-09 13:00:00 -05:00
Dave Collins
e473fd6eb8 Add message tests for MsgAlert and MsgMemPool. 2013-05-09 00:01:29 -05:00
Dave Collins
69b27dd5d3 Initial implementation. 2013-05-08 18:58:29 -05:00