third_party/libprocess/include/stout/protobuf.hpp
// Write out the given protobuf to the specified file descriptor by
// first writing out the length of the protobuf followed by the
// contents.
Write out the given protobuf to the specified file descriptor by
first writing out the length of the protobuf followed by the
contents.
Write out the given protobuf to the specified file descriptor by first writing out the length of the protobuf followed by the contents .
inline Try<bool> write(int fd, const google::protobuf::Message& message)
{
  if (!message.IsInitialized()) {
    LOG(ERROR) << "Failed to write protocol buffer to file, "
               << "protocol buffer is not initialized!";
    return false;
  }
  uint32_t size = message.ByteSize();
  ssize_t length = ::write(fd, (void*) &size, sizeof(size));
  if (length == -1) {
    std::string error = strerror(errno);
    error = error + " (" + __FILE__ + ":" + stringify(__LINE__) + ")";
    return Try<bool>::error(error);
  }
  CHECK(length != 0);
  CHECK(length == sizeof(size)); 
  return message.SerializeToFileDescriptor(fd);
}
inline Try < bool > write ( int fd , const google :: protobuf :: Message & message ) { if ( ! message . IsInitialized ( ) ) { LOG ( ERROR ) << " " << " " ; return false ; } uint32_t size = message . ByteSize ( ) ; ssize_t length = :: write ( fd , ( void * ) & size , sizeof ( size ) ) ; if ( length == -1 ) { std :: string error = strerror ( errno ) ; error = error + " " + __FILE__ + " " + stringify ( __LINE__ ) + " " ; return Try < bool > :: error ( error ) ; } CHECK ( length != 0 ) ; CHECK ( length == sizeof ( size ) ) ; return message . SerializeToFileDescriptor ( fd ) ; }
Write out the given protobuf to the specified file descriptor by
first writing out the length of the protobuf followed by the
contents.
Write out the given protobuf to the specified file descriptor by first writing out the length of the protobuf followed by the contents .
// TODO(benh): Handle a non-blocking fd?