private static void RunTestForRecord() { Schema schema; using (var stream = new FileStream("./Schemas/Widget.avsc", FileMode.Open)) { var reader = new JsonSchemaReader(); schema = reader.Read(stream); } var serializer = new BinarySerializerBuilder() .BuildSerializer <Widget>(schema); var deserializer = new BinaryDeserializerBuilder() .BuildDeserializer <Widget>(schema); var widgetIn = new Widget { Id = 1010, Name = "One Thousand Ten", Cost = 3829.7401m, Lifetime = TimeSpan.FromMilliseconds(987654321), GlobalId = new Guid("21d45c13-76b1-459d-8571-ba0ad0fa27de"), CreatedAt = DateTime.UtcNow, CreatedAtLocal = DateTimeOffset.Now }; var bytes = serializer.Serialize(widgetIn); var widgetOut = deserializer.Deserialize(bytes); Console.WriteLine(); Console.WriteLine($"Serialized widget to {bytes.Length} bytes."); Console.WriteLine($"Deserialized widget {widgetOut.Id} (\"{widgetOut.Name}\")."); }
protected override async Task Run() { var generator = new CSharpCodeGenerator(); var reader = new JsonSchemaReader(); var schema = reader.Read(await this.ResolveSchema()); try { Console.WriteLine(generator.WriteCompilationUnit(schema)); } catch (Exception exception) { throw new ProgramException(message: exception.Message, inner: exception); } }
protected override void Run() { var type = this.ResolveType(); var task = this.ResolveSchema(); task.Wait(); var reader = new JsonSchemaReader(); var schema = reader.Read(task.Result); try { var builder = new BinaryDeserializerBuilder(); var method = typeof(IBinaryDeserializerBuilder) .GetMethod(nameof(IBinaryDeserializerBuilder.BuildDeserializer)) .MakeGenericMethod(type); method.Invoke(builder, new[] { schema }); } catch (TargetInvocationException exception) when(exception.InnerException is Exception inner) { throw new ProgramException(message: $"A deserializer cannot be created for {type}: {inner.Message}", inner: inner); } try { var builder = new BinarySerializerBuilder(); var method = typeof(IBinarySerializerBuilder) .GetMethod(nameof(IBinarySerializerBuilder.BuildSerializer)) .MakeGenericMethod(type); method.Invoke(builder, new[] { schema }); } catch (TargetInvocationException exception) when(exception.InnerException is Exception inner) { throw new ProgramException(message: $"A serializer cannot be created for {type}: {inner.Message}", inner: inner); } Console.Error.WriteLine($"{type} is compatible with the schema."); }
public void AsymmetricRepresentations(string @out, string @in) { Assert.Equal(@out, writer.Write(reader.Read(@out))); Assert.Equal(@out, writer.Write(reader.Read(@in))); }