public class bind_transmitter : PDUHeader, IProtocolDataUnit
{
#region Public Ctor
public bind_transmitter()
{
this.command_id = CommandConstants.BIND_TRANSMITTER;
this.command_status = 0;
this.addr_npi = 0;
this.addr_ton = 0;
this.address_range = String.Empty;
this.interface_version = 0;
this.password = String.Empty;
this.system_id = String.Empty;
this.system_type = String.Empty;
}
#endregion
#region Private Properties
private byte _addr_npi;
private byte _addr_ton;
private string _address_range;
private byte _interface_version;
private string _password;
private string _system_id;
private string _system_type;
#endregion
#region IProtocolDataUnit Members
/// <summary>
/// Identifies the ESME system requesting to bind as a transmitter
with the SMSC
/// </summary>
public string system_id
{
get { return (_system_id); }
set { _system_id = value; }
}
/// <summary>
/// The password may be used by the SMSC to authenticate the ESME
requesting to bind.
/// </summary>
public string password
{
get { return (_password); }
set { _password = value; }
}
/// <summary>
/// Identifies the type of ESME system requesting to bind as a
transmitter with the SMSC.
/// </summary>
public string system_type
{
get { return (_system_type); }
set { _system_type = value; }
}
/// <summary>
/// Indicates the version of the SMPP protocol supported by the ESME.
/// </summary>
public byte interface_version
{
get { return (_interface_version); }
set { _interface_version = value; }
}
/// <summary>
/// Indicates Type of Number of the ESME address. If not known set
to NULL
/// </summary>
public byte addr_ton
{
get { return (_addr_ton); }
set { _addr_ton = value; }
}
/// <summary>
/// Numbering Plan Indicator for ESME address. If not known set to
NULL.
/// </summary>
public byte addr_npi
{
get { return (_addr_npi); }
set { _addr_npi = value; }
}
/// <summary>
/// The ESME address. If not known set to NULL.
/// </summary>
public string address_range
{
get { return (_address_range); }
set { _address_range = value; }
}
public byte[] Serialize()
{
MemoryStream ms = new MemoryStream();
using (BinaryWriter bw = new BinaryWriter(ms))
{
bw.Write(this.command_length);
bw.Write(this.command_id);
bw.Write(this.command_status);
bw.Write(this.sequence_number);
bw.Write(this.system_id);
bw.Write(this.password);
bw.Write(this.system_type);
}
byte[] buf = ms.ToArray();
uint len = (uint)buf.Length;
uint totalLen = len + (uint)len.ToString().Length;
buf[0] = (byte)totalLen;
return (buf);
}
}
Hi, thanks for the quick response, sorry I am not explaining myself properly
I have posted a snippet of the code, the byte array has the format as follows:
4 Octet Integer - command_length
4 Octet Integer - command_id
4 Octet Integer - command_status
4 Octet Integer - sequence_number
16 Octet String - system_id
9 Octet String - password
13 Octet String - system_type
1 Octet String - interface version
1 Octet Integer - addr_ton
1 Octet Integer - addr_npi
41 Octet String - address_range
[00 00 00 21][00 00 00 04][00 00 00 00][00 00 00 00]00 00 00 00 00 00 00 00
00
00 00 00 00 00 00 00 00
bw.Write(this.command_length); this results 21 i need it to
make it result in the following 00 00 00 21
I want to serialize(not the .NET Serialization) the above class into the
format of the byte array described above
"Jon Skeet [C# MVP]" wrote:
Michael <Mi*****@discussions.microsoft.comwrote:
I need to create a formatted byte array for SMPP, e.g.:
00 00 00 21 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
[00 00 00 21] is the length of the entire message in octets, however the
value is only in the 4 octet, is there someway I can format this into fixed
width, a comparison would be
string s = "21";
Console.WriteLine(s.PadLeft(4,'0'));
Result: 0021
Currently my result is as follows(the value of 15 changes because it is the
octet length of the entire structure
15 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I need it to look like
00 00 00 21 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
Any assistance would be greatly appreciated.
I'm afraid I'm still not entirely sure what you want to do - but
BinaryWriter and BitConverter can both help converting the length into
4 bytes.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too