Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
T
trivial-json-codec
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
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
Eric Diethelm
trivial-json-codec
Commits
51afb85d
Verified
Commit
51afb85d
authored
6 years ago
by
Eric Diethelm
Browse files
Options
Downloads
Patches
Plain Diff
Handle empty lists correctly as nil and don't serialize functions.
To serialize function, see trivial-action.
parent
f2567f6b
No related branches found
No related tags found
No related merge requests found
Pipeline
#50078685
passed
6 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
trivial-json-codec.lisp
+10
-3
10 additions, 3 deletions
trivial-json-codec.lisp
with
10 additions
and
3 deletions
trivial-json-codec.lisp
+
10
−
3
View file @
51afb85d
...
...
@@ -11,6 +11,10 @@ Implementations for built-in types already exist. The user might extend with met
(
declare
(
type
stream
stream
))
(
format
stream
"<>"
))
(
defmethod
serialize
((
obj
function
)
stream
)
(
declare
(
type
stream
stream
))
(
serialize
nil
stream
))
(
defmethod
serialize
((
obj
(
eql
t
))
stream
)
(
declare
(
type
stream
stream
))
(
princ
#\T
stream
))
...
...
@@ -102,7 +106,9 @@ If *CLASS* is non-nil and represents a class, an instance of it is returned. Oth
(
declare
(
type
list
parsed-l
))
(
return-from
create-symbol-from-json
(
case
(
car
parsed-l
)
(
List
(
mapcar
#'
(
lambda
(
elm
)
(
create-symbol-from-json
elm
base-class
constructors
))
(
cdr
parsed-l
)))
(
List
(
if
(
eq
1
(
length
parsed-l
))
nil
(
mapcar
#'
(
lambda
(
elm
)
(
create-symbol-from-json
elm
base-class
constructors
))
(
cdr
parsed-l
))))
(
Array
(
let
((
arr
(
make-array
(
length
(
the
list
(
cdr
parsed-l
))))))
(
loop
for
elm
in
(
cdr
parsed-l
)
for
i
of-type
fixnum
=
0
then
(
1+
i
)
...
...
@@ -186,8 +192,9 @@ If *CLASS* is non-nil and represents a class, an instance of it is returned. Oth
(
let*
((
types
(
if
(
listp
raw-type
)
(
cdr
raw-type
)
(
list
raw-type
)))
(
data
(
get-data-for-slot
name
parsed
))
(
unk
(
gensym
))
(
res
(
loop
for
type
in
(
remove
'null
types
)
with
r
=
nil
with
r
=
unk
until
(
setf
r
(
if
(
and
(
typep
data
type
)
...
...
@@ -196,7 +203,7 @@ If *CLASS* is non-nil and represents a class, an instance of it is returned. Oth
data
(
create-symbol-from-json
data
(
find-class
type
)
constructors
)))
finally
(
return
r
))))
(
unless
res
(
when
(
eq
unk
res
)
(
error
"Could not match value to type."
))
(
list
...
...
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