Siebel eScript Language Reference > Siebel eScript Commands > Buffer Objects in Siebel eScript >

The Buffer Constructor in Siebel eScript


To create a Buffer object, use one of the following syntax forms.

Syntax A

new Buffer([size] [, unicode] [, bigEndian]);

Parameter
Description

size

The size of the new buffer to be created

unicode

True if the buffer is to be created as a Unicode string, otherwise, false; default is false

bigEndian

True if the largest data values are stored in the most significant byte; false if the largest data values are stored in the least significant byte; default is true

Usage

If size is specified, then the new buffer is created with the specified size and filled with null bytes. If no size is specified, then the buffer is created with a size of 0, although it can be extended dynamically later.

The unicode parameter is an optional Boolean flag describing the initial state of the unicode flag of the object. Similarly, bigEndian describes the initial state of the bigEndian parameter of the buffer.

Syntax B

new Buffer( string [, unicode] [, bigEndian] );

Usage

This syntax creates a new Buffer object from the string provided. If the string parameter is a Unicode string (if Unicode is enabled within the application), then the buffer is created as a Unicode string.

This behavior can be overridden by specifying true or false with the optional Boolean unicode parameter. If this parameter is set to false, then the buffer is created as an ASCII string, regardless of whether the original string was in Unicode or not.

Similarly, specifying true makes sure that the buffer is created as a Unicode string. The size of the buffer is the length of the string (twice the length if it is Unicode). This constructor does not add a terminating null byte at the end of the string.

Syntax C

new Buffer(buffer [, unicode] [, bigEndian]);

Parameter
Description

buffer

The Buffer object from which the new buffer is to be created

unicode

True if the buffer is to be created as a Unicode string, otherwise, false; default is the Unicode status of the underlying Siebel eScript engine

bigEndian

True if the largest data values are stored in the most significant byte; false if the largest data values are stored in the least significant byte; default is true

Usage

A line of code following this syntax creates a new Buffer object from the buffer provided. The contents of the buffer are copied as-is into the new Buffer object. The unicode and bigEndian parameters do not affect this conversion, although they do set the relevant flags for future use.

Syntax D

new Buffer(bufferobject);

Parameter
Description

bufferobject

The Buffer object from which the new buffer is to be created

Usage

A line of code following this syntax creates a new Buffer object from another Buffer object. Everything is duplicated exactly from the other bufferObject, including the cursor location, size, and data.

Example

The following example shows creation of new Buffer objects.

function BufferConstruct()
{
   TheApplication().TraceOn("c:\\temp\\BufferTrace.doc","Allocation","All");
   // Create empty buffer with size 100
   var buff1 = new Buffer(100 , true , true);
   // Create a buffer from string
   var buff2 = new Buffer("This is a buffer String constructor example", true);
   // Create buffer from buffer
   var buff3 = new Buffer(buff2,false);
   try
   {
      with(buff1)
      {
         // Add values from 0-99 to the buffer
         for(var i=0;i<size;i++)
         {
            putValue(i);
         }
         var val = "";
         cursor=0;
         // Read the buffer values into variable
         for(var i=0;i<size;i++)
         {
            val += getValue(1)+" ";
         }
         // Trace the buffer value
         TheApplication().Trace("Buffer 1 value: "+val);
      }
      with(buff2)
      {
         // Trace buffer 2
         TheApplication().Trace("Buffer 2 value: "+getString());
      }
      // Trace buffer 3
      with(buff3)
      {
         TheApplication().Trace("Buffer 3 value: "+getString());
      }
   }
   catch(e)
   {
      TheApplication().Trace(e.toString());
   }
}

Siebel eScript Language Reference