int RpcSerde::ParseDelimited()

in src/hbase/serde/rpc-serde.cc [53:85]


int RpcSerde::ParseDelimited(const IOBuf *buf, Message *msg) {
  if (buf == nullptr || msg == nullptr) {
    return -2;
  }

  DCHECK(!buf->isChained());

  ArrayInputStream ais{buf->data(), static_cast<int>(buf->length())};
  CodedInputStream coded_stream{&ais};

  uint32_t msg_size;

  // Try and read the varint.
  if (coded_stream.ReadVarint32(&msg_size) == false) {
    FB_LOG_EVERY_MS(ERROR, 1000) << "Unable to read a var uint32_t";
    return -3;
  }

  coded_stream.PushLimit(msg_size);
  // Parse the message.
  if (msg->MergeFromCodedStream(&coded_stream) == false) {
    FB_LOG_EVERY_MS(ERROR, 1000) << "Unable to read a protobuf message from data.";
    return -4;
  }

  // Make sure all the data was consumed.
  if (coded_stream.ConsumedEntireMessage() == false) {
    FB_LOG_EVERY_MS(ERROR, 1000) << "Orphaned data left after reading protobuf message";
    return -5;
  }

  return coded_stream.CurrentPosition();
}