ruby-core

Mailing list archive

[#7055] More on VC++ 2005 — Austin Ziegler <halostatue@...>

Okay. I've got Ruby compiling. I'm attempting to get everything in

17 messages 2006/01/05
[#7058] Re: More on VC++ 2005 — nobuyoshi nakada <nobuyoshi.nakada@...> 2006/01/06

Hi,

[#7084] mathn: ugly warnings — hadmut@... (Hadmut Danisch)

Hi,

22 messages 2006/01/10
[#7097] Re: mathn: ugly warnings — Daniel Berger <Daniel.Berger@...> 2006/01/10

Hadmut Danisch wrote:

[#7098] Design contracts and refactoring (was Re: mathn: ugly warnings) — mathew <meta@...> 2006/01/10

Daniel Berger wrote:

[#7118] Re: Design contracts and refactoring (was Re: mathn: ugly warnings) — mathew <meta@...> 2006/01/12

*Dean Wampler *<deanwampler gmail.com> writes:

[#7226] Fwd: Re: Question about massive API changes — "Sean E. Russell" <ser@...>

Hello,

23 messages 2006/01/28
[#7228] Re: Question about massive API changes — Caleb Tennis <caleb@...> 2006/01/28

>

Newbie question

From: mac <mtscolony@...>
Date: 2006-01-05 20:59:16 UTC
List: ruby-core #7056
Hello all and happy new year.
I just started learning Ruby. I have good experience in Java and Perl and
have read most of the doc on Ruby that I can get my hands on. I started on =
a
project to build the DICOM netwrok library as a way to learn Ruby. I have
done quite bit of coding on this project and have a working code. Well when
I say quite a bit, it is about 5% done!! What I am looking for is RubyIdiom=
s
and if there are better ways of doing things as opposed to what I have
already done. Basically DICOM messages are binary and we need to read the
data and manipulate byes. We will have to construct integers or floats from
bytes or pair of bytes and the next few bytes could be a string etc. I have
pasted some part of the code and want your opinion on this. Also, once this
project has reached a point where it could be used, I will release it to th=
e
community.

What I am looking for is recomendation to improve the speed of the code in
processing the bytes. is 'slice' the best way to do what I am doing. I am
going to re-arrange the code, so dont worry about the neatness at this
point.

Thans and here is the code.

session comes from

server =3D TCPServer.new('localhost', port)
  p "waiting on connection"
while (session =3D server.accept) ........

def ae_6 session
#AE_6
 p "Inside ae_6"
 #stop ARTIM and issue and a-associate indiction primitive.
 # all we have to do here is suck in the whole PDU, that amounts to sending
the indication primitive.
 pdu=3Dsession.getc # reserved, neglect this byte
 pduLen=3Dsession.read(4).unpack('N')[0] # unsigned integer 4 bytes long
 print "PDU Length =3D", pduLen,"\n"
 pdu=3Dsession.read(pduLen) # this is the full PDU
 #version=3Dpdu.slice(0..1).unpack('n')[0]
 #p version
 calledAETitle =3D pdu.slice(4..19) # string of 16 chars
 callingAETitle =3D pdu.slice(20..35) # string of 16 chars
 p calledAETitle
 p callingAETitle
 #pdu.each_byte {|c| print c,"|" }
 #reserved=3Dpdu.slice(36..67) # ignore this
 #next item type should be 10H which is "Application Context" which is
always set to "1.2.840.10008.3.1.1.1"
 itemType=3Dpdu.slice(68..68).unpack('C')[0]
 #printf( "ItemType=3D%XH\n", itemType)
 #ignore the next byte, byte # 69
 itemLength=3Dpdu.slice(70..71).unpack('n')[0]
 contextName=3Dpdu.slice(72..72+itemLength-1)
 p contextName
 # Next we read presentation context items

 start =3D 72+itemLength
 finish =3D 0
 while finish < pduLen
  finish =3D getNextPresentationContext(start, pdu)
  print "Finish =3D ",finish,"  outside proc\n"
  start=3Dfinish+1
 end
end

def getNextPresentationContext(start, pdu)
 finish =3D start
 itemType=3Dpdu.slice(start..finish).unpack('C')[0] #should be20H
 start =3D finish+2 # added 2 here since we need to skip on byte which is
reserved
 finish =3D start + 1 # total of two bytes
 itemLength=3Dpdu.slice(start..finish).unpack('n')[0]
 #printf( "FIRST ItemType=3D%XH,  itemLength=3D%d\n", itemType,itemLength)
 start =3D finish+1
 finish =3D start
 presContextId=3Dpdu.slice(start..finish).unpack('C')[0]
 # next 3 bytes needs to be ignored, they are reserved hence +4 below
 start =3D finish +4
 finish =3D start
 itemType=3Dpdu.slice(start..finish).unpack('C')[0]
 start =3D finish+2 # added 2 here since we need to skip on byte which is
reserved
 finish =3D start + 1 # total of two bytes
 itemLength=3Dpdu.slice(start..finish).unpack('n')[0]
 #printf( "SECOND ItemType=3D%XH,  itemLength=3D%d\n", itemType,itemLength)
 start =3D finish+1
 finish =3D start + itemLength-1 # total of two bytes
 abstractSyntax=3Dpdu.slice(start..finish)

 start =3D finish +1
 finish =3D start
 itemType=3Dpdu.slice(start..finish).unpack('C')[0]
 while itemType =3D=3D 64
  start =3D finish+2 # added 2 here since we need to skip one byte which is
reserved
  finish =3D start + 1 # total of two bytes
  itemLength=3Dpdu.slice(start..finish).unpack('n')[0]
  #printf( "LATER ItemType=3D%XH,  itemLength=3D%d\n", itemType,itemLength)
  start =3D finish+1
  finish =3D start + itemLength-1 # total of two bytes
  transferSyntax=3Dpdu.slice(start..finish)
  printf("id=3D%d, AbstractSyntax =3D%s, TxSyntax=3D%s\n",
presContextId,abstractSyntax,transferSyntax)
  start=3Dfinish+1
  finish =3D start
  itemType=3Dpdu.slice(start..finish).unpack('C')[0]
 end
 return finish-1

In This Thread

Prev Next