Skip to content

Instantly share code, notes, and snippets.

@nolandubeau
Created June 7, 2013 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolandubeau/25da0d626d62bdd00748 to your computer and use it in GitHub Desktop.
Save nolandubeau/25da0d626d62bdd00748 to your computer and use it in GitHub Desktop.
<cffunction name="serializeObject" output="false" access="public" returntype="any" hint="Serialize an object and optionally save it into a file.">
<cfargument name="target" type="any" required="true" hint="The complex object, such as a query or CFC, that will be serialized."/>
<cfargument name="filePath" type="string" required="false" hint="The path of the file in which to save the serialized data."/>
<cfargument name="algorithm" type="string" required="false" default="" hint="Override the instance algorithm."/>
<cfscript>
var binaryData = "";
if(len(trim(arguments.algorithm))){
local.algorithm = arguments.algorithm;
}else{
local.algorithm = instance.algorithm;
}
// Which algorithm to use?
switch(local.algorithm){
case "generic" : {
binaryData = serializeGeneric(arguments.target);
break;
}
case "railo" : {
binaryData = serializeRailo(arguments.target);
break;
}
case "objectSave" : {
binaryData = serializeWithObjectSave(arguments.target);
break;
}
}
// Save to File?
if( structKeyExists(arguments,"filePath") ){
saveToFile(arguments.filePath,binaryData);
}
return binaryData;
</cfscript>
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment