Remove proxyBehavior, in favor of "session" construct

Sessions do not mandate the existence of client nor server unlike
proxyBehavior, instead closures/thunks are used to acquire proxying
behaviors.  The result is more generality with less code for known use
cases.

This was motivated by trying write another, non-proxy FEBE-speaking
backend.

Signed-off-by: Daniel Farina <daniel@heroku.com>
Better not-quite-enums

Signed-off-by: Dan Farina <drfarina@acm.org>
Remove dependency on ReadBytes interface

Callers -- of which there is only one -- will just have to implement
their own version, or break out a utility procedure.  This just makes
life for interface implementations somewhat simpler.

Signed-off-by: Dan Farina <drfarina@acm.org>
Make Message an interface

This is pursuant to supporting more complex message-creation behavior
for reasons of efficiency.  The old concrete Message implementation
has been embellished to create "hybridMessage," which is for
supporting large messages without full in-memory buffering, although
for now both it and the .Next() method of MessageStreams have not yet
been taught how to do that.

Signed-off-by: Dan Farina <drfarina@acm.org>
Error propagation and two entry states for message handling

Before this, various utility functions would silently fail.  Now they
propagate errors instead.  In addition, the slick mechanism used to
try to disambiguate whether the caller expected a startup packet from
the message stream or not is now gone.

Signed-off-by: Dan Farina <drfarina@acm.org>
Buffered, low-GC message handling

The new big bottleneck is eliminating memory copies.

This introduces some regressions in stream error handling and needs
more testing, but it's functional for some of pgbench and much, much
faster.

Signed-off-by: Daniel Farina <daniel@heroku.com>
Implement WriteTo interface on Message

This makes it easier to test by encoding Message into a bytes.Buffer,
for instance.

Signed-off-by: Daniel Farina <daniel@heroku.com>
Fix bug in InitMsgFromBytes

It was just wrong before.  Manifestation should be a nil pointer
dereference.

Signed-off-by: Daniel Farina <daniel@heroku.com>
Unit Tests: initial commit

the old femebe_test was just an abuse of the testing infrastructure to
run code.  However, it makes 'go test' fail spuriously, so remove it.

In addition, add a new, legitimate unit test has been added.

Signed-off-by: Daniel Farina <daniel@heroku.com>
Change FailNow to Fatal

Fatal is more useful because it prints the line number.

Signed-off-by: Dan Farina <drfarina@acm.org>
Add testing of promise messages

Intended to exercise when messages are fragmented across a buffered
boundary.

Signed-off-by: Dan Farina <drfarina@acm.org>
Add incomplete message-header test

Signed-off-by: Dan Farina <drfarina@acm.org>
Improve buffered error handling

Now might actually work, and returns the last error seen repeatedly
rather than switching to the errors.New there before.

Tested with some EOF situations.

Signed-off-by: Dan Farina <drfarina@acm.org>
Remove hasFuture kludge

Now that errors are being recorded in the MessageStream struct, rely
on that to determine if one should terminate the byte-seeking loop.

Signed-off-by: Dan Farina <drfarina@acm.org>
Add specialized parser for bytes.Buffer on Uint32

This was one of the hot spots in the code, but the common case is
definitely taking a byte buffer: this makes it cheaper.

As a target of opportunity, adjust buffer parsing naming conventions
to be more like Go's library version.

Signed-off-by: Dan Farina <drfarina@acm.org>
Combine Reader and Writer into ReadWriteCloser

This regresses the buffering behavior of proxying, which will make
things slow until it is re-enabled.

Signed-off-by: Daniel Farina <daniel@heroku.com>
Fixing WriteCString
Constants!
Changing startup message byte writing mechanism.
Properly dealing with CancelRequest messages.