19 using System.Collections.Generic;
29 private readonly Stream stream;
51 if (b == 0)
return false;
52 if (b == 1)
return true;
53 throw new AvroException(
"Not a boolean value in the stream: " + b);
75 while ((b & 0x80) != 0)
78 n |= (b & 0x7FUL) << shift;
82 return (-(value & 0x01L)) ^ ((value >> 1) & 0x7fffffffffffffffL);
93 byte[] buffer = read(4);
95 if (!BitConverter.IsLittleEndian)
96 Array.Reverse(buffer);
98 return BitConverter.ToSingle(buffer, 0);
116 long bits = (stream.ReadByte() & 0xffL) |
117 (stream.ReadByte() & 0xffL) << 8 |
118 (stream.ReadByte() & 0xffL) << 16 |
119 (stream.ReadByte() & 0xffL) << 24 |
120 (stream.ReadByte() & 0xffL) << 32 |
121 (stream.ReadByte() & 0xffL) << 40 |
122 (stream.ReadByte() & 0xffL) << 48 |
123 (stream.ReadByte() & 0xffL) << 56;
124 return BitConverter.Int64BitsToDouble(bits);
139 byte[] buffer =
new byte[length];
142 return System.Text.Encoding.UTF8.GetString(buffer);
152 return doReadItemCount();
157 return doReadItemCount();
162 return doReadItemCount();
167 return doReadItemCount();
180 public void ReadFixed(
byte[] buffer,
int start,
int length)
182 Read(buffer, start, length);
242 private byte[] read(
long p)
244 byte[] buffer =
new byte[p];
245 Read(buffer, 0, buffer.Length);
249 private static float intBitsToFloat(
int value)
251 return BitConverter.ToSingle(BitConverter.GetBytes(value), 0);
256 int n = stream.ReadByte();
257 if (n >= 0)
return (
byte)n;
258 throw new AvroException(
"End of stream reached");
261 private void Read(
byte[] buffer,
int start,
int len)
265 int n = stream.Read(buffer, start, len);
266 if (n <= 0)
throw new AvroException(
"End of stream reached");
272 private long doReadItemCount()
283 private void Skip(
int p)
285 stream.Seek(p, SeekOrigin.Current);
288 private void Skip(
long p)
290 stream.Seek(p, SeekOrigin.Current);
293 internal void skip(
long block_size)
295 throw new NotImplementedException();
void ReadNull()
null is written as zero bytes
BinaryDecoder(Stream stream)
void SkipBytes()
Skips a bytes Avro type on the stream.
void SkipBoolean()
Skips a boolean Avro type on the stream.
bool ReadBoolean()
a boolean is written as a single byte whose value is either 0 (false) or 1 (true).
long ReadMapNext()
See ReadMapStart().
int ReadEnum()
Reads an enum AvroType
void ReadFixed(byte[] buffer, int start, int length)
Read a Fixed Avro type of length.
long ReadArrayNext()
See ReadArrayStart().
long ReadArrayStart()
Starts reading the array Avro type.
void SkipNull()
Skips a null Avro type on the stream.
byte [] ReadBytes()
Bytes are encoded as a long followed by that many bytes of data.
void ReadFixed(byte[] buffer)
A convenience method for ReadFixed(buffer, 0, buffer.Length);
Decoder is used to decode Avro data on a stream.
void SkipDouble()
Skips a double Avro type on the stream.
void SkipLong()
Skips a long Avro type on the stream.
float ReadFloat()
A float is written as 4 bytes.
double ReadDouble()
A double is written as 8 bytes.
int ReadUnionIndex()
Reads the index, which determines the type in an union Avro type.
void SkipInt()
Skips a int Avro type on the stream.
void SkipFloat()
Skips a float Avro type on the stream.
int ReadInt()
int and long values are written using variable-length, zig-zag coding.
void SkipString()
Skips a string Avro type on the stream.
string ReadString()
Reads a string Avro type
long ReadLong()
int and long values are written using variable-length, zig-zag coding.
long ReadMapStart()
Starts reading the map Avro type.
Decoder for Avro binary format