473,789 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BinaryReader -- can it be forced to read a BigEndian stream

Can BinaryReader be forced to read a stream, say a TCP/IP stream or memory
stream or even file stream in big endian order or do I have to write
something custom to reverse the byte order? So, for example, I'd like a
Windows client PC (native little endian) to be able to read a network stream
coming in as big endian. I want to be able to read a short for example
without worrying about flipping the bytes.

Thank you,
Laszlo
Nov 16 '05
14 19064
> Laszlo Szijarto <ls*******@nosp am.mrdoc.cc> wrote:
I've never had any trouble with stuff being out of order except if I've
changed my struct mid stream. Then, for some reason, I have to delete all the stuff in the "bin" directories and THEN recompile. Otherwise, the order always seems to come back as listed in the Class (or struct) Definition.


Yes, it does *now* - but it's not guaranteed that it will in the
future. You're relying on the implementation of GetFields not changing,
and I suspect it's very likely that it will in the future.

--
Jon Skeet - <sk***@pobox.co m>


Could [StructLayout(La youtKind.Sequen tial)] help with this?
Nov 16 '05 #11
Hmmm. OK. Then how else would I do something like this. It really would
be helpful if I could read a struct / class out of a stream (like you can in
C++) without resorting to unsafe code and pointers.
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Laszlo Szijarto <ls*******@nosp am.mrdoc.cc> wrote:
I've never had any trouble with stuff being out of order except if I've
changed my struct mid stream. Then, for some reason, I have to delete all the stuff in the "bin" directories and THEN recompile. Otherwise, the order always seems to come back as listed in the Class (or struct) Definition.


Yes, it does *now* - but it's not guaranteed that it will in the
future. You're relying on the implementation of GetFields not changing,
and I suspect it's very likely that it will in the future.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #12
If that works, is there an equivalent for a class? Unfortunately, with a
struct, if you have an array of any kind, you can't specify how many in that
array, so my algorithm won't work, whereas with a class, you can go

public short[] shrt = new short[5];

"Filip Strugar" <fili@sezampro_ dot_yu> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
Laszlo Szijarto <ls*******@nosp am.mrdoc.cc> wrote:
I've never had any trouble with stuff being out of order except if I've changed my struct mid stream. Then, for some reason, I have to delete all the stuff in the "bin" directories and THEN recompile. Otherwise, the order always seems to come back as listed in the Class (or struct)
Definition.
Yes, it does *now* - but it's not guaranteed that it will in the
future. You're relying on the implementation of GetFields not changing,
and I suspect it's very likely that it will in the future.

--
Jon Skeet - <sk***@pobox.co m>


Could [StructLayout(La youtKind.Sequen tial)] help with this?

Nov 16 '05 #13
Filip Strugar <fili@sezampro_ dot_yu> wrote:
Could [StructLayout(La youtKind.Sequen tial)] help with this?


It wouldn't guarantee the order fields are returned in, no. It
determines the order of the fields in memory, but that's different.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #14
Laszlo Szijarto <ls*******@nosp am.mrdoc.cc> wrote:
Hmmm. OK. Then how else would I do something like this. It really would
be helpful if I could read a struct / class out of a stream (like you can in
C++) without resorting to unsafe code and pointers.


Well, you could always sort the fields yourself, eg alphabetically.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
8024
by: Rafal 'Raf256' Maj | last post by:
Hi, I need to parse a file. This means reading from it as from std::istream. But - sometimes I also need to put-back some text I read before. What type of string can I use for that? Something like: void cLine::Load(std::istream &data) { data.ignore(4); // ignore word "line" char c; // ignore { and } chars data >> c >> x1 >> y1 >> x2 >> y2 >> c;
1
1387
by: ywchan | last post by:
I have used a stream reader and sometimes it contains more than one rows of text. How to read all the lines in a stream reader? sr.Readline can only get line by line...and every times the total lines varies...I wonder how to get all the lines at the same time. Thanks!
2
1858
by: om | last post by:
hi I an new to c++ and was wondering if anyone could advise me how to read a stream coming from a http source thanks alot...
2
2099
by: James Minns | last post by:
Hi, I have the following problem with my VB code: accented characters are being transformed into a cr-lf pair! I am reading a sequence of bytes from a binary file, one part of which is a text string. Here is a code snippet: Dim fs As New FileStream("c:\test.bin", FileMode.Open) Dim br As New BinaryReader(fs) Dim str As String
4
2481
by: csharpula csharp | last post by:
Hello,I am trying to read from a zip stream and one of the files is of a 0 size (0 bytes)- Exception is thrown as a result but there are some other files after it in a stream which I want to keep reading and writing to temp dir. How can I deal such exception. I get error when in the end I want to erase the temp dir and it won't let me because the 0 bytes file is being used by other process. How to solve it? Thank you!
6
15934
by: =?Utf-8?B?RGFu?= | last post by:
I need to read an HTTP stream that is defined as excel format. How can I access this via ADO.Net? This dataset pastes nicely into excel. http://ts-lc.sc8.finance.lycos.com/1184344340757?User=?????&Pswd=?????&DataType=Excel97&Symbol=INDEX:NDX.X&Interval=10&Permission=1000&Ht=400&Wd=600&Display=0&Study=&Param1=&Param2=&Param3=&FontSize=10&LocaleID=0x0409 Thanks in advance
2
6617
by: Jack | last post by:
Hi, I want to read a string a chars from a stream, and put it into a string. At the moment, I'm creating a buffer of a fixed size, and reading the stream of text into it. It works, but I have to create a buffer of a pre-defined length: (ConstBufferByteSize=10000000). How can I read a stream into a buffer or string without knowing the number of chars the stream will contain?
11
2285
by: csharpula csharp | last post by:
Hello, I would like to know how can I read a file by this way: Read from line X to Y and in other iteration from line Y to P and on and on. How to implement it? Which method and how? Thank u! *** Sent via Developersdex http://www.developersdex.com ***
3
7459
by: hdbbdh | last post by:
Hello everyone, I try to read a stream and save it as byte array to add it later to zip file. this is the code that I use Dim totalbytes As Byte() = Nothing Dim iBytesRead As Integer Dim sChunks As FileStream = File.OpenRead("c:\myfile.wav") Dim Totalread As Int64 = 0 ReDim totalbytes(sChunks.Length)
0
9663
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10195
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.