diff --git a/ASN1-Model/ASN1AdaptiveTypeObject.class.st b/ASN1-Model/ASN1AdaptiveTypeObject.class.st index ef0f8da..3914c99 100644 --- a/ASN1-Model/ASN1AdaptiveTypeObject.class.st +++ b/ASN1-Model/ASN1AdaptiveTypeObject.class.st @@ -3,7 +3,8 @@ Class { #superclass : 'ASN1AdaptiveTypeValue', #instVars : [ 'map', - 'selfExpanding' + 'selfExpanding', + 'addedByDefault' ], #category : 'ASN1-Model', #package : 'ASN1-Model' @@ -19,6 +20,12 @@ ASN1AdaptiveTypeObject class >> typedCollection [ ^ ASN1TypedCollectionType type: self ] +{ #category : 'accessing' } +ASN1AdaptiveTypeObject >> addedByDefault: aKey [ + addedByDefault ifNil: [ addedByDefault := OrderedCollection new ]. + addedByDefault add: aKey +] + { #category : 'accessing' } ASN1AdaptiveTypeObject >> at: aKey [ ^ self @@ -282,3 +289,9 @@ ASN1AdaptiveTypeObject >> size [ ASN1AdaptiveTypeObject >> soleValue [ ^ map values first ] + +{ #category : 'as yet unclassified' } +ASN1AdaptiveTypeObject >> wasAddedByDefault: aKey [ + addedByDefault ifNil: [ ^ false ]. + ^ addedByDefault includes: aKey +] diff --git a/ASN1-Tool/ASN1ReadVisitor.class.st b/ASN1-Tool/ASN1ReadVisitor.class.st index 3851778..af0f10d 100644 --- a/ASN1-Tool/ASN1ReadVisitor.class.st +++ b/ASN1-Tool/ASN1ReadVisitor.class.st @@ -166,7 +166,8 @@ ASN1ReadVisitor >> visitCollection: aCollection [ "write the default value in the result" element value defaultValue isAsn1 ifTrue: [ value baseValueAt: element key put: element value defaultValue ] - ifFalse: [ value at: element key put: element value defaultValue ] ]. + ifFalse: [ value at: element key put: element value defaultValue ]. + value addedByDefault: element key ]. elementStream next ] ifFalse: [ isExtended ifTrue: [ (aCollection hasElementWithTag: content tag) ifFalse: [ diff --git a/ASN1-Tool/ASN1WriteVisitor.class.st b/ASN1-Tool/ASN1WriteVisitor.class.st index b4be9fd..90bf356 100644 --- a/ASN1-Tool/ASN1WriteVisitor.class.st +++ b/ASN1-Tool/ASN1WriteVisitor.class.st @@ -2,13 +2,20 @@ Class { #name : 'ASN1WriteVisitor', #superclass : 'ASN1ModelVisitor', #instVars : [ - 'currentValue' + 'currentValue', + 'skipAddedDefaults' ], #category : 'ASN1-Tool-Visitor', #package : 'ASN1-Tool', #tag : 'Visitor' } +{ #category : 'initialization' } +ASN1WriteVisitor >> initialize [ + super initialize. + skipAddedDefaults := true +] + { #category : 'exceptions' } ASN1WriteVisitor >> mandatoryElementNotFound [ ASN1MandatoryElementNotFound signal @@ -23,6 +30,11 @@ ASN1WriteVisitor >> push: anObject during: aBlock [ ^aBlock ensure: [ currentValue := formerValue ] ] +{ #category : 'accessing' } +ASN1WriteVisitor >> skipAddedDefaults [ + skipAddedDefaults := true +] + { #category : 'visiting' } ASN1WriteVisitor >> visit: aType [ (aType isNil ifTrue: [ Error signal: 'type cannot be nil' ]). @@ -101,18 +113,19 @@ ASN1WriteVisitor >> visitSequenceType: aSequence [ object := currentValue "basicValue". aSequence elements associations do: [ :each | (each value class = ASN1Extension) ifFalse: [ - (object includesKey: each key) - ifTrue: [ - self - push: (object privAt: each key) - during: [ encoded elements add: (self visit: (aSequence elementAt: each key)) ]] - ifFalse: [ - each value isOptional - ifTrue: [ each value hasDefaultValue ifTrue: [ - self - push: each value defaultValue - during: [ encoded elements add: (self visit: (aSequence elementAt: each key) value) ] ] ] - ifFalse: [ self mandatoryElementNotFound ] ] ] ]. + (skipAddedDefaults and: [ object wasAddedByDefault: each key ]) ifFalse: [ + (object includesKey: each key) + ifTrue: [ + self + push: (object privAt: each key) + during: [ encoded elements add: (self visit: (aSequence elementAt: each key)) ]] + ifFalse: [ + each value isOptional + ifTrue: [ each value hasDefaultValue ifTrue: [ + self + push: each value defaultValue + during: [ encoded elements add: (self visit: (aSequence elementAt: each key) defaultValue type ) ] ] ] + ifFalse: [ self mandatoryElementNotFound ] ] ] ] ]. ^ encoded ]