@@ -635,6 +635,24 @@ true.
635635removeallmethods GtWireFloatPrintStringEncoder
636636removeallclassmethods GtWireFloatPrintStringEncoder
637637
638+ doit
639+ ( GtWireObjectEncoder
640+ subclass : 'GtWireFractionEncoder'
641+ instVarNames : #( )
642+ classVars : #( )
643+ classInstVars : #( )
644+ poolDictionaries : #( )
645+ inDictionary : Globals
646+ options : #( #logCreation )
647+ )
648+ category: 'GToolkit-WireEncoding' ;
649+ immediateInvariant .
650+ true .
651+ %
652+
653+ removeallmethods GtWireFractionEncoder
654+ removeallclassmethods GtWireFractionEncoder
655+
638656doit
639657( GtWireObjectEncoder
640658 subclass : 'GtWireGemStoneOopEncoder'
@@ -2221,6 +2239,28 @@ float
22212239 self assert: next equals: f ]
22222240%
22232241
2242+ category: 'examples'
2243+ method: GtWireEncodingExamples
2244+ floatBinary
2245+ "Check float encoding forcing GtWireFloatEncoder"
2246+ < gtExample >
2247+ < return : #GtWireEncodingExamples>
2248+ | encoder fbEncoder byteArray next |
2249+
2250+ encoder := GtWireEncoder onByteArray.
2251+ fbEncoder := GtWireFloatEncoder new.
2252+ { Float fmin .
2253+ Float fmax .
2254+ 1.25 .
2255+ Float pi . }
2256+ doWithIndex: [ :f :i |
2257+ encoder reset.
2258+ fbEncoder encode: f with: encoder.
2259+ byteArray := encoder contents.
2260+ next := (GtWireDecoder on: byteArray readStream) next.
2261+ self assert: next equals: f ]
2262+ %
2263+
22242264category: 'examples'
22252265method: GtWireEncodingExamples
22262266floatString
@@ -2243,6 +2283,26 @@ floatString
22432283 self assert: next equals: f ]
22442284%
22452285
2286+ category: 'examples'
2287+ method: GtWireEncodingExamples
2288+ fraction
2289+ "Check fraction encoding using the default encoder"
2290+ < gtExample >
2291+ < return : #GtWireEncodingExamples>
2292+ | encoder byteArray next |
2293+ encoder := GtWireEncoder onByteArray.
2294+ { 3 / 5. SmallInteger maxVal * 20 / 17. }
2295+ doWithIndex: [ :f :i |
2296+ self assert: (encoder objectEncoderFor: f) class
2297+ identicalTo: GtWireFractionEncoder.
2298+ encoder reset.
2299+ encoder nextPut: f.
2300+ byteArray := encoder contents.
2301+ next := (GtWireDecoder on: byteArray readStream) next.
2302+ self assert: next class identicalTo: Fraction.
2303+ self assert: next equals: f ]
2304+ %
2305+
22462306category: 'examples'
22472307method: GtWireEncodingExamples
22482308gemStoneRemoteObjectEncoderHasInvalidConfigurationWithoutEncoder
@@ -3037,7 +3097,7 @@ defaultReverseMapIsArray
30373097
30383098 reverseMap := GtWireEncoderDecoder defaultReverseMap.
30393099 self assert: reverseMap isArray.
3040- self assert: reverseMap size equals: 28 .
3100+ self assert: reverseMap size equals: 29 .
30413101 self assert: (reverseMap at: 1) class equals: GtWireNilEncoder.
30423102 ^ reverseMap
30433103%
@@ -3849,6 +3909,46 @@ encode: aFloat with: aGtWireEncoderContext
38493909 putString: aFloat asString
38503910%
38513911
3912+ ! Class implementation for 'GtWireFractionEncoder'
3913+
3914+ ! Class methods for 'GtWireFractionEncoder'
3915+
3916+ category: 'accessing'
3917+ classmethod: GtWireFractionEncoder
3918+ typeIdentifier
3919+
3920+ ^ 30
3921+ %
3922+
3923+ ! Instance methods for 'GtWireFractionEncoder'
3924+
3925+ category: 'encoding - decoding'
3926+ method: GtWireFractionEncoder
3927+ decodeWith: aGtWireEncoderContext
3928+ | numerator denominator negative fraction |
3929+
3930+ negative := aGtWireEncoderContext next.
3931+ numerator := aGtWireEncoderContext nextPackedInteger.
3932+ denominator := aGtWireEncoderContext nextPackedInteger.
3933+ fraction := numerator / denominator.
3934+ ^ negative
3935+ ifTrue: [ fraction negated ]
3936+ ifFalse: [ fraction ].
3937+ %
3938+
3939+ category: 'encoding - decoding'
3940+ method: GtWireFractionEncoder
3941+ encode: aFraction with: aGtWireEncoderContext
3942+ | absFraction |
3943+
3944+ absFraction := aFraction abs.
3945+ aGtWireEncoderContext
3946+ putPackedInteger: self typeIdentifier;
3947+ nextPut: aFraction negative;
3948+ putPackedInteger: absFraction numerator;
3949+ putPackedInteger: absFraction denominator.
3950+ %
3951+
38523952! Class implementation for 'GtWireGemStoneOopEncoder'
38533953
38543954! Class methods for 'GtWireGemStoneOopEncoder'
@@ -4478,25 +4578,6 @@ contents
44784578
44794579category: 'encoding - decoding'
44804580method: GtWireStream
4481- float64
4482- | byteArray |
4483-
4484- byteArray := self next: 8.
4485- ^ byteArray doubleAt: 1.
4486- %
4487-
4488- category: 'encoding - decoding'
4489- method: GtWireStream
4490- float64: aFloat
4491- | byteArray |
4492-
4493- byteArray := ByteArray new: 8.
4494- byteArray doubleAt: 1 put: aFloat.
4495- self nextPutAll: byteArray.
4496- %
4497-
4498- category: 'as yet unclassified'
4499- method: GtWireStream
45004581int64
45014582 "Answer the next signed, 32-bit integer from this (binary) stream."
45024583 "Details: As a fast check for negative number, check the high bit of the first digit"
@@ -4513,7 +4594,7 @@ int64
45134594 ^ n
45144595%
45154596
4516- category : 'as yet unclassified '
4597+ category : 'encoding - decoding '
45174598method : GtWireStream
45184599int64 : anInteger
45194600 | n |
@@ -4715,12 +4796,14 @@ defaultMapping
47154796 at: Set put: GtWireSetEncoder new;
47164797 at: SmallInteger put: GtWireIntegerEncoder new;
47174798 at: LargeInteger put: GtWireIntegerEncoder new;
4718- at: Float put: GtWireFloatPrintStringEncoder new;
4719- at: SmallDouble put: GtWireFloatPrintStringEncoder new;
4720- at: SmallFloat put: GtWireFloatPrintStringEncoder new;
4799+ at: Float put: GtWireFloatEncoder new;
4800+ at: SmallDouble put: GtWireFloatEncoder new;
4801+ at: SmallFloat put: GtWireFloatEncoder new;
47214802 at: UndefinedObject put: GtWireNilEncoder new;
47224803 at: DateAndTime put: GtWireDateAndTimeEncoder new;
4723- at: SmallDateAndTime put: GtWireDateAndTimeEncoder new.
4804+ at: SmallDateAndTime put: GtWireDateAndTimeEncoder new;
4805+ at: Fraction put: GtWireFractionEncoder new;
4806+ at: SmallFraction put: GtWireFractionEncoder new.
47244807 ^ mapping
47254808%
47264809
@@ -4757,7 +4840,8 @@ getDefaultMap
47574840 at: ((self lookupClass: #ExecBlock4) ifNil: [ self error: 'Unable to find: ExecBlock4' ]) put: GtWireBlockClosureEncoder new;
47584841 at: ((self lookupClass: #ExecBlock5) ifNil: [ self error: 'Unable to find: ExecBlock5' ]) put: GtWireBlockClosureEncoder new;
47594842 at: ((self lookupClass: #ExecBlockN) ifNil: [ self error: 'Unable to find: ExecBlockN' ]) put: GtWireBlockClosureEncoder new;
4760- at: ((self lookupClass: #Float) ifNil: [ self error: 'Unable to find: Float' ]) put: GtWireFloatPrintStringEncoder new;
4843+ at: ((self lookupClass: #Float) ifNil: [ self error: 'Unable to find: Float' ]) put: GtWireFloatEncoder new;
4844+ at: ((self lookupClass: #Fraction) ifNil: [ self error: 'Unable to find: Fraction' ]) put: GtWireFractionEncoder new;
47614845 at: ((self lookupClass: #GtRsrEvaluatorFeaturesService) ifNil: [ self error: 'Unable to find: GtRsrEvaluatorFeaturesService' ]) put: GtWireGemStoneRsrEncoder new;
47624846 at: ((self lookupClass: #GtRsrEvaluatorFeaturesServiceServer) ifNil: [ self error: 'Unable to find: GtRsrEvaluatorFeaturesServiceServer' ]) put: GtWireGemStoneRsrEncoder new;
47634847 at: ((self lookupClass: #GtRsrEvaluatorService) ifNil: [ self error: 'Unable to find: GtRsrEvaluatorService' ]) put: GtWireGemStoneRsrEncoder new;
@@ -4781,8 +4865,9 @@ getDefaultMap
47814865 at: ((self lookupClass: #RsrService) ifNil: [ self error: 'Unable to find: RsrService' ]) put: GtWireGemStoneRsrEncoder new;
47824866 at: ((self lookupClass: #Set) ifNil: [ self error: 'Unable to find: Set' ]) put: GtWireSetEncoder new;
47834867 at: ((self lookupClass: #SmallDateAndTime) ifNil: [ self error: 'Unable to find: SmallDateAndTime' ]) put: GtWireDateAndTimeEncoder new;
4784- at: ((self lookupClass: #SmallDouble) ifNil: [ self error: 'Unable to find: SmallDouble' ]) put: GtWireFloatPrintStringEncoder new;
4785- at: ((self lookupClass: #SmallFloat) ifNil: [ self error: 'Unable to find: SmallFloat' ]) put: GtWireFloatPrintStringEncoder new;
4868+ at: ((self lookupClass: #SmallDouble) ifNil: [ self error: 'Unable to find: SmallDouble' ]) put: GtWireFloatEncoder new;
4869+ at: ((self lookupClass: #SmallFloat) ifNil: [ self error: 'Unable to find: SmallFloat' ]) put: GtWireFloatEncoder new;
4870+ at: ((self lookupClass: #SmallFraction) ifNil: [ self error: 'Unable to find: SmallFraction' ]) put: GtWireFractionEncoder new;
47864871 at: ((self lookupClass: #SmallInteger) ifNil: [ self error: 'Unable to find: SmallInteger' ]) put: GtWireIntegerEncoder new;
47874872 at: ((self lookupClass: #String) ifNil: [ self error: 'Unable to find: String' ]) put: GtWireStringEncoder new;
47884873 at: ((self lookupClass: #Symbol) ifNil: [ self error: 'Unable to find: Symbol' ]) put: GtWireSymbolEncoder new;
@@ -4827,6 +4912,7 @@ getDefaultReverseMap
48274912 at: 27 put: GtWireGemStoneWithRsrEncoder new;
48284913 at: 28 put: GtWireClassEncoder new;
48294914 at: 29 put: GtWireFloatPrintStringEncoder new;
4915+ at: 30 put: GtWireFractionEncoder new;
48304916 yourself.
48314917%
48324918
@@ -4943,6 +5029,29 @@ assert: actual equals: expected
49435029 description: actual printString, ' is not equal to ', expected printString.
49445030%
49455031
5032+ ! Class extensions for 'GtWireStream'
5033+
5034+ ! Instance methods for 'GtWireStream'
5035+
5036+ category: '*GToolkit-WireEncoding-GemStone'
5037+ method: GtWireStream
5038+ float64
5039+ | byteArray |
5040+
5041+ byteArray := self next: 8.
5042+ ^ byteArray doubleAt: 1.
5043+ %
5044+
5045+ category: '*GToolkit-WireEncoding-GemStone'
5046+ method: GtWireStream
5047+ float64: aFloat
5048+ | byteArray |
5049+
5050+ byteArray := ByteArray new: 8.
5051+ byteArray doubleAt: 1 put: aFloat.
5052+ self nextPutAll: byteArray.
5053+ %
5054+
49465055! Class Initialization
49475056
49485057run
0 commit comments