packages/grpc-native-core/src/server.js
function sendUnaryResponse(call, value, serialize, metadata, flags) {
  var end_batch = {};
  var statusMetadata = new Metadata();
  var status = {
    code: constants.status.OK,
    details: 'OK'
  };
  if (metadata) {
    statusMetadata = metadata;
  }
  var message;
  try {
    message = serialize(value);
  } catch (e) {
    e.code = constants.status.INTERNAL;
    handleError(call, e);
    return;
  }
  status.metadata = statusMetadata._getCoreRepresentation();
  if (!call.metadataSent) {
    end_batch[grpc.opType.SEND_INITIAL_METADATA] =
        (new Metadata())._getCoreRepresentation();
    call.metadataSent = true;
  }
  message.grpcWriteFlags = flags;
  end_batch[grpc.opType.SEND_MESSAGE] = message;
  end_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = status;
  call.startBatch(end_batch, function (){});
}
function sendUnaryResponse(call, value, serialize, metadata, flags) {
  var end_batch = {};
  var statusMetadata = new Metadata();
  var status = {
    code: constants.status.OK,
    details: 'OK'
  };
  if (metadata) {
    statusMetadata = metadata;
  }
  var message;
  try {
    message = serialize(value);
  } catch (e) {
    e.code = constants.status.INTERNAL;
    handleError(call, e);
    return;
  }
  status.metadata = statusMetadata._getCoreRepresentation();
  if (!call.metadataSent) {
    end_batch[grpc.opType.SEND_INITIAL_METADATA] =
        (new Metadata())._getCoreRepresentation();
    call.metadataSent = true;
  }
  message.grpcWriteFlags = flags;
  end_batch[grpc.opType.SEND_MESSAGE] = message;
  end_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = status;
  call.startBatch(end_batch, function (){});
}
function sendUnaryResponse ( call , value , serialize , metadata , flags ) { var end_batch = { } ; var statusMetadata = new Metadata ( ) ; var status = { code : constants . status . OK , details : 'OK' } ; if ( metadata ) { statusMetadata = metadata ; } var message ; try { message = serialize ( value ) ; } catch ( e ) { e . code = constants . status . INTERNAL ; handleError ( call , e ) ; return ; } status . metadata = statusMetadata . _getCoreRepresentation ( ) ; if ( ! call . metadataSent ) { end_batch [ grpc . opType . SEND_INITIAL_METADATA ] = ( new Metadata ( ) ) . _getCoreRepresentation ( ) ; call . metadataSent = true ; } message . grpcWriteFlags = flags ; end_batch [ grpc . opType . SEND_MESSAGE ] = message ; end_batch [ grpc . opType . SEND_STATUS_FROM_SERVER ] = status ; call . startBatch ( end_batch , function ( ) { } ) ; }
Send a response to a unary or client streaming call.
@private
@param {grpc.Call} call The call to respond on
@param {*} value The value to respond with
@param {grpc~serialize} serialize Serialization function for the
response
@param {grpc.Metadata=} metadata Optional trailing metadata to send with
status
@param {number=} [flags=0] Flags for modifying how the message is sent.
Send a response to a unary or client streaming call .