Generated Go Function Format and Calling Parameters

The primary interface to decode data in Go is through the use of the generated Unmarshal function. This function has the same signature as that found in the Go encoding/asn1 package:

func Unmarshal(b []byte, val interface{}) (rest []byte, err error)

The b argument is used to pass a byte slice into the function containing the message to be decoded. The val argument holds a pointer to a variable of the type into which the message is to be decoded. Note that the Unmarshal function only supports decoding of types determined to be Protocol Data Unit (PDU) types. By default, a PDU type in a schema is a type not found to be referenced by any other type. This behavior can be overridden by using the -pdu command-line option to explicitly select types as PDU types>

The Unmarshal function returns any unused bytes after the message is decoded in the rest argument. This makes it possible to decode a buffer containing multiple messages by looping to decode a message and then assigning the rest result to the message buffer. When the buffer is empty, decoding would be terminated. If any errors occur during decoding, the error result is returned in the err error return value.