Map Property
Represents a map from keys to values.
See properties page to see which property types it can contain for as key and as value. Property definitions need to be required and values can thus not be null.
- Kotlin Definition:
MapDefinition<K, V>- K for type of key definition
- V for type of value definition
- Kotlin Value:
Map - Maryk Yaml Definition:
Map
Usage options
Section titled “Usage options”- Value
Validation Options
Section titled “Validation Options”required- default truefinal- default falseminSize- default unset. Minimum size of mapmaxSize- default unset. Maximum size of map
Other options
Section titled “Other options”default- the default value to be used if value was not set.keyDefinition- definition of keys contained in mapvalueDefinition- definition of values contained in map
Examples
Section titled “Examples”Example of a Map property definition for use within a Model
val mappedNames by map( index = 1u, required = false, final = true, keyDefinition = NumberDefinition(type = UInt32), valueDefinition = StringDefinition())Example of a separate Map property definition
val def = MapDefinition( required = false, final = true, keyDefinition = NumberDefinition(type = UInt32), valueDefinition = StringDefinition())Operations
Section titled “Operations”Use Change on an at(key) reference to add or replace a map entry. Set that
entry to null to remove it. There is no separate MapChange request. Use a
Check to compare the complete map or an individual entry before changing it.
For a map with UInt32 keys and string values:
Change( Model.ref { mapOfIntToString.at(3u) } with "three", Model.ref { mapOfIntToString.at(4u) } with "four", Model.ref { mapOfIntToString.at(1u) } with null, Model.ref { mapOfIntToString.at(2u) } with null)Indexing map keys
Section titled “Indexing map keys”Map properties can be indexed on:
- any map key with
anyKey()(map.~in string notation) - specific map value/key refs like
at(key)/key(key)
anyValue() (map.*) is available for filtering, but is not indexable.
Example:
object ExampleModel : RootDataModel<ExampleModel>( indexes = { listOf( ExampleModel.ref { mapValues.anyKey() } ) }) { val mapValues by map( index = 1u, required = false, keyDefinition = StringDefinition(), valueDefinition = StringDefinition() )}Storage Byte representation
Section titled “Storage Byte representation”Depends on the specific implementation. The values are stored in their representative byte representation.
Transport Byte representation
Section titled “Transport Byte representation”Maps are encoded as multiple entries of tag/value pairs with the tag referring to the index
of the map. The wire type is length delimited and the values are 2 tag/value pairs with the
first one with tag=1 the key and secondly the value with tag=2.
Map encoding
T L Tk Vk Tv Vv T L Tk Vk Tv Vv
Tis the tag index of the mapLis length of encoded key value pairTkis the tag for key and is 1Vkis the value of the keyTvis the tag for the value which is 2Vvis the encoded value of the value
(The encoded values could be encoded Length delimited and thus also contain lengths of the bytes)
