Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
00567d17
Commit
00567d17
authored
12 years ago
by
Per Hedbor
Browse files
Options
Downloads
Patches
Plain Diff
Added a simple Serializer.Encodeable class.
Inheriting that class makes the object encode/decode value combatible.
parent
dc57c89e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/Serializer.pmod/module.pmod
+59
-0
59 additions, 0 deletions
lib/modules/Serializer.pmod/module.pmod
with
59 additions
and
0 deletions
lib/modules/Serializer.pmod/module.pmod
+
59
−
0
View file @
00567d17
...
@@ -12,3 +12,62 @@
...
@@ -12,3 +12,62 @@
constant Serializable = Builtin.Serializable;
constant Serializable = Builtin.Serializable;
constant serialize = Builtin.serialize;
constant serialize = Builtin.serialize;
constant deserialize = Builtin.deserialize;
constant deserialize = Builtin.deserialize;
//! Simple base for an object that can be serialized by encode_value.
//! Also supports decoding.
//!
//! Uses @[Serializable] as it's base.
//!
//! Simply inherit this class in the classes you want to have encoded
//! and decoded.
//!
//! Note that it's not automatically recursive, objects assigned to
//! variables in this object have to be Encodeable on their own for
//! encode to work.
//!
//! When decoding only variables that existed at the time the object
//! was encoded are assigned, that is, if the class now has more
//! variables they new variables will be set to 0.
class Encodeable
{
inherit Serializable;
//! Callback for encoding the object. Returns a mapping from
//! variable name to value.
//!
//! Called automatically by @[encode_value], not normally called
//! manually.
mapping(string:mixed) _encode()
{
mapping res = ([]);;
_serialize( this, lambda( mixed val, string name, mixed type )
{
res[name] = val;
});
return res;
}
// Override the one from Serializable.
void _deserialize_variable(function deserializer,
function(mixed:void) setter,
string symbol,
mixed symbol_type)
{
deserializer(setter,symbol,symbol_type);
}
//! Callback for decoding the object. Sets variables in the object
//! from the values in the mapping.
//!
//! Called automatically by @[decode_value], not normally called
//! manually.
void _decode(mapping(string:mixed) m)
{
_deserialize( this, lambda( function(mixed:void) set,
string name, mixed type )
{
set( m[name] );
} );
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment