code: func MarshalCmd(id interface{}, cmd interface{}) ([]byte, error) {
  	// Look up the cmd type and error out if not registered.
  	rt := reflect.TypeOf(cmd)
  	registerLock.RLock()
  	method, ok := concreteTypeToMethod[rt]
  	registerLock.RUnlock()
  	if !ok {
  		str := fmt.Sprintf("%q is not registered", method)
  		return nil, makeError(ErrUnregisteredMethod, str)
  	}
  
  	// The provided command must not be nil.
  	rv := reflect.ValueOf(cmd)
  	if rv.IsNil() {
  		str := "the specified command is nil"
  		return nil, makeError(ErrInvalidType, str)
  	}
  
  	// Create a slice of interface values in the order of the struct fields
  	// while respecting pointer fields as optional params and only adding
  	// them if they are non-nil.
  	params := makeParams(rt.Elem(), rv.Elem())
  
  	// Generate and marshal the final JSON-RPC request.
  	rawCmd, err := NewRequest(id, method, params)
  	if err != nil {
  		return nil, err
  	}
  	return json.Marshal(rawCmd)
  }
docs: // MarshalCmd marshals the passed command to a JSON-RPC request byte slice that
  // is suitable for transmission to an RPC server.  The provided command type
  // must be a registered type.  All commands provided by this package are
  // registered by default.