The BinaryWriter/Reader's are little-endian only. Was hoping they were going
to be made more flexible in 2.0, but that doesn't appear to be the case.
Anyone already done all the work of implementing this? :)
Karl
-- http://www.openmymind.net/ 6 27062
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:ua******** ******@tk2msftn gp13.phx.gbl... The BinaryWriter/Reader's are little-endian only. Was hoping they were going to be made more flexible in 2.0, but that doesn't appear to be the case.
Anyone already done all the work of implementing this? :)
I was hoping so as well.
In addition, any word of a .Net binary stream or serialzation library
compat. with a Java serializaion or Java DataInput/Output stream would
great. This on the .Net server side would save me quite a bit of mobile
badwidth and parsing processing power on the J2ME client side vis-a-vis XML. Karl -- http://www.openmymind.net/
Here's an adapted version of one I've used successfully for reading TIFF
files. Note that it requires a "fieldsize" parameter. This is because the
stream is read the same direction regardless of the byte order. It is the
size in bytes of the data that affects the reading of the bytes from the
stream. It returns the bytes in the correct order after reading, as an array
of bytes. It can be used with other methods to get specific types, such as
Int32, Int64, etc. For example, if you know you're reading Int32 data, you
would pass 32 to the fieldSize parameter. Then you use the BitConverter
class to convert the byte array to whatever data type it is. Below the enum
and method definition I have an example for Int32:
public enum ByteOrder : int
{
LittleEndian,
BigEndian
}
public static byte[] ReadBytes(Binar yReader reader, int fieldSize, ByteOrder
byteOrder)
{
byte[] bytes = new byte[fieldSize];
if (byteOrder == ByteOrder.Littl eEndian)
return reader.ReadByte s(fieldSize);
else
{
for (int i = fieldSize - 1; i > -1; i--)
bytes[i] = reader.ReadByte ();
return bytes;
}
}
public static int ReadInt32(Binar yReader reader, ByteOrder byteOrder)
{
if (byteOrder == ByteOrder.Littl eEndian)
{
return (int)reader.Rea dInt32();
}
else // Big-Endian
{
return BitConverter.To Int32(ReadBytes (reader, 32,
ByteOrder.BigEn dian));
}
}
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
"Mike" <vi********@yah oo.com> wrote in message
news:Of******** *****@TK2MSFTNG P14.phx.gbl... "Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:ua******** ******@tk2msftn gp13.phx.gbl... The BinaryWriter/Reader's are little-endian only. Was hoping they were going to be made more flexible in 2.0, but that doesn't appear to be the case.
Anyone already done all the work of implementing this? :)
I was hoping so as well. In addition, any word of a .Net binary stream or serialzation library compat. with a Java serializaion or Java DataInput/Output stream would great. This on the .Net server side would save me quite a bit of mobile badwidth and parsing processing power on the J2ME client side vis-a-vis XML.
Karl -- http://www.openmymind.net/
Works great.
An int32 would be 4 bytes, 32 bites...so you'd do
ReadBytes(reade r, 4, ByteOrder.BigEn dian)...
;)
Karl
-- http://www.openmymind.net/ http://www.fuelindustries.com/
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:uf******** ******@TK2MSFTN GP15.phx.gbl... Here's an adapted version of one I've used successfully for reading TIFF files. Note that it requires a "fieldsize" parameter. This is because the stream is read the same direction regardless of the byte order. It is the size in bytes of the data that affects the reading of the bytes from the stream. It returns the bytes in the correct order after reading, as an array of bytes. It can be used with other methods to get specific types, such as Int32, Int64, etc. For example, if you know you're reading Int32 data, you would pass 32 to the fieldSize parameter. Then you use the BitConverter class to convert the byte array to whatever data type it is. Below the enum and method definition I have an example for Int32:
public enum ByteOrder : int { LittleEndian, BigEndian }
public static byte[] ReadBytes(Binar yReader reader, int fieldSize, ByteOrder byteOrder) { byte[] bytes = new byte[fieldSize]; if (byteOrder == ByteOrder.Littl eEndian) return reader.ReadByte s(fieldSize); else { for (int i = fieldSize - 1; i > -1; i--) bytes[i] = reader.ReadByte (); return bytes; } }
public static int ReadInt32(Binar yReader reader, ByteOrder byteOrder) { if (byteOrder == ByteOrder.Littl eEndian) { return (int)reader.Rea dInt32(); } else // Big-Endian { return BitConverter.To Int32(ReadBytes (reader, 32, ByteOrder.BigEn dian)); } }
-- HTH,
Kevin Spencer Microsoft MVP .Net Developer We got a sick zebra a hat, you ultimate tuna.
"Mike" <vi********@yah oo.com> wrote in message news:Of******** *****@TK2MSFTNG P14.phx.gbl... "Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:ua******** ******@tk2msftn gp13.phx.gbl... The BinaryWriter/Reader's are little-endian only. Was hoping they were going to be made more flexible in 2.0, but that doesn't appear to be the case.
Anyone already done all the work of implementing this? :)
I was hoping so as well. In addition, any word of a .Net binary stream or serialzation library compat. with a Java serializaion or Java DataInput/Output stream would great. This on the .Net server side would save me quite a bit of mobile badwidth and parsing processing power on the J2ME client side vis-a-vis XML.
Karl -- http://www.openmymind.net/
Oops! Sorry, Karl. As I said, it was adopted from some code that worked, and
I was in a hurry when writing the derived ReadInt32 method. The ReadBytes
method I simply copied, and removed the remarks. In my original class, I
only used the ReadBytes method for things like reading pixels, and used the
actual code in it for the specific data type methods, in order to avoid a
bit of indirection.
I hate it when I do something stupid like that! Apologies.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:uR******** ******@TK2MSFTN GP09.phx.gbl... Works great. An int32 would be 4 bytes, 32 bites...so you'd do
ReadBytes(reade r, 4, ByteOrder.BigEn dian)...
;)
Karl
-- http://www.openmymind.net/ http://www.fuelindustries.com/
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message news:uf******** ******@TK2MSFTN GP15.phx.gbl... Here's an adapted version of one I've used successfully for reading TIFF files. Note that it requires a "fieldsize" parameter. This is because the stream is read the same direction regardless of the byte order. It is the size in bytes of the data that affects the reading of the bytes from the stream. It returns the bytes in the correct order after reading, as an array of bytes. It can be used with other methods to get specific types, such as Int32, Int64, etc. For example, if you know you're reading Int32 data, you would pass 32 to the fieldSize parameter. Then you use the BitConverter class to convert the byte array to whatever data type it is. Below the enum and method definition I have an example for Int32:
public enum ByteOrder : int { LittleEndian, BigEndian }
public static byte[] ReadBytes(Binar yReader reader, int fieldSize, ByteOrder byteOrder) { byte[] bytes = new byte[fieldSize]; if (byteOrder == ByteOrder.Littl eEndian) return reader.ReadByte s(fieldSize); else { for (int i = fieldSize - 1; i > -1; i--) bytes[i] = reader.ReadByte (); return bytes; } }
public static int ReadInt32(Binar yReader reader, ByteOrder byteOrder) { if (byteOrder == ByteOrder.Littl eEndian) { return (int)reader.Rea dInt32(); } else // Big-Endian { return BitConverter.To Int32(ReadBytes (reader, 32, ByteOrder.BigEn dian)); } }
-- HTH,
Kevin Spencer Microsoft MVP .Net Developer We got a sick zebra a hat, you ultimate tuna.
"Mike" <vi********@yah oo.com> wrote in message news:Of******** *****@TK2MSFTNG P14.phx.gbl... "Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:ua******** ******@tk2msftn gp13.phx.gbl... The BinaryWriter/Reader's are little-endian only. Was hoping they were going to be made more flexible in 2.0, but that doesn't appear to be the case.
Anyone already done all the work of implementing this? :)
I was hoping so as well. In addition, any word of a .Net binary stream or serialzation library compat. with a Java serializaion or Java DataInput/Output stream would great. This on the .Net server side would save me quite a bit of mobile badwidth and parsing processing power on the J2ME client side vis-a-vis XML.
Karl -- http://www.openmymind.net/
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mark Miller |
last post by:
I have a char array and when I write it to a file using BinaryWriter the
position of the pointer is the size of the array + 1. For example: writing
char leaves the pointer at position 26 after starting at position 0. I
thought that char was 2 bytes, but this makes it seem as though it is just 1
when I write to a file. Why is this? I imagine...
|
by: ThunderMusic |
last post by:
Hi,
In my app, I open a file using a FileStream then pass it to a
BinaryWriter. I then use the BinaryWriter instance to write to my file. But
a problem arose : The file never gets bigger than 1kb. The code calls the
bw.write(TheValue), but nothing is written after 1kb. I'm I missing
something?
Here's the way I create my FileStream and...
|
by: Perception |
last post by:
Hello all,
If I have a C-like data structure such that
struct Data {
int a; //16-bit value
char; //3 ASCII characters
int b; //32-bit value
int c; //24-bit value
}
|
by: John Aldrin |
last post by:
Hi,
I'm looking for info that explains the format of a string data type
when written to a stream using a BinaryWriter. I've looked all over
MSDN and Internet and I cannot seem to find it.
I did some simple testing and it seems that the string data is
prefixed w/a variable number of bytes that indicate the length.
1 byte if length <=...
|
by: Burns |
last post by:
Hi
I've just tried the following code
FileStream objFS = new FileStream(strFileName, FileMode.Open, FileAccess.Read)
BinaryReader objReader = new BinaryReader(objFS)
UInt32 intFirst = objReader.ReadUInt32()
UInt32 intSecond = 0xC5B8FF00
| |
by: Filip Strugar |
last post by:
Considering that the BinaryWriter/BinaryReader object closes the underlaying
stream upon being gc collected, is the following code correct, and if it is
what is the reason preventing BinaryWriter object garbage collection after
the WriteSomething method is executed?
----
using System;
using System.IO;
|
by: Claire |
last post by:
I'm writing from a serial port into a MemoryStream via a BinaryWriter in my
protocol object.
After I've filled the memorystream, which is approx 200KB in size, I then
pass it up to my datahandler object where I plan to create a BinaryReader to
extract the data and format it ready for a database insert.
At the moment I close the binarywriter...
|
by: Barguast |
last post by:
Is it necessary to call the close method for every BinaryWriter that I
create? Or is it just a way to close the underlying stream? For example is it
OK to do the following:
private void WriteUnicodeStringToStream (Stream s, string string)
{
BinaryWriter bw = new BinaryWriter (s, Encoding.Unicode);
bw.Write (string);
}
|
by: Eugene |
last post by:
I'm trying to write a class which uses BinaryWriter as its base but allows
for queuing of write requests
Public Class QueuedBinaryWriter
Inherits BinaryWriter
I override all the Write methods like so:
Public Overloads Overrides Sub Write(ByVal Value As Byte)
m_Queue.Enqueue(New WriteRequest(MyBase.BaseStream.Position, Value))
End Sub...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |