Hi Chris,
Thanks for the code analysis, however
the idea of the sample was on dealing
with an array of fix data that need
referring to later in my code.
The actual project was one to figure out
the RADIUS Accounting protocol, where I have
like large arrays of text that represents
the Vendor specific information and the
text representing that the rfc itself.
e.g. (read RFC2866)
-------------------------------------------------------------------------------------------
....raw radius packet in hex......
-------------------------------------------------------------------------------------------
0439030BA260924F4DB0E2162E00F4260406CB5F2C0A30303030303046371F06333030321A3800000009193268
3332332D73657475702D74696D653D31343A34333A31302E3237302055544320467269204D6172203232203230
30321A1A000000092114683332332D67772D69643D526F757465722E1A38000000091832683332332D636F6E66
2D69643D46364632373730432033434439313144362038323743443745362037343431454343431A1F00000009
1A19683332332D63616C6C2D6F726967696E3D616E737765721A20000000091B1A683332332D63616C6C2D7479
70653D54656C6570686F6E791A4100000009013B683332332D696E636F6D696E672D636F6E662D69643D463646
32373730432033434439313144362038323743443745362037343431454343431A1E0000000901187375627363
72696265723D526567756C61724C696E651A8000000009017A666561747572652D7673613D666E3A5457432C66
743A30332F32322F323030322031343A34333A31302E3237302C63676E3A333030322C63646E3A2C6672733A30
2C6669643A3232382C666369643A46364632373730433343443931314436383237434437453637343431454343
432C6C656749443A45302A06000000002B06000000002F06000000003006000000002E06000000001A3A000000
091C34683332332D636F6E6E6563742D74696D653D31343A34333A31332E3138312055544320467269204D6172
20323220323030321A3D000000091D37683332332D646973636F6E6E6563742D74696D653D31343A34333A3133
2E3138312055544320467269204D617220323220323030321A20000000091E1A683332332D646973636F6E6E65
63742D63617573653D31301A2300000009011D683332332D6976722D6F75743D5461726966663A556E6B6E6F77
6E1A1800000009011272656C656173652D736F757263653D311A1C000000091F16683332332D766F6963652D71
75616C6974793D300106333030322806000000023D0600000000050600000000570946585320332F3106060000
00010406AC11002429060000000F
-------------------------------------------------------------------------------------------
.....deciphered radius packet as text.....
-------------------------------------------------------------------------------------------
Radius Type : Accounting Request
Sequence Id : 57
Length Calc : 779
Length Given : 779
Authenticator : A260924F4DB0E2162E00F4260406CB5F
Normal RADIUS-Area
Acct-Session-Id [44] 10 000000F7
Calling-Station-Id [31] 6 3002
Vendor-Specific-Area [26]
H323 Setup Time [25] 50 h323-setup-time=14:43:10.270
UTC Fri Mar 22 2002
H323 GW Id [33] 20 h323-gw-id=Router.
H323 Conf Id [24] 50 h323-conf-id=F6F2770C 3CD911D6
827CD7E6 7441ECCC
H323 Call Origin [26] 25 h323-call-origin=answer
H323 Call Type [27] 26 h323-call-type=Telephony
Cisco AV Pair [1] 59 h323-incoming-conf-id=F6F2770C
3CD911D6 827CD7E6 7441ECCC
Cisco AV Pair [1] 24 subscriber=RegularLine
Cisco AV Pair [1] 122
feature-vsa=fn:TWC,ft:03/22/2002
14:43:10.270,cgn:3002,cdn:,frs:0,fid:228,fcid:F6F2770C3CD911D6827CD7E67441ECCC,legID:E0
Normal RADIUS-Area
Acct-Input-Octets [42] 6 0.0.0.0
Acct-Output-Octets [43] 6 0.0.0.0
Acct-Input-Packets [47] 6 0.0.0.0
Acct-Output-Packets [48] 6 0.0.0.0
Acct-Session-Time [46] 6 0.0.0.0
Vendor-Specific-Area [26]
H323 Connect Time [28] 52 h323-connect-time=14:43:13.181
UTC Fri Mar 22 2002
H323 Disconnect Time [29] 55
h323-disconnect-time=14:43:13.181 UTC Fri Mar 22 2002
H323 Disconnect Cause [30] 26 h323-disconnect-cause=10
Cisco AV Pair [1] 29 h323-ivr-out=Tariff:Unknown
Cisco AV Pair [1] 18 release-source=1
H323 Voice Quality [31] 22 h323-voice-quality=0
Normal RADIUS-Area
User-Name [1] 6 3002
Acct-Status-Type [40] 6 0.0.0.2
NAS-Port-Type [61] 6 0.0.0.0
NAS-Port [5] 6 0.0.0.0
NAS Port ID [87] 9 FXS 3/1
Service-Type [6] 6 0.0.0.1
NAS-IP-Address [4] 6 172.17.0.36
Acct-Delay-Time [41] 6 0.0.0.15
-------------------------------------------------------------------------------------------
In the deciphered text, the items at the left such as 'H323 Disconnect
Cause' is actually a byte value 40 so I have this massive structured
array with integers and text.
Hope you guys finally get it..
:)
However thanks for your responses..
Cheers!!
Post by Chris Uzdavinis (TeamB)Post by Colin B MaharajHi all,
lets say I have some code like this
//--------------------------------------------------------
struct NumbersStruct
{
int value;
char string[32];
};
NumbersStruct Numbers[] =
{
{ 1, " One " },
{ 2, " Two " },
{ 3, " Three " }
};
Um, ok. Already, however, I'd suggest you have an issue, maybe two.
1) 32 strings is the max. What happens when you need to go to 33, or
128? Recompile and redeploy the application? Ewww. That's an
aritficial limitiation and a pain to work with. Better, you should
load the array from a file, and build it to the proper size as
necessary.
2) You are building in formatting into the data, which means that the
data knows how it will be used. That's typically indicative of a
design flaw. It may work when it's only used in one way today, but
once you have a new use for it, you have possibly "wrongly
formatted" strings, and must strip out the spaces if you want to,
say, make normal sentences with numeric words in them.
3) if you put {0, "Zero"} as the first element, then you can use the
number as the index into the array, and even get rid of the numeric
value in the array.
Post by Colin B MaharajAnsiString MyClass::MyIntToText(int v)
{
AnsiString A = "";
for (int i=0; i<3; i++)
{
if (Numbers[i].value == v) A = Numbers[i].string;
}
return A;
}
Why loop? Are you planning on omitting certain numbers? Having an
array automatically gives a simple indexing function already.
Post by Colin B Maharaj1. Should I place this structure in a separate file and reference it
using an extern declaration, or
I'd hide the implementation behind a functional interface. Then the
"how" is not exposed to clients. You just pass in a number, and get
back a string. "Magic."
Post by Colin B Maharaj2. Should I keep it in the same file as the class and ......
No. This could be is a self-contained class or function that is
*used* by your class.