Appcelerator Blog

The Leading Resource for All Things Mobile

Titanium Mobile Intro Series: Buffer and Codec

0 Flares 0 Flares ×

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.Network.Socket and 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 insert() or append() methods. Their length may also be reduced by setting the length property to a smaller value or using the release() method.



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 Conversions

Numeric conversion is provided for the following types: byte, short, int, long, float, and double.


String Conversions

String conversion is provided using the following character sets: ISO_LATIN1, UTF8, UTF16, UTF16BE, and 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 Buffer.


Additional Resources

Buffer Specification: Buffer Unit Tests: buffer.js Codec Specification: Code Unit Tests: codec.js

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

Sign up for updates!

Become a mobile leader. Take the first step to scale mobile innovation throughout your enterprise.
Get in touch
computer and tablet showing Appcelerator software
Start free, grow from there.
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×