-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from OpenSmock/hf_tonel
- Loading branch information
Showing
10 changed files
with
222 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Class { | ||
#name : #BlFakeSerializer, | ||
#superclass : #Object, | ||
#classInstVars : [ | ||
'counter' | ||
], | ||
#category : #'Bloc-Serialization-Tests-Core' | ||
} | ||
|
||
{ #category : #initialization } | ||
BlFakeSerializer class >> materialize: anObject [ | ||
|
||
counter := counter + 1 | ||
] | ||
|
||
{ #category : #initialization } | ||
BlFakeSerializer class >> materializeCount [ | ||
|
||
^ counter | ||
] | ||
|
||
{ #category : #initialization } | ||
BlFakeSerializer class >> resetForTest [ | ||
|
||
counter := 0. | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Extension { #name : #Array } | ||
|
||
{ #category : #'*Bloc-Serialization' } | ||
Array >> materializeAsBlElement [ | ||
|
||
^ self | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
" | ||
Serailizer class for Bloc | ||
" | ||
Class { | ||
#name : #BlStashSerializer, | ||
#superclass : #Object, | ||
#traits : 'TBlSerializer', | ||
#classTraits : 'TBlSerializer classTrait', | ||
#category : #'Bloc-Serialization-Core' | ||
} | ||
|
||
{ #category : #'as yet unclassified' } | ||
BlStashSerializer class >> materializeImplementation: anObject [ | ||
|
||
^ Stash new materialize: anObject | ||
] | ||
|
||
{ #category : #'as yet unclassified' } | ||
BlStashSerializer class >> serializeImplementation: anObject [ | ||
|
||
^ Stash new serialize: anObject | ||
] | ||
|
||
{ #category : #'see class side' } | ||
BlStashSerializer >> seeClassSide [ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
" | ||
Serailizer class for Bloc | ||
" | ||
Class { | ||
#name : #BlStonSerializer, | ||
#superclass : #Object, | ||
#traits : 'TBlSerializer', | ||
#classTraits : 'TBlSerializer classTrait', | ||
#category : #'Bloc-Serialization-Core' | ||
} | ||
|
||
{ #category : #'as yet unclassified' } | ||
BlStonSerializer class >> materializeImplementation: anObject [ | ||
|
||
^ STON fromString: anObject | ||
] | ||
|
||
{ #category : #'as yet unclassified' } | ||
BlStonSerializer class >> serializeImplementation: anObject [ | ||
|
||
^ STON toStringPretty: anObject | ||
] | ||
|
||
{ #category : #'see class side' } | ||
BlStonSerializer >> seeClassSide [ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Trait { | ||
#name : #TBlSerializer, | ||
#category : #'Bloc-Serialization' | ||
} | ||
|
||
{ #category : #serialization } | ||
TBlSerializer classSide >> materialize: aString [ | ||
"Materialize a String into a BlElement and return it. Default materializer is STON." | ||
| blElement | | ||
aString isString not ifTrue:[ BlocMaterializationError signal: 'Cannot materialize a no String object into BlElement' ]. | ||
"Try to materialize and catch an error into a BlocMaterialization error" | ||
[ blElement := STON fromString: aString ] onErrorDo: [ :e | BlocMaterializationError signal: 'Cannot support Bloc materialization of this String (', e asString, ')' ]. | ||
blElement ifNil:[ BlocMaterializationError signal: 'Bloc materialization result is nil' ]. | ||
|
||
^ blElement | ||
] | ||
|
||
{ #category : #serialization } | ||
TBlSerializer classSide >> serialize: aBlElementOrABlElementsCollection [ | ||
"Serialize a BlElement or a list of BlElements into a String using a serializer. Default serializer is STON." | ||
|
||
| string | | ||
aBlElementOrABlElementsCollection isCollection | ||
ifTrue: [ self verifyCollection: aBlElementOrABlElementsCollection ] | ||
ifFalse: [ self verifyElement: aBlElementOrABlElementsCollection ]. | ||
|
||
"Try to serialize and catch an error into a BlocSerialization error" | ||
[ string := STON toStringPretty: aBlElementOrABlElementsCollection ] onErrorDo: [ :e | BlocSerializationError signal: 'Cannot support serialization of this BlElement (', e asString, ')' ]. | ||
|
||
^ string | ||
] | ||
|
||
{ #category : #'as yet unclassified' } | ||
TBlSerializer classSide >> verifyCollection: aCollection [ | ||
|
||
"Check if the collection is supported : can contains some BlElements" | ||
aCollection isString ifTrue:[ | ||
BlocSerializationError signal: 'Cannot serialize a String' | ||
]. | ||
|
||
aCollection isDictionary ifTrue:[ | ||
BlocSerializationError signal: 'Cannot serialize a Dictionary' | ||
]. | ||
|
||
aCollection do: [ :each | self verifyElement: each ] | ||
] | ||
|
||
{ #category : #'as yet unclassified' } | ||
TBlSerializer classSide >> verifyElement: aBlElement [ | ||
|
||
(aBlElement isKindOf: BlElement) ifFalse: [ | ||
BlocSerializationError signal: | ||
'Cannot serialize an objet which is not from BlElement class hierarchy' ] | ||
] |