beautypg.com

Apple Newton Programmer’s Newton 2.0 (for Newton 2.0) User Manual

Page 843

background image

C H A P T E R 2 3

Endpoint Interface

Using the Endpoint Interface

23-15

termination sequence, or an array of items, any one of which will cause the input to
terminate. A termination sequence can be a single character, a string, a number, or
an array of bytes. If you don't want to look for a termination sequence, don't define
this slot.

For the

'binary

data form, you cannot use the

endSequence

slot to specify a

termination condition.

Note

Note that the system executes byte-by-byte comparisons between
the termination sequence and the input stream. To facilitate this
process, the termination sequence (or elements within the

endSequence

array) is converted to a byte or binary format to

speed the comparison. Internally, single characters are converted
to single bytes using the translation table specified by the
endpoint

encoding

slot. Numbers are converted to single bytes;

strings are converted to binary objects. An array of bytes is also
treated as a binary object. For large numbers, you must encode
your number as an array of bytes if there are significant digits
beyond the high order byte of the number.

If you want to terminate input based on a transport-level end-of-packet (EOP)
indicator, then you can set the

useEOP

slot in the

termination

frame. This slot

holds a Boolean value specifying whether or not to look for EOP indicators.
Specify this slot only if the input spec

rcvFlags

slot includes the

kPacket

flag.

Moreover, if the

rcvFlags

slot includes the

kPacket

flag and you do not specify

the

termination.useEOP

slot, the system effectively sets

useEOP

to the

default value

true

. For more information, see the following section, “Specifying

Flags for Receiving.”

It is not appropriate to specify the

termination

slot for data forms other than

'string

,

'bytes

, and

'binary

. The

'char

and

'number

data forms

automatically terminate after 1 and 4 bytes, respectively. The

'frame

data form is

terminated automatically when a complete frame has been received, and the

'template

data form terminates when the number of bytes received matches the

typelist

specification in the

target

frame.

To limit the amount of accumulated data in the input buffer, you can define a

discardAfter

slot in the input spec. You can do this only when you have not

specified a

termination.byteCount

slot for

'string

and

'bytes

data

forms. The

discardAfter

slot sets the input buffer size. If the buffer overflows,

older bytes are discarded in favor of more recently received bytes.