示例#1
0
        /// <summary>
        /// This reads a single serialized datum from a file (not an Avro file container
        /// complete with schema, but the datum only).
        /// </summary>
        private static TransferRequest DeserializeSingleDatumFrom(string file)
        {
            var result = new TransferRequest();

            using (var stream = new FileStream(file, FileMode.Open))
            {
                var decoder = new Avro.IO.BinaryDecoder(stream);
                var reader  = new Avro.Specific.SpecificDefaultReader(result.Schema, result.Schema);
                reader.Read(result, decoder);
            }

            return(result);
        }
        public static ISpecificRecord unpackMessage <T>(IBytesMessage message)
        {
            long len = message.BodyLength;

            byte[]       data = new byte[(int)len];
            int          read = message.ReadBytes(data);
            MemoryStream ins  = new MemoryStream(data);

            Avro.IO.Decoder dc = new Avro.IO.BinaryDecoder(ins);

            // Decode<T> r = new Decode<T>();
            // SpecificReader<T> r = new SpecificReader<T>(c);
            SpecificDefaultReader sdr    = new SpecificDefaultReader(x, z);
            DatumReader <T>       reader = new SpecificReader <T>(sdr);
            T actual = reader.Read(typeof(T), dc);

            //T actual = r(dc);

            ins.Close();
            return((ISpecificRecord)actual);
        }
 private object DecodeIBytesMessage(IBytesMessage msg, JSONPROXY map)
 {
     int len = (int) msg.BodyLength;
     byte[] bytes = new byte[len];
     msg.ReadBytes(bytes, len);
     MemoryStream ins = new MemoryStream(bytes);
     Schema rs = SchemeFor(msg.ContentType, map);
     Schema ws = rs;
     if (rs != null)
     {
         var sdr = new DefaultReader(rs, ws);
         Avro.IO.Decoder dc = new Avro.IO.BinaryDecoder(ins);
         try
         {
             object actual = sdr.Read<object>(null, dc);
             Type t = actual.GetType();
             return actual;
         }
         catch (Exception e)
         {
             Console.Error.WriteLine(e);
             throw;
         }
         finally
         {
             ins.Close();
         }
     }
     else
     {
         Console.WriteLine("*** NO DECODER FOR msg.ContentType='{0}' FOUND ***", msg.ContentType);
         return null;
     }
 }