Marshaling functions

From HEWIKI
Jump to: navigation, search

Marshaling is a technique used to serialize and send a node from/to the client/server. This page contains documentation on some of the external functions used to accomplish this.

Contents

MarshalNode

MarshalNode(source as NodeRef) as String

Arguments

<source> 
A NodeRef containing the data to marshaled.

Description

This function returns a string containing all of the field values of the node in a format that can be unmarshaled back onto a node having the same fields. Fields are identified by name, so this can be used to transmit data between client and server as long as the fields of the same name are compatible.

This is a built-in function, usable on both client and server.

MarshalPrototype

MarshalPrototype(source as NodeRef) as String

Arguments

<source> 
A NodeRef containing the data to marshaled.

Description

This function returns a string containing all of the field values of the prototype in a format that can be unmarshaled back onto a node having the same fields. Fields are identified by name, so this can be used to transmit data between client and server as long as the fields of the same name are compatible.

This is a built-in function, usable on both client and server.

UnmarshalNode

UnmarshalNode(data as String, dest as NodeRef, failSilently as Boolean)

Arguments

<data> 
A string variable that contains the marshaled data to be extracted.
<dest> 
A NodeRef to contain the extracted data.
<failSilently> 
A boolean specifying if error detection should happen.

Description

This is a built-in function, usable on both client and server, which extracts marshaled data into the fields of a node. Fields are identified by name, so this can be used to transmit data between client and server as long as the fields of the same name are compatible.

Unmarshaling will auto-convert primitive types (string, integer, float, id, ScriptRef, NodeRef, etc.), but if the field can't be converted, it will either be ignored or cause a script error based on the value of failSilently.

MarshalAppendField

MarshalAppendField( marshalData references String, n as NodeRef, sourceField as String)

Arguments

<marshalData> 
A string reference variable to contain the result data.
<n> 
A NodeRef that you want to marshal.
<sourceField> 
The name of a field you want marshaled.

Description

This is a built-in function, usable on both client and server, which adds a single field from a node to the output from a prior MarshalNode call. Alternatively, this can be used starting from a empty string to build a completely custom set of marshaled fields.

MarshalAppendFieldRemap

MarshalAppendFieldRemap( marshalData references String, n as NodeRef, sourceField as String, destField as String)

Arguments

<marshalData> 
A string reference variable to contain the result data.
<n> 
A NodeRef that you want to marshal.
<sourceField> 
The name of a field you want marshaled.
<destField> 
The name you want the field to be when unmarshaled.

Description

This is a built-in function, usable on both client and server, which adds to a marshal buffer a single field and gives it a different name. Alternatively, this can be used starting from a empty string to build a completely custom set of marshaled fields.

MarshalAppendNodeClass

MarshalAppendNodeClass( marshalData references String, n as NodeRef, className as String)

Arguments

<marshalData> 
A string reference variable to contain the result data.
<n> 
A NodeRef that you want to marshal.
<className> 
The name of a class that has the fields you want marshaled.

Description

This is a built-in function, usable on both client and server, which adds to a marshal buffer all of the values for fields that belong to the specified class. Alternatively, this can be used starting from a empty string to build a completely custom set of marshaled fields.

Example

var marshalBuffer = MarshalNode(n1)
MarshalAppendField( marshalBuffer, n2, "aFieldName" )
MarshalAppendFieldRemap( marshalBuffer, n2, "aRealFieldName", "theNewFieldName" )
MarshalAppendNodeClass( marshalBuffer, n2, "aClassName" )
 
// marshalBuffer gets transmitted to another process
 
n3 as NodeRef = createNodeFromClass("aClassName")
UnmarshalNode( marshalBuffer, n3, false )

See also

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox