[squeak-dev] Re: encoding challenge

Robert Withers robert.w.withers at gmail.com
Sat Dec 19 08:22:51 UTC 2015


It turns out my problem was elsewhere. These convert just fine.

My issue is the combination of flipping the whole stack to frames and 
adding headers and header method calls down at the Transport layer. The 
session layer is actually 2 sub-layers, data on top of control. In this 
case, we need a data frame but no control frame, so the transport is 
frameless. It is blowing up on me because control messages have an 
artificial frame.

I will look into Asn1Der encoding of the control messages, however.

cheers,,
robert

On 12/19/2015 01:09 AM, Robert Withers wrote:
> A core part of communications, whether online or to persistence, is 
> encoding, or marshalling.  Let's do an example! Thank you for your 
> thoughtful, earnest participation, as God wills it.
>
> Here are 2 methods that encode and decode a DateAndTime object, but 
> rather poorly. I've been going without much sleep for a bit and I 
> can't figure it out. Here is the code in hopes that some will find 
> this an interesting exercise in team and community building. For that 
> intention, as a beginning.  What's the best solution?
>
> Let's show them how to code when given the space in the environment.  
> Tnks! :)
>
> In class ASN1UTCTimeType..
>
> encodeValue: anObject withDERStream: derStream
>
>     | yy mo dd hh mm ss utcDateTime |
>     yy :=  anObject year asString copyFrom: 3 to: 4.
>     mo :=  anObject month asString padded: #left to: 2 with: $0.
>     dd :=  anObject dayOfMonth asString padded: #left to: 2 with: $0.
>     hh :=  anObject hour asString padded: #left to: 2 with: $0.
>     mm :=  anObject minute asString padded: #left to: 2 with: $0.
>     ss :=  anObject seconds asString padded: #left to: 2 with: $0.
>     utcDateTime := (yy, mo, dd, hh, mm, ss, 'Z') asByteArray.
>     derStream nextPutAll: utcDateTime.
>
>
>
> decodeValueWithDERStream: derStream length: length
>
>     | aUTCDateTime |
>     aUTCDateTime := (derStream next: length) asByteArray asString.
>     ^ (DateAndTime readFromString: (
>         ((aUTCDateTime copyFrom: 1 to: 2) asInteger > 50 ifTrue: 
> ['19'] ifFalse: ['20']),
>         (aUTCDateTime copyFrom: 1 to: 2), '-',
>         (aUTCDateTime copyFrom: 3 to: 4), '-',
>         (aUTCDateTime copyFrom: 5 to: 6), 'T',
>         (aUTCDateTime copyFrom: 7 to: 8), ':',
>         (aUTCDateTime copyFrom: 9 to: 10), ':',
>         (aUTCDateTime copyFrom: 11 to: 12)))
>             offset: 0
>
>

-- 
. .. .. ^,^ robert


More information about the Squeak-dev mailing list