blob: 50d5dca573a46d96b90184ad9532d69708a51a98 [file] [log] [blame]
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'message_grouper.dart';
import 'message_grouper_state.dart';
/// Groups bytes in delimited proto format into the bytes for each message.
class SyncMessageGrouper implements MessageGrouper {
final _state = new MessageGrouperState();
final Stdin _stdin;
/// Blocks until the next full message is received, and then returns it.
/// Returns null at end of file.
List<int> get next {
List<int> message;
while (message == null) {
var nextByte = _stdin.readByteSync();
if (nextByte == -1) return null;
message = _state.handleInput(nextByte);
return message;