anchor.diff:      _messageStreamController.close();
     }
   }
  +
  +/// A buffer of fixed length.
  +class _FixedBuffer {
  +  final Uint8List bytes;
  +
  +  /// The offset in [bytes].
  +  int _offset = 0;
  +
  +  _FixedBuffer(int length) : bytes = new Uint8List(length);
  +
  +  /// Return `true` when the required number of bytes added.
  +  bool get isReady => _offset == bytes.length;
  +
  +  int operator [](int index) => bytes[index];
  +
  +  void addByte(int byte) {
  +    bytes[_offset++] = byte;
  +  }
  +
  +  /// Reset the number of added bytes to zero.
  +  void reset() {
  +    _offset = 0;
  +  }
  +}
  
positive.code: // BSD-style license that can be found in the LICENSE file.
  
  import 'dart:async';
  import 'dart:math';
  import 'dart:typed_data';
  
  /// Collects messages from an input stream of bytes.
  
negative.code:   }
  
    void _handleBytes(List<int> bytes, [int offset = 0]) {
      final _FixedBuffer? messageBuffer = _messageBuffer;
      if (messageBuffer == null) {
        while (offset < bytes.length && !_lengthBuffer.isReady) {
          _lengthBuffer.addByte(bytes[offset++]);
        }
        if (_lengthBuffer.isReady) {
          int length = _lengthBuffer[0] << 24 |
              _lengthBuffer[1] << 16 |
              _lengthBuffer[2] << 8 |
              _lengthBuffer[3];
          // Reset the length reading state.
          _lengthBuffer.reset();
          // Switch to the message payload reading state.
          _messageBuffer = new _FixedBuffer(length);
          _handleBytes(bytes, offset);
        } else {
          // Continue reading the length.
          return;
        }
      } else {
        // Read the data from `bytes`.
        while (offset < bytes.length && !messageBuffer.isReady) {
          messageBuffer.addByte(bytes[offset++]);
        }
  
        // If we completed a message, add it to the output stream.
        if (messageBuffer.isReady) {
          _messageStreamController.add(messageBuffer.bytes);
          // Switch to the length reading state.
          _messageBuffer = null;
          _handleBytes(bytes, offset);
        }
      }
  