Questions tagged [binaryreader]

In .net is a class used to read binary values. In general, it is a class or a program to read and manipulate binary data.

244 questions
8
votes
2 answers

How do I know current offset of BinaryReader in C#?

I have source below: public static void DisplayValues() { float aspectRatio; string tempDirectory; int autoSaveTime; bool showStatusBar; if (File.Exists(fileName)) { using (BinaryReader reader = new…
Joshua Son
  • 1,839
  • 6
  • 31
  • 51
8
votes
2 answers

C# BinaryReader.ReadChar throws "System.ArgumentException: The output char buffer is too small" when reading NetworkStream

When reading C# NetworkStream (from stream-type TCP socket), BinaryReader.ReadChar occasionally throws exceptions System.ArgumentException: The output char buffer is too small to contain the decoded characters, encoding 'Unicode (UTF-8)' All buffers…
user2732454
  • 265
  • 1
  • 3
  • 8
7
votes
3 answers

How many bits does BinaryReader.PeekChar() read?

I am working on improving a stream reader class that uses a BinaryReader. It consists of a while loop that uses .PeekChar() to check if more data exists to continue processing. The very first operation is a .ReadInt32() which reads 4 bytes. What if…
JYelton
  • 35,664
  • 27
  • 132
  • 191
7
votes
2 answers

Count bytes transmitted by TcpClient via NetworkStream BinaryReader/BinaryWriter

I am using a networking protocol built around TcpClient, using BinaryReader to read bytes from the underlying NetworkStream (and, conversely, using BinaryWriter to write). The protocol transmits strings in UTF-8 encoding, and is calling…
Optimax
  • 1,534
  • 2
  • 16
  • 23
7
votes
4 answers

Issue with BinaryReader.ReadChars()

I've run into what I believe is an issue with the BinaryReader.ReadChars() method. When I wrap a BinaryReader around a raw socket NetworkStream occasionally I get a stream corruption where the stream being read gets out of sync. The stream in…
Mike Q
  • 22,839
  • 20
  • 87
  • 129
6
votes
1 answer

C# BinaryReader.Read() gets junk to start with

I am trying to figure out what I am doing wrong here. I am attempting to use a Binary Reader to ease getting an initial four bytes from a stream into an Int32 value that tells me how long the rest of the data is to be expected. static void…
James
  • 1,651
  • 2
  • 18
  • 24
5
votes
1 answer

Binary Reader and Writer open at same time?

I'm writing code that deals with a file that uses hashes. I need to read a chunk, then hash it, then write it, then read another chunk, etc. In other words, I need to do a lot of reading and writing. I'm sure this is really simple, but I just…
mowwwalker
  • 16,634
  • 25
  • 104
  • 157
5
votes
2 answers

BinaryReader ReadString specifying length?

I'm working on a parser to receive UDP information, parse it, and store it. To do so I'm using a BinaryReader since it will mostly be binary information. Some of it will be strings though. MSDN says for the ReadString() function: Reads a string…
Corey Ogburn
  • 24,072
  • 31
  • 113
  • 188
4
votes
3 answers

BinaryReader - Reading a Single " BIT "?

Case : Again trying to capture packets through my NIC, I have developed 2 Extensions to use in capturing variable number of bits public static string ReadBits ( this BinaryReader Key , int Value ) { BitArray _BitArray = new…
Ahmed Ghoneim
  • 6,834
  • 9
  • 49
  • 79
4
votes
1 answer

Read with BinaryReader line by line

I am using the following code to serialize data, from dataTable. var rows = new List>(); I am filling the rows from DataTable and placing them in Dictionary. Don't ask why :) using(var fileStream = new…
4
votes
2 answers

Performance: use a BinaryReader on a MemoryStream to read a byte array, or read directly?

I would like to know whether using a BinaryReader on a MemoryStream created from a byte array (byte[]) would reduce performance significantly. There is binary data I want to read, and I get that data as an array of bytes. I am currently deciding…
Daniel A.A. Pelsmaeker
  • 47,471
  • 20
  • 111
  • 157
4
votes
2 answers

Fast reading of an array of structs from a binary file

Is it possible to read an array of structs from binary file in one call? For example, I have a file containing thousands of vertices: struct Vector3 { float x, y, z; } I need C# port for the C++ code: Vector3 *verts = new Vector3[num_verts]; fread…
Newbee
  • 1,032
  • 1
  • 11
  • 27
4
votes
5 answers

c# - reading from binary log file that is updated every 6 seconds with 12k of data

I have a binary log file with streaming data from a sensor (Int16). Every 6 seconds, 6000 samples of type Int16 are added, until the sensor is disconnected. I need to poll this file on regular intervals, continuing from last position read. Is it…
cabgef
  • 1,398
  • 3
  • 19
  • 35
3
votes
2 answers

How to use BinaryReader and correctly input data into file?

I am working on my homework assignment and I am completely stuck! What I am trying to do is to use already defined input and save it to the file by using saveDataTo() method and read the input by using readDataFrom() method. I am stuck on the first…
HelpNeeder
  • 6,383
  • 24
  • 91
  • 155
3
votes
2 answers

Improving the performance of a BinaryReader

I am currently in the process of writing a BinaryReader that caches the BaseStream.Position and BaseStream.Length properties. Here is what I have so far: public class FastBinaryReader { BinaryReader reader; public long Length { get;…
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
1
2
3
16 17