# Re: Newbie question

**URL:** <https://www.ruby-forum.com/t/re-newbie-question/51725>\
**Category:** Ruby\
**Created:** [January 6, 2006, 10:31am UTC](https://www.ruby-forum.com/t/re-newbie-question/51725 "2006-01-06T10:31:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KroegerS\_Simon\_Sext](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/57b2e6/32.png) [@KroegerS\_Simon\_Sext](https://www.ruby-forum.com/u/KroegerS_Simon_Sext)\
**Post date:** [January 6, 2006, 10:31am UTC](https://www.ruby-forum.com/t/re-newbie-question/51725/1 "2006-01-06T10:31:45Z")

</div>

Welcome mac,

your code below should be more or less equal to:  
(no chance of testing obviously)

def ae\_6 session  
pdu, pduLen = session.read(5).unpack(‘cN’)  
buffer = session.read(pduLen)

calledAETitle, callingAETitle, itemType, itemLength =  
buffer.unpack(‘x4A16A16x35Cxn’)

start = 72+itemLength  
contextName=buffer.slice(72…start)

while start \< pduLen  
start = getNextPresentationContext(start, pdu[start…-1]) + 1  
print “Finish = “,start-1,” outside proc\n”  
end  
end

def getNextPresentationContext(start, pdu)  
it, itemLength, presContextId, itemType, itemLength =  
pdu.unpack(‘CxnCx3Cxn’)

start = 12 + itemLength  
abstractSyntax=pdu[12…start]  
itemType=pdu[start]

while itemType == 64  
itemLength=pdu[start+2…start+1].unpack(‘n’)[0]  
transferSyntax=pdu[start+2…start+2+itemLength]

```
puts "id=#{presContextId}, AbstractSyntax =#{abstractSyntax},

```

TxSyntax=#{transferSyntax}"  
start=start+2+itemLength+1  
itemType=pdu[start]  
end  
return start-1  
end

Hope you get the idea.

cheers

Simon
