To represent related values, LDS has an implementation of Struct. A struct definition contains a list of root level property names and the types. Supported types are:
UInt8
UInt32
UInt16
Float32
Float64
String
Here's an example definition of Struct
Person = LDS.Struct "Person",
{property: 'name', type: LDS.Types.String, length: 1}
{property: 'age', type: LDS.Types.Int16}
{property: 'values', type: LDS.Types.Int32, length: 5}
{property: 'address', type: LDS.Types.String, length: 5}
- property 'name' is a String
- property 'age' is a 16-bit integer
- property 'values' is a fixed-length array of 32-bit integer
- property 'address' is a fixed-length array of Strings
p = new Person
p.setName 'Bob'
p.setAge 23
p.setValues [1, 2, 3]
p.setAddress ["No. 123", "Street 1", "Street 2", ""]
p.setAddress "index-3-new", 3
str = new LDS.String "4-fourth"
p.setAddress str, 4, on
str.release()
If you are to create LDS.String, you must release those string objects by calling release()
method. In most cases you will not create LDS.Strings. But you might create Hashtables and ArrayLists having LDS.Strings in their Structs. In such cases you'll have to call release()
method of those objects once you are done working with that data structure.
console.log p.get()
console.log p.getAddress 2
str = p.getAddress 0, on
console.log str.toString()
str.release()
p2 = new Person
p2.copyFrom p
console.log p2.get()
Struct.copyFrom()
method copies the content from source struct buffer area to target struct buffer area. LDS.Strings are copied by reference.
- Reference counts to existing strings in source are decremented by 1.
- Reference counts to strings in target are incremented by 1.