Main Content

delegateTo

Class: matlab.net.http.io.ContentConsumer
Namespace: matlab.net.http.io

Delegate to another consumer

Syntax

[OK,bufsize] = delegateTo(consumer,delegate,header)

Description

[OK,bufsize] = delegateTo(consumer,delegate,header) prepares delegate as a consumer to process subsequent payloads based on header. consumer becomes the delegator and delegate becomes the delegate.

To prepare a delegate, delegateTo sets the following properties.

  • Set consumer.CurrentDelegate to delegate

  • Set delegate.Header to the value of header

  • Set delegate.MyDelegator to consumer

  • Set delegate properties, such as Request, Response, and URI, to the corresponding consumer properties

delegateTo then calls the delegate's initialize method. If initialize returns true, indicating that the delegate accepts the message, then delegateTo calls the start method.

Do not call delegateTo in a different delegate without telling the first delegate that the data has ended. To do this, call delegate.putData(uint8.empty).

The delegate's initialize method sets OK and its start method sets bufsize. bufsize is valid only if OK is true. If OK is false, then the start method was not called and this consumer should not invoke putData in that delegate.

Input Arguments

expand all

Content consumer, specified as a matlab.net.http.io.ContentConsumer object.

Consumer to process payload, specified as a matlab.net.http.io.ContentConsumer object or a handle to a function that returns a ContentConsumer. If a function, then it has no input arguments.

Header of the payload currently being processed, specified as a matlab.net.http.HeaderField object.

Output Arguments

expand all

Indicate whether the consumer accepts or rejects the payload of the message, returned as true or false. The default is true if the status code of the ResponseMessage is StatusCode.OK.

If OK is true, then the caller must call delegate.putData explicitly to feed data to the delegate, and, if desired, to copy any data that the delegate inserts in its Response.Body back into the caller's Response, on each call or before switching to a new delegate or at the end of the message.

If OK is false, or if the previous delegate has been told that the data has ended, then a consumer can call delegateTo to invoke another delegate for subsequent (or the same) data in the same message.

Maximum buffer size, returned as double.

Attributes

Accessprotected

Version History

Introduced in R2018a