Questions tagged [binarywriter]

170 questions
4
votes
1 answer

*(decimal*)d=XXXm results in another output than BinaryWriter.Write(XXXm)

I'm writing an optimized binary reader/writer for learning purposes by myself. Everything works fine, until I wrote the tests for the en- and decoding of decimals. My tests also include if the BinaryWriter of the .NET Framework produces compatible…
Scharle
  • 140
  • 1
  • 7
4
votes
2 answers

Do you have to flush your BinaryWriter data

In C# I am using BinaryWriter like this: BinaryWriter br = new BinaryWriter(myPipe); var bytes = new byte[5]; br.Write(bytes); br.Flush(); https://msdn.microsoft.com/de-de/library/system.io.binarywriter.flush(v=vs.110).aspx mentions you should use…
4
votes
1 answer

How do I make the compiler choose the BinaryWriter.Write overload I want?

I am using binary readers and writers to read / write data to a file. For example for this: MyWriter.Write(Ord(TMyEnum(2))); I would expect it to write down SmallInt to be read with MyReader.ReadSmallInt But in IDE I see it writes down byte. How…
user1593881
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

extracting data from .net Data.ToBinary()

I need to read custom-serialized binary data, written using BinaryWriter class. To store a date, the original designers used BinaryWriter.Write( Data.ToBinary() ); This article sort-of mentions how the ToBinary function works; but what I need, is to…
user697296
  • 51
  • 6
3
votes
1 answer

Why is sending data with BinaryWriter so much faster using Write(Byte[]) instead of using foreach and Write(Byte)?

I'm using C# and 32feet (version 3.5) to send blocks of 250 bytes over bluetooth (SPP) to an embedded device I'm currently writing firmware for. I'm setting up my connection with the following code: var client = new BluetoothClient(); client.Encrypt…
Markus
  • 767
  • 2
  • 7
  • 19
3
votes
0 answers

C# [anonymous\generic] object to byte[] without BinaryFormatter [in .NET 4.5]?

BinaryFormatter works great, but doesn't exist in Portable class libraries for .NET 4.5. I've read that it IS in .NET 4.6 Portable. I have not confirmed this because when I change to 4.6 in my project settings, I get a warning message that "4.5…
3
votes
1 answer

EndOfStreamException with simple BinaryWriter and BinaryReader

I'm using the following code: var fileStream = new MemoryStream(); var binaryWriter = new BinaryWriter(fileStream); var binaryReader = new BinaryReader(fileStream); binaryWriter.Write("Hello"); var msg = binaryReader.ReadString(); However I'm…
Mugen
  • 8,301
  • 10
  • 62
  • 140
3
votes
1 answer

Does binarywriter.flush() also flush the underlying filestream object?

I have got a code snippet as follows: Dim fstream = new filestream(some file here) dim bwriter = new binarywriter(fstream) while not end of file read from source file bwriter.write() bwriter.flush() end while The question I have is the…
3
votes
2 answers

Copy data from MemoryStream directly to BinaryWriter.BaseStream?

I have a bunch of data in a MemoryStream and I want to write all of it to a BinaryWriter. Lucky for me all streams now have a Stream.CopyTo(Stream) method, and I can get the target stream from the BinaryWriter.BaseStream property. public void…
Daniel A.A. Pelsmaeker
  • 47,471
  • 20
  • 111
  • 157
3
votes
1 answer

Nonblocking io using BinaryWriter to write to usblp0

I'm doing a program in c# (mono) to print to a fiscal printer (escpos) and it works okay. The problem is that when I print, the program hangs until the buffer I have is cleared. So, as you imagine if I print a couple of images it gets bigger and so…
2
votes
1 answer

Binary Writer returns byte array of null

I'm working with the MRIM (Mail.Ru Agent) protocol. MRIM is a binary protocol, so in order to make the data binary, I'm using the BinaryWriter class. Here's the code: private byte[] CreateMrimPacket(ulong message) { byte[]…
Cracker
  • 912
  • 2
  • 14
  • 26
2
votes
1 answer

C# BinaryWriter Save as PFM image file

Trying to write a 32bit float RGB image as a pfm file, but not sure how to interpret this explanation. (http://www.pauldebevec.com/Research/HDR/PFM/) The format begins with three lines of text specifying the image size and type, and then continues…
Patrik Fröhler
  • 1,221
  • 1
  • 11
  • 38
2
votes
6 answers

BinaryWriter problem - "code adds some byte between Write() method"

I am try to do some code using BinaryWriter and Then BinaryReader. When I wanna write I use method Write(). But the problem is that between two lines of Write method there appears a new byte which is in ASCII table in decimal 31 (sometines 24). You…
Mitja Bonca
  • 4,268
  • 5
  • 24
  • 30
2
votes
2 answers

Modify data via StreamWriter or file writes?

I need to create binary data file. It cannot be created in one pass, I need to serialize some data, then go back and write offsets in the header. File will comfortably fit in memory (a few megabytes). Can I use BinaryWriter and go back to write…
tomash
  • 12,742
  • 15
  • 64
  • 81
1
2
3
11 12