Welcome to the first in a series of articles about some of the new features we’re releasing in Titanium Mobile 1.7.0. These articles are introductory in scope and provide links to additional resources related to the APIs to help give you a broader understanding of the feature.
This article is concerned with Titanium
Buffer, a container for bytes, and
Titanium.Codec, methods to convert to and from binary data. These two API additions are primarily used in conjunction with
Titanium.Stream which will be introduced over the next few days.
Buffers are created from the Titanium module with
Titanium.createBuffer(). Buffers are similar to byte arrays in other programming languages but have the ability to be resized. Buffers may be grown by setting the
length property to a larger value, or when using the
append() methods. Their length may also be reduced by setting the
length property to a smaller value or using the
Applications that read and manipulate binary data also require the ability to encode and decode that data into easily recognizable primitive types. The
Titanium.Codec module addresses this issue by exposing encoding, decoding, and byte order operations. The Codec module supports conversion of two basic primitive types: Numbers and Strings.
Numeric conversion is provided for the following types:
String conversion is provided using the following character sets:
UTF16LE. Titanium.Codec also suports both Big Endian and Little Endian byte ordering.
Buffer Creation With Encode
Titanium.createBuffer() has convenience options for creating a buffer from existing data and encoding it into the requested representation in the returned