IBM
Contents Index Previous Next



Appendix A: Formats for ASCII


The ASCII encoding function, ASCII_ENCODE, encodes the SDL signal parameters and variables as ASCII characters before adding into the buffer. The output into the buffer is illustrated with a number of examples.

Braces { } are used for most data types and show where the data types start and stop. Signal parameters start and stop with braces.

Comma is used to delimit.

For more information about data types see Using SDL Data Types.

Array, CArray

Array is used to define a fixed number of elements.

Array takes two generator parameters, an index sort and a component sort.

Example 446 : Using Array

newtype A1 Array(b, Integer) endnewtype;

dcl Var_Array A1;

task Var_Array := (. 3 .);

Output to the buffer: {3,3,3}

Bag

Bag is almost the same as Powerset. The only difference is that Bag contains the same value several times. Bag can be used as an abstraction of other data types.

Bag takes one generator parameter, the item sort.

Example 447 : Using Bag

newtype B1 Bag(Integer) endnewtype;

dcl Var_Bag B1;

task Var_Bag := (. 7, 4, 7 .); 

Output to the buffer: {2:7,1:4}

Example 448 : Using Bag (old-style SDL operator code generation)

newtype B1 Bag(Integer) endnewtype;

dcl Var_Bag B1;

task Var_Bag := Incl(7, Incl(4, Incl(7, Empty))); 

Output to the buffer: {2:7,1:4}

Bit

Bit can only take two values, 0 and 1.

Example 449 : Using Bit

dcl Var_Bit Bit;

task Var_Bit := 1;

Output to the buffer: 1

Bit_String

Bit_String is used to represent a sequence of bits.

Example 450 : Using Bit_String

dcl Var_Bit Bit_String;

task Var_Bit := Mkstring(I20(1101));

Output to the buffer: `1101'

Boolean

Boolean can only take two values, False and True.

Example 451 : Using Boolean

dcl Var_Boolean Boolean;

task Var_Boolean := TRUE;

Output to the buffer: T

If Var_Boolean is set to FALSE, the output to the buffer will be F.

Character

Character is used to represent the ASCII characters.

Example 452 : Using Character

dcl Var_Character Character;

task Var_Character := `M'

Output to the buffer: M

CharStar, PId, UnionC, Userdef, VoidStar, VoidStarStar

The user has to define encoding/decoding procedures for these types, see Appendix B: User defined ASCII encoding and decoding. If no encoding/decoding procedure is defined, then there will be no output to buffer.

For threaded integrations, the PId value will be encoded/decoded by coding the memory address as an integer.

CharString, IA5String, NumericString, PrintableString, VisibleString

These string types are used to represent sequences of characters.

Example 453 : Using Charstring

dcl Var_Charstring Charstring;

task Var_Charstring := `Hello world'

Output to the buffer: `Hello world'

Choice, Union

Choice represents the ASN.1 concept CHOICE and can also be seen as a C union with an implicit tag field.

Example 454 : Using Choice

newtype C Choice
  c1 Character;
  c2 Boolean;
endnewtype;

dcl Var_Choice C;

task Var_Choice := c2:true;

Output to the buffer: {1,T}, where 1 is an implicit tag.

Duration, Time

Time is used to denote `a point in time' and Duration is used to denote `a time interval'.

A value of sort Time represents a point of time in the real world. The Time unit is usually 1 second.

Example 455 : Using Time

dcl Var_Time Time;

task Var_Time := 1;

Output to the buffer: {1,0}. The first field is seconds and the second field is nano-seconds.

Enum

Enum contains only the values enumerated in a sort.

Example 456 : Using Enum

newtype E /*Enum*/
  literals e1, e2, e3;
endnewtype;

dcl Var_Enum E;

task Var_Enum := e2;

Output to the buffer: 1

Float

Float is equivalent to float in C.

Example 457 : Using Float

dcl Var_Float Float;

task Var_Float := 3.14159;

Output to the buffer: 3.1415901e0 (always 7 decimals)

GPowerset, Object_Identifier, String

GPowerset is used as an abstraction of other data types. GPowerset takes one generator parameter, the item sort.

Object_Identifier is a sequence of Natural values.

String can be used to build lists of items of the same type. String has two generator parameters, the component sort and the name of an empty string.

Example 458 : Using GPowerset

newtype GP Powerset(Integer) endnewtype;

dcl Var_GPowerset GP;

task Var_GPowerset := Incl(7, Incl(4, Empty));

Output to the buffer: {3,4}

Object_Identifier and String are used in the same way as GPowerset.

Inherits, Syntype

Syntype and Inherits create a new type, that has the same properties as an existing type, by inheriting the type or make a syntype of the type.

Example 459 : Using Syntype

syntype newinteger = Integer endsyntype;

dcl Var_Newinteger newinteger;

task Var_Newinteger := 2

Output to the buffer: 2

Integer, LongInt, ShortInt, UnsignedInt, UnsignedLongInt, UnsignedShortInt, Natural

Integer is used to represent mathematical integers.

Natural is a syntype of Integer.

Example 460 : Using Integer

dcl Var_Integer Integer;

task Var_Integer := 1

Output to the buffer: 1

Null

The sort Null only contains one value, Null.

Example 461 : Using Null

dcl Var_Null Null;

task Var_Null := Null;

Output to the buffer: 0

Octet

Octet is used to represent eight-bit values.

Example 462 : Using Octet

dcl Var_Octet Octet;

task Var_Octet := I20(12);

Output to the buffer: 0c

Octet_String

Octet_String represents a sequence of Octet values.

Octet_String always contains an equal number of characters, since every octet takes two characters.

Example 463 : Using Octet_String

dcl Var_OctetString Octet_String;

task Var_OctetString := Mkstring(I20(12));

Output to the buffer: `0c'

ORef, Own, Ref

ORef, Own and Ref are used to define pointer types.

Example 464 : Using Ref

newtype R Ref(r1) endnewtype;

dcl Var_Ref R;

task Var_Ref := (. (. 1, 2, `Telelogic' .) .);

Output to the buffer: {{1,2,'Telelogic'}}

Powerset

Powerset takes one generator parameter, the item sort, and implements a powerset over that sort. Powerset can be used as an abstraction of other data types.

Example 465 : Using Powerset

newtype P Powerset(p1) endnewtype;

dcl Var_Powerset P;

task Var_Powerset := (. 4, 3 .);

Output to the buffer: `00110000000000000000000000000000'

The bits are an equal multiple of sizeof(unsigned long).

Example 466 : Using Powerset (old-style SDL operator code generation)

newtype P Powerset(p1) endnewtype;

dcl Var_Powerset P;

task Var_Powerset := Incl(4, Incl(3, Empty));

Output to the buffer: `00110000000000000000000000000000'

The bits are an equal multiple of sizeof(unsigned long).

Real

Real is used to represent the mathematical real values.

Example 467 : Using Real

dcl Var_Real Real;

task Var_Real := 1.0;

Output to the buffer: 1.0000000000000e0 (always 13 decimals)

SignalId

SignalId is used to describe the signal ID.

SignalId is a sequence with characters.

Example 468 : Using SignalId

dcl Var_SignalId SignalId;

task Var_SignalId := `Sig1'; 

Output to the buffer: `Sig1'

Struct

Struct can be used to make an aggregate of data that belong together.

Example 469 : Using Struct

newtype S struct
  s1 integer;
  s2 integer;
  s3 charstring;
endnewtype;

dcl Var_Struct S;

task Var_Struct := (. 1, 2, `Telelogic' .);

Output to the buffer: {1,2,'Telelogic'}


http://www.ibm.com/rational
Contents Index Previous Next