├── Microsoft.Avro.Tests
├── TestResources
│ └── readme.txt
├── Properties
│ └── AssemblyInfo.cs
├── Microsoft.Avro.Tests.csproj
├── PerformanceTests.cs
├── TypeExtensionsTest.cs
├── MockExecutionContext.cs
└── TestClasses
│ └── AvroCustomContractResolver.cs
├── external
├── avro
│ ├── Avro.dll
│ ├── avro.res
│ ├── log4net.dll
│ ├── flavor_debug
│ │ ├── Avro.dll
│ │ ├── log4net.dll
│ │ └── Newtonsoft.Json.dll
│ └── flavor_release
│ │ ├── Avro.dll
│ │ ├── avro.res
│ │ ├── log4net.dll
│ │ └── Newtonsoft.Json.dll
└── protobuf.net
│ ├── r602
│ ├── net30
│ │ └── protobuf-net.dll
│ ├── Licence.txt
│ ├── WhatFilesDoNeed.txt
│ └── What Files Do I Need.txt
│ └── OSSREADME_1212.txt
├── nuget.config
├── Microsoft.Avro.Core
├── Utils
│ ├── Templates
│ │ ├── Utilities
│ │ │ └── Common.ttinclude
│ │ ├── EnumTemplate.tt
│ │ ├── ITemplate.cs
│ │ ├── EnumTemplate-Methods.cs
│ │ ├── ClassTemplate-Methods.cs
│ │ └── ClassTemplate.tt
│ ├── CompilerError.cs
│ └── GeneratorCore.cs
├── Microsoft.Avro.Core.csproj
├── AvroNull.cs
├── Container
│ ├── IAvroReaderBlock.cs
│ ├── IAvroWriterBlock.cs
│ ├── NullCodec.cs
│ ├── IAvroReader.cs
│ ├── DeflateCodec.cs
│ ├── CodecFactory.cs
│ ├── SequentialReader.cs
│ ├── IAvroWriter.cs
│ ├── Codec.cs
│ ├── AvroBufferWriterBlock.cs
│ ├── AvroBufferReaderBlock.cs
│ └── DecompressionStream.cs
├── NullableSchemaAttribute.cs
├── Schema
│ ├── BooleanSchema.cs
│ ├── LongSchema.cs
│ ├── StringSchema.cs
│ ├── IntSchema.cs
│ ├── NullSchema.cs
│ ├── FloatSchema.cs
│ ├── StandardProperties.cs
│ ├── BytesSchema.cs
│ ├── DoubleSchema.cs
│ ├── Token.cs
│ ├── PrimitiveTypeSchema.cs
│ ├── NamedEntityAttributes.cs
│ ├── NullableSchema.cs
│ ├── TypeSchema.cs
│ ├── NamedSchema.cs
│ ├── FixedSchema.cs
│ ├── ArraySchema.cs
│ └── SurrogateSchema.cs
├── GeneratedSerializer.cs
├── Properties
│ └── AssemblyInfo.cs
├── MemberSerializationInfo.cs
├── Serializers
│ ├── NullableSerializer.cs
│ ├── AsStringSerializer.cs
│ ├── UriSerializer.cs
│ ├── GuidSerializer.cs
│ ├── StringSerializer.cs
│ ├── LongSerializer.cs
│ ├── BooleanSerializer.cs
│ ├── ByteArraySerializer.cs
│ ├── FloatSerializer.cs
│ ├── IObjectSerializer.cs
│ ├── DoubleSerializer.cs
│ ├── IFieldSerializer.cs
│ ├── NullSerializer.cs
│ ├── IntSerializer.cs
│ └── SurrogateSerializer.cs
├── Cache.cs
├── Encoders
│ ├── ISkipper.cs
│ ├── IDecoder.cs
│ └── IEncoder.cs
├── TypeSerializationInfo.cs
├── SerializerGenerator.cs
├── AvroEnum.cs
├── IAvroSerializer.cs
├── Resources
│ └── StringResources.Designer.cs
└── IAvroSurrogate.cs
├── AvroTestApp
├── AvroTestApp.csproj
└── Program.cs
├── Microsoft.Avro.Tools
├── Microsoft.Avro.Tools.csproj
├── ICommand.cs
├── IExecutionContext.cs
├── SampleJSON
│ └── SampleJSONSchema.avsc
├── Properties
│ └── AssemblyInfo.cs
├── CommandFactory.cs
├── ExecutionContext.cs
└── Program.cs
├── README.md
├── .gitignore
├── MicrosoftAvro.sln
└── .gitattributes
/Microsoft.Avro.Tests/TestResources/readme.txt:
--------------------------------------------------------------------------------
1 | This is a general read me file.
--------------------------------------------------------------------------------
/external/avro/Avro.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dougmsft/microsoft-avro/HEAD/external/avro/Avro.dll
--------------------------------------------------------------------------------
/external/avro/avro.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dougmsft/microsoft-avro/HEAD/external/avro/avro.res
--------------------------------------------------------------------------------
/external/avro/log4net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dougmsft/microsoft-avro/HEAD/external/avro/log4net.dll
--------------------------------------------------------------------------------
/external/avro/flavor_debug/Avro.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dougmsft/microsoft-avro/HEAD/external/avro/flavor_debug/Avro.dll
--------------------------------------------------------------------------------
/external/avro/flavor_release/Avro.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dougmsft/microsoft-avro/HEAD/external/avro/flavor_release/Avro.dll
--------------------------------------------------------------------------------
/external/avro/flavor_release/avro.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dougmsft/microsoft-avro/HEAD/external/avro/flavor_release/avro.res
--------------------------------------------------------------------------------
/external/avro/flavor_debug/log4net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dougmsft/microsoft-avro/HEAD/external/avro/flavor_debug/log4net.dll
--------------------------------------------------------------------------------
/external/avro/flavor_release/log4net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dougmsft/microsoft-avro/HEAD/external/avro/flavor_release/log4net.dll
--------------------------------------------------------------------------------
/external/avro/flavor_debug/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dougmsft/microsoft-avro/HEAD/external/avro/flavor_debug/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/external/avro/flavor_release/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dougmsft/microsoft-avro/HEAD/external/avro/flavor_release/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/external/protobuf.net/r602/net30/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dougmsft/microsoft-avro/HEAD/external/protobuf.net/r602/net30/protobuf-net.dll
--------------------------------------------------------------------------------
/nuget.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Utils/Templates/Utilities/Common.ttinclude:
--------------------------------------------------------------------------------
1 | <#+
2 | public void GenerateDataContractNamespace(NamedSchema schema){
3 | #>(Namespace = "<#= Utilities.Validate(schema.Namespace) #>")<#+
4 | }
5 |
6 | private string GetNamespace(NamedSchema schema)
7 | {
8 | return this.ForceNameSpace ? this.DefaultNamespace : string.IsNullOrEmpty(schema.Namespace) ? this.DefaultNamespace : schema.Namespace;
9 | }
10 | #>
--------------------------------------------------------------------------------
/external/protobuf.net/OSSREADME_1212.txt:
--------------------------------------------------------------------------------
1 | ATTENTION - THIS DIRECTORY CONTAINS THIRD PARTY OPEN SOURCE MATERIALS OR THIS PROJECT CONTAINS BUILD SCRIPTS AND TOOLS THAT MAKE USE OF OPEN SOURCE DEVELOPMENT TOOLS OR THIS PROJECT CONTAINS OPEN SOURCE HEADER FILES THAT ARE CONSUMED DURING COMPILATION AND LINK TO OPEN SOURCE LIBRARIES AT RUN TIME: THEY ARE CLEARED ONLY FOR LIMITED USE BY STREAMINSIGHT TEAM FOR THE WINDOWS AZURE STREAMINSIGHT PRODUCT. DO NOT USE OR SHARE THIS CODE WITHOUT APPROVAL PURSUANT TO THE MICROSOFT OPEN SOURCE SOFTWARE APPROVAL POLICY.
--------------------------------------------------------------------------------
/Microsoft.Avro.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | //[assembly: AssemblyTitle("Microsoft.Hadoop.Avro.Tests")]
10 | //[assembly: AssemblyProduct("Microsoft.Hadoop.Avro.Tests")]
11 |
12 | [assembly: ComVisible(false)]
13 | [assembly: CLSCompliant(false)]
14 |
15 | // The following GUID is for the ID of the typelib if this project is exposed to COM
16 |
--------------------------------------------------------------------------------
/AvroTestApp/AvroTestApp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | AvroTestApp
4 | Exe
5 | Test Application for Microsoft Avro libraries
6 | Avro
7 | netcoreapp2.0;net451
8 | win7-x64;win7-x86;ubuntu.16.04-x64;ubuntu.16.04-x86
9 | win7-x64
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Tools/Microsoft.Avro.Tools.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Microsoft.Avro.Tools
4 | Exe
5 | Microsoft Avro Tools for .NET Core 2.0 and .NET Framework 4.5.1.
6 | Avro Serialization Json Binary Schema
7 | netcoreapp2.0;net451
8 | win7-x64;ubuntu.16.04-x64
9 | win7-x64
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Microsoft.Avro.Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Microsoft.Avro.Core
4 | Microsoft Avro library for .NET Standard 2.0 and .NET Framework 4.5.1.
5 | Avro Serialization Json Binary Schema
6 | netstandard2.0;net451
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/external/protobuf.net/r602/Licence.txt:
--------------------------------------------------------------------------------
1 | The core Protocol Buffers technology is provided courtesy of Google.
2 | At the time of writing, this is released under the BSD license.
3 | Full details can be found here:
4 |
5 | http://code.google.com/p/protobuf/
6 |
7 |
8 | This .NET implementation is Copyright 2008 Marc Gravell
9 |
10 | Licensed under the Apache License, Version 2.0 (the "License");
11 | you may not use this file except in compliance with the License.
12 | You may obtain a copy of the License at
13 |
14 | http://www.apache.org/licenses/LICENSE-2.0
15 |
16 | Unless required by applicable law or agreed to in writing, software
17 | distributed under the License is distributed on an "AS IS" BASIS,
18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | See the License for the specific language governing permissions and
20 | limitations under the License.
21 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/AvroNull.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | ///
18 | /// The Avro null class.
19 | ///
20 | public static class AvroNull
21 | {
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Utils/Templates/EnumTemplate.tt:
--------------------------------------------------------------------------------
1 | <#@ template language="C#" linePragmas="false" visibility="internal"#>
2 | <#@ import namespace="Microsoft.Hadoop.Avro.Schema" #>
3 | <#@ assembly name="System.Core" #>
4 | //
5 | namespace <#= Utilities.GetNamespace(this, this.Schema.Namespace) #>
6 | {
7 | using System.Runtime.Serialization;
8 |
9 | ///
10 | /// Used to serialize and deserialize Avro enum <#= Utilities.Validate(this.Schema.FullName) #>.
11 | ///
12 | [DataContract(Namespace = "<#= this.Schema.Namespace #>")]
13 | public enum <#= Utilities.Validate(this.Schema.Name) #>
14 | {
15 | <#
16 | foreach(var symbol in ((EnumSchema)this.Schema).Symbols)
17 | {
18 | #>
19 | ///
20 | /// The <#= Utilities.Validate(symbol) #> symbol.
21 | ///
22 | [EnumMember]
23 | <#= Utilities.Validate(symbol) #>,
24 |
25 | <#
26 | }
27 | #>
28 | }
29 | }
--------------------------------------------------------------------------------
/Microsoft.Avro.Tools/ICommand.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | // use this file except in compliance with the License. You may obtain a copy
5 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
6 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
7 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
8 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
9 | // MERCHANTABLITY OR NON-INFRINGEMENT.
10 | // See the Apache Version 2.0 License for specific language governing
11 | // permissions and limitations under the License.
12 | namespace Microsoft.Hadoop.Avro.Tools
13 | {
14 | internal interface ICommand
15 | {
16 | void Execute(string[] args, IExecutionContext context);
17 |
18 | string GetUsage();
19 |
20 | string GetSyntax();
21 |
22 | string GetSynopsis();
23 |
24 | string Name { get; }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Tools/IExecutionContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | // use this file except in compliance with the License. You may obtain a copy
5 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
6 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
7 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
8 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
9 | // MERCHANTABLITY OR NON-INFRINGEMENT.
10 | // See the Apache Version 2.0 License for specific language governing
11 | // permissions and limitations under the License.
12 |
13 | namespace Microsoft.Hadoop.Avro.Tools
14 | {
15 | using System.IO;
16 |
17 | public interface IExecutionContext
18 | {
19 | void Error(string message);
20 |
21 | void Out(string message);
22 |
23 | string ReadFile(string filePath);
24 |
25 | void WriteFile(string filePath, Stream stream);
26 |
27 | void SetOutputDirectory(string directoryPath);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Tools/SampleJSON/SampleJSONSchema.avsc:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 |
16 | [
17 | {
18 | "namespace":"Microsoft.Hadoop.Avro.Sample",
19 | "type":"record",
20 | "name":"SensorData",
21 | "fields":
22 | [
23 | {
24 | "name":"Location",
25 | "type":
26 | {
27 | "type":"record",
28 | "name":"Location",
29 | "fields":
30 | [
31 | { "name":"Floor", "type":"int" },
32 | { "name":"Room", "type":"int" }
33 | ]
34 | }
35 | },
36 | { "name":"Value", "type":"bytes" }
37 | ]
38 | }
39 | ]
40 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/IAvroReaderBlock.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 |
20 | ///
21 | /// Represents an Avro block for reading.
22 | ///
23 | /// Type of Avro objects inside the block.
24 | public interface IAvroReaderBlock : IDisposable
25 | {
26 | ///
27 | /// Gets decoded Avro objects in a lazy manner.
28 | ///
29 | IEnumerable Objects { get; }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Tools/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Resources;
4 | using System.Runtime.CompilerServices;
5 | using System.Runtime.InteropServices;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 |
11 | // Setting ComVisible to false makes the types in this assembly not visible
12 | // to COM components. If you need to access a type in this assembly from
13 | // COM, set the ComVisible attribute to true on that type.
14 | [assembly: ComVisible(false)]
15 | [assembly: CLSCompliant(true)]
16 |
17 | // The following GUID is for the ID of the typelib if this project is exposed to COM
18 | //[assembly: NeutralResourcesLanguage("en-US")]
19 |
20 | #if CODESIGN
21 | [assembly: InternalsVisibleTo("Microsoft.Avro.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
22 | #else
23 | [assembly: InternalsVisibleTo("Microsoft.Avro.Tests")]
24 | #endif
25 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/NullableSchemaAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | using System;
18 |
19 | ///
20 | /// Makes a field or a property nullable. It allows the user to override nullable handling policy
21 | /// of the resolver and map the type of the field or the property to an Avro union of null and the corresponding Avro type.
22 | ///
23 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
24 | public sealed class NullableSchemaAttribute : Attribute
25 | {
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/BooleanSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System.Collections.Generic;
18 |
19 | ///
20 | /// Class represents a boolean schema.
21 | /// For more details please see the specification.
22 | ///
23 | public sealed class BooleanSchema : PrimitiveTypeSchema
24 | {
25 | internal BooleanSchema()
26 | : this(new Dictionary())
27 | {
28 | }
29 |
30 | internal BooleanSchema(Dictionary attributes)
31 | : base(typeof(bool), attributes)
32 | {
33 | }
34 |
35 | internal override string Type
36 | {
37 | get { return Token.Boolean; }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Utils/CompilerError.cs:
--------------------------------------------------------------------------------
1 |
2 | // Copyright (c) Microsoft Corporation
3 | // All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 | // use this file except in compliance with the License. You may obtain a copy
7 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
11 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12 | // MERCHANTABLITY OR NON-INFRINGEMENT.
13 | //
14 | // See the Apache Version 2.0 License for specific language governing
15 | // permissions and limitations under the License.
16 |
17 | namespace Microsoft.Hadoop.Avro.Utils
18 | {
19 | using System.Collections;
20 |
21 | public class CompilerError
22 | {
23 | private string errorText;
24 | private bool isWarning;
25 |
26 | public CompilerError()
27 | {
28 | }
29 |
30 | public string ErrorText
31 | {
32 | get { return errorText; }
33 | set { errorText = value; }
34 | }
35 |
36 | public bool IsWarning
37 | {
38 | get { return isWarning; }
39 | set { isWarning = value; }
40 | }
41 |
42 | }
43 |
44 | public class CompilerErrorCollection //: CollectionBase
45 | {
46 | public CompilerErrorCollection()
47 | {
48 | }
49 |
50 | public int Add(CompilerError value)
51 | {
52 | //List.Add(value);
53 | return 0;
54 | }
55 |
56 | }
57 | }
--------------------------------------------------------------------------------
/Microsoft.Avro.Tools/CommandFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | // use this file except in compliance with the License. You may obtain a copy
5 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
6 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
7 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
8 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
9 | // MERCHANTABLITY OR NON-INFRINGEMENT.
10 | // See the Apache Version 2.0 License for specific language governing
11 | // permissions and limitations under the License.
12 | namespace Microsoft.Hadoop.Avro.Tools
13 | {
14 | using System;
15 | using System.Collections.Generic;
16 |
17 | internal sealed class CommandFactory
18 | {
19 | public static readonly Dictionary> Commands = new Dictionary>(StringComparer.CurrentCultureIgnoreCase)
20 | {
21 | { new CodeGenerationCommand().Name, () => new CodeGenerationCommand() },
22 | { new HelpCommand().Name, () => new HelpCommand() }
23 | };
24 |
25 | public ICommand Create(string command)
26 | {
27 | if (command == null)
28 | {
29 | throw new ArgumentNullException("command");
30 | }
31 |
32 | if (!Commands.ContainsKey(command))
33 | {
34 | throw new ArgumentException("Command does not exists.");
35 | }
36 |
37 | return Commands[command]();
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/LongSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 |
20 | ///
21 | /// Class represents a long schema.
22 | /// For more details please see the specification.
23 | ///
24 | public sealed class LongSchema : PrimitiveTypeSchema
25 | {
26 | internal LongSchema()
27 | : this(typeof(long))
28 | {
29 | }
30 |
31 | internal LongSchema(Type type)
32 | : this(type, new Dictionary())
33 | {
34 | }
35 |
36 | internal LongSchema(Type type, Dictionary attributes)
37 | : base(type, attributes)
38 | {
39 | }
40 |
41 | internal override string Type
42 | {
43 | get { return Token.Long; }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/StringSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System.Collections.Generic;
18 | using System;
19 |
20 | ///
21 | /// Class represents a string schema.
22 | /// For more details please see the specification.
23 | ///
24 | public class StringSchema : PrimitiveTypeSchema
25 | {
26 | internal StringSchema()
27 | : this(typeof(string))
28 | {
29 | }
30 |
31 | internal StringSchema(Type type)
32 | : this(type, new Dictionary())
33 | {
34 | }
35 |
36 | internal StringSchema(Type type, Dictionary attributes)
37 | : base(type, attributes)
38 | {
39 | }
40 |
41 | internal override string Type
42 | {
43 | get { return Token.String; }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/IntSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 |
20 | ///
21 | /// Class represents an int schema.
22 | /// For more details please see the specification.
23 | ///
24 | public class IntSchema : PrimitiveTypeSchema
25 | {
26 | internal IntSchema()
27 | : this(typeof(int))
28 | {
29 | }
30 |
31 | internal IntSchema(Type runtimeType)
32 | : this(runtimeType, new Dictionary())
33 | {
34 | }
35 |
36 | internal IntSchema(Type runtimeType, Dictionary attributes)
37 | : base(runtimeType, attributes)
38 | {
39 | }
40 |
41 | internal override string Type
42 | {
43 | get { return Token.Int; }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/NullSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 |
20 | ///
21 | /// Class represents a null schema.
22 | /// For more details please see the specification.
23 | ///
24 | public class NullSchema : PrimitiveTypeSchema
25 | {
26 | internal NullSchema(Type runtimeType)
27 | : this(runtimeType, new Dictionary())
28 | {
29 | }
30 |
31 | internal NullSchema()
32 | : this(typeof(object))
33 | {
34 | }
35 |
36 | internal NullSchema(Type runtimeType, Dictionary attributes)
37 | : base(runtimeType, attributes)
38 | {
39 | }
40 |
41 | internal override string Type
42 | {
43 | get { return Token.Null; }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/FloatSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 |
20 | ///
21 | /// Class represents a float schema.
22 | /// For more details please see the specification.
23 | ///
24 | public sealed class FloatSchema : PrimitiveTypeSchema
25 | {
26 | internal FloatSchema()
27 | : this(new Dictionary())
28 | {
29 | }
30 |
31 | internal FloatSchema(Dictionary attributes)
32 | : base(typeof(float), attributes)
33 | {
34 | }
35 |
36 | internal FloatSchema(Type runtimeType)
37 | : base(runtimeType, new Dictionary())
38 | {
39 | }
40 |
41 | internal override string Type
42 | {
43 | get { return Token.Float; }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/StandardProperties.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System.Collections.Generic;
18 |
19 | ///
20 | /// Class containing standard properties for different avro types.
21 | ///
22 | internal static class StandardProperties
23 | {
24 | public static readonly HashSet Primitive = new HashSet { Token.Type };
25 |
26 | public static readonly HashSet Record = new HashSet
27 | {
28 | Token.Type,
29 | Token.Name,
30 | Token.Namespace,
31 | Token.Doc,
32 | Token.Aliases,
33 | Token.Fields
34 | };
35 |
36 | public static readonly HashSet Enumeration = new HashSet
37 | {
38 | Token.Type,
39 | Token.Name,
40 | Token.Namespace,
41 | Token.Doc,
42 | Token.Aliases,
43 | Token.Symbols
44 | };
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/IAvroWriterBlock.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using System.IO;
19 |
20 | ///
21 | /// Represents an Avro block for writing.
22 | ///
23 | /// The type of objects inside the block.
24 | public interface IAvroWriterBlock : IDisposable
25 | {
26 | ///
27 | /// Gets the number of Avro objects in the block.
28 | ///
29 | long ObjectCount { get; }
30 |
31 | ///
32 | /// Writes the specified object to the block.
33 | ///
34 | /// The object.
35 | void Write(T obj);
36 |
37 | ///
38 | /// Flushes buffered data.
39 | ///
40 | void Flush();
41 |
42 | ///
43 | /// Gets the content of the block as a stream.
44 | ///
45 | Stream Content { get; }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Utils/Templates/ITemplate.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Utils.Templates
16 | {
17 | using Microsoft.Hadoop.Avro.Schema;
18 |
19 | ///
20 | /// The Template interface.
21 | ///
22 | public interface ITemplate
23 | {
24 | ///
25 | /// Gets or sets the user defined namespace.
26 | ///
27 | ///
28 | /// The user defined namespace.
29 | ///
30 | string UserDefinedNamespace { get; set; }
31 |
32 | ///
33 | /// Gets or sets the schema.
34 | ///
35 | ///
36 | /// The schema.
37 | ///
38 | NamedSchema Schema { get; set; }
39 |
40 | ///
41 | /// Gets or sets a value indicating whether the namespace is enforced.
42 | ///
43 | ///
44 | /// true if the namespace is enforced; otherwise, false.
45 | ///
46 | bool ForceNamespace { get; set; }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/GeneratedSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | using System;
18 | using Microsoft.Hadoop.Avro.Schema;
19 |
20 | ///
21 | /// Class representing a single generated serializer.
22 | ///
23 | internal sealed class GeneratedSerializer
24 | {
25 | ///
26 | /// Gets or sets the reader schema.
27 | ///
28 | public TypeSchema ReaderSchema { get; set; }
29 |
30 | ///
31 | /// Gets or sets the writer schema.
32 | ///
33 | public TypeSchema WriterSchema { get; set; }
34 |
35 | ///
36 | /// Gets or sets the serialize function.
37 | ///
38 | //public Action Serialize { get; set; }
39 | public Delegate Serialize { get; set; }
40 |
41 | ///
42 | /// Gets or sets the deserialize function.
43 | ///
44 | //public Func Deserialize { get; set; }
45 | public Delegate Deserialize { get; set; }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/BytesSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System.Collections.Generic;
18 |
19 | ///
20 | /// Class represents a byte array schema.
21 | /// For more details please see the specification.
22 | ///
23 | public sealed class BytesSchema : PrimitiveTypeSchema
24 | {
25 | ///
26 | /// Initializes a new instance of the class.
27 | ///
28 | internal BytesSchema() : this(new Dictionary())
29 | {
30 | }
31 |
32 | ///
33 | /// Initializes a new instance of the class.
34 | ///
35 | /// The attributes.
36 | internal BytesSchema(Dictionary attributes) : base(typeof(byte[]), attributes)
37 | {
38 | }
39 |
40 | internal override string Type
41 | {
42 | get { return Token.Bytes; }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/DoubleSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System.Collections.Generic;
18 |
19 | ///
20 | /// Class represents a double schema.
21 | /// For more details please see the specification.
22 | ///
23 | public sealed class DoubleSchema : PrimitiveTypeSchema
24 | {
25 | ///
26 | /// Initializes a new instance of the class.
27 | ///
28 | internal DoubleSchema() : this(new Dictionary())
29 | {
30 | }
31 |
32 | ///
33 | /// Initializes a new instance of the class.
34 | ///
35 | /// The attributes.
36 | internal DoubleSchema(Dictionary attributes) : base(typeof(double), attributes)
37 | {
38 | }
39 |
40 | internal override string Type
41 | {
42 | get { return Token.Double; }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/NullCodec.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using System.IO;
19 |
20 | ///
21 | /// No-compression codec.
22 | ///
23 | internal sealed class NullCodec : Codec
24 | {
25 | public static readonly string CodecName = "null";
26 |
27 | ///
28 | /// Initializes a new instance of the class.
29 | ///
30 | public NullCodec() : base(CodecName)
31 | {
32 | }
33 |
34 | public override Stream GetCompressedStreamOver(Stream decompressed)
35 | {
36 | if (decompressed == null)
37 | {
38 | throw new ArgumentNullException("decompressed");
39 | }
40 |
41 | return decompressed;
42 | }
43 |
44 | public override Stream GetDecompressedStreamOver(Stream compressed)
45 | {
46 | if (compressed == null)
47 | {
48 | throw new ArgumentNullException("compressed");
49 | }
50 |
51 | return compressed;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // /********************************************************
2 | // * *
3 | // * Copyright (C) Microsoft. All rights reserved. *
4 | // * *
5 | // ********************************************************/
6 |
7 | using System;
8 | using System.Reflection;
9 | using System.Resources;
10 | using System.Runtime.CompilerServices;
11 | using System.Runtime.InteropServices;
12 |
13 | // General Information about an assembly is controlled through the following
14 | // set of attributes. Change these attribute values to modify the information
15 | // associated with an assembly.
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 | [assembly: CLSCompliant(true)]
22 |
23 | #if CODESIGN
24 | [assembly: InternalsVisibleTo("Microsoft.Avro.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
25 | [assembly: InternalsVisibleTo("Microsoft.Avro.Tools, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
26 | #else
27 | [assembly: InternalsVisibleTo("Microsoft.Avro.Tests")]
28 | [assembly: InternalsVisibleTo("Microsoft.Avro.Tools")]
29 | #endif
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/IAvroReader.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using Microsoft.Hadoop.Avro.Schema;
19 |
20 | ///
21 | /// Represents a reader around Avro object container.
22 | ///
23 | /// The type of objects inside the container.
24 | public interface IAvroReader : IDisposable
25 | {
26 | ///
27 | /// Gets the schema of the underlying stream.
28 | ///
29 | TypeSchema Schema { get; }
30 |
31 | ///
32 | /// Positions the reader to the absolute position.
33 | ///
34 | /// The block start position.
35 | void Seek(long blockStartPosition);
36 |
37 | ///
38 | /// Moves to the next block.
39 | ///
40 | /// True if the next block exists.
41 | bool MoveNext();
42 |
43 | ///
44 | /// Gets current block.
45 | ///
46 | IAvroReaderBlock Current
47 | {
48 | get;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/DeflateCodec.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using System.IO;
19 |
20 | ///
21 | /// Deflate compression codec.
22 | ///
23 | internal sealed class DeflateCodec : Codec
24 | {
25 | public static readonly string CodecName = "deflate";
26 |
27 | ///
28 | /// Initializes a new instance of the class.
29 | ///
30 | public DeflateCodec() : base(CodecName)
31 | {
32 | }
33 |
34 | public override Stream GetCompressedStreamOver(Stream decompressed)
35 | {
36 | if (decompressed == null)
37 | {
38 | throw new ArgumentNullException("decompressed");
39 | }
40 |
41 | return new CompressionStream(decompressed);
42 | }
43 |
44 | public override Stream GetDecompressedStreamOver(Stream compressed)
45 | {
46 | if (compressed == null)
47 | {
48 | throw new ArgumentNullException("compressed");
49 | }
50 |
51 | return new DecompressionStream(compressed);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/MemberSerializationInfo.cs:
--------------------------------------------------------------------------------
1 | // /********************************************************
2 | // * *
3 | // * Copyright (C) Microsoft. All rights reserved. *
4 | // * *
5 | // ********************************************************/
6 |
7 | namespace Microsoft.Hadoop.Avro
8 | {
9 | using System.Collections.Generic;
10 | using System.Reflection;
11 |
12 | ///
13 | /// Represents serialization information about a member of a class/struct.
14 | ///
15 | public sealed class MemberSerializationInfo
16 | {
17 | ///
18 | /// Initializes a new instance of the class.
19 | ///
20 | public MemberSerializationInfo()
21 | {
22 | this.Aliases = new List();
23 | this.Doc = string.Empty;
24 | }
25 |
26 | ///
27 | /// Gets or sets the Avro name of the member.
28 | ///
29 | public string Name { get; set; }
30 |
31 | ///
32 | /// Gets the aliases of the member.
33 | ///
34 | public ICollection Aliases { get; private set; }
35 |
36 | ///
37 | /// Gets or sets the doc attribute.
38 | ///
39 | public string Doc { get; set; }
40 |
41 | ///
42 | /// Gets or sets the runtime type of the member.
43 | ///
44 | public MemberInfo MemberInfo { get; set; }
45 |
46 | ///
47 | /// Gets or sets a value indicating whether member is nullable.
48 | ///
49 | ///
50 | /// true if member is nullable; otherwise, false.
51 | ///
52 | public bool Nullable { get; set; }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | # microsoft-avro
21 |
22 | This repository contains the Avro core extracted from the HDInsight SDK and
23 | ported to the .NET Standard API on the .NET Core 2.0 runtime. It was last
24 | tested against the 2.0.0-preview2-005858 version of the .NET Core tools and
25 | runtime.
26 |
27 | Prerequisites
28 | -------------
29 |
30 | * Windows OS including Windows 10 or Windows Server 2016.
31 | * .NET Cli tools: [https://github.com/dotnet/cli](https://github.com/dotnet/cli)
32 |
33 |
34 | Instructions
35 | ------------
36 |
37 | You will need to build at the command line using the .NET Core SDK tools (dotnet)
38 | since building in Visual Studio 2017 is not yet supported. However, the solution
39 | can be opened in Visual Studio 2017. .NET Core applications will run on both
40 | Windows and Linux.
41 |
42 | dotnet clean MicrosoftAvro.sln
43 | dotnet restore MicrosoftAvro.sln
44 | dotnet build -c Relase/Debug MicrosoftAvro.sln
45 |
46 | * `clean` cleans any previously built binary
47 | * `restore` restores nuget dependencies
48 | * `build` builds the solution
49 |
50 | To build nuget packages, type the following:
51 |
52 | * `dotnet pack MicrosoftAvro.sln`
53 |
54 | Projects will build out to `Microsoft-Avro\bin\` and will contain
55 | all the platforms that the project supports.
56 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/NullableSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System.Globalization;
18 | using System.Linq.Expressions;
19 | using System.Runtime.Serialization;
20 | using Microsoft.Hadoop.Avro.Schema;
21 |
22 | internal sealed class NullableSerializer : ObjectSerializerBase
23 | {
24 | public NullableSerializer(NullableSchema schema) : base(schema)
25 | {
26 | }
27 |
28 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
29 | {
30 | var exception = new SerializationException(
31 | string.Format(
32 | CultureInfo.InvariantCulture,
33 | "Unexpected null value for the object of type '{0}'. Please check the schema.",
34 | this.Schema.RuntimeType));
35 | return Expression.IfThenElse(
36 | Expression.Equal(value, Expression.Constant(null)),
37 | Expression.Throw(Expression.Constant(exception)),
38 | this.Schema.ValueSchema.Serializer.BuildSerializer(encoder, Expression.Property(value, "Value")));
39 | }
40 |
41 | protected override Expression BuildDeserializerSafe(Expression decoder)
42 | {
43 | return Expression.Convert(this.Schema.ValueSchema.Serializer.BuildDeserializer(decoder), this.Schema.RuntimeType);
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Cache.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | using System.Collections.Generic;
18 |
19 | ///
20 | /// This class represents a cache of generated serializer(s).
21 | ///
22 | /// The type of the key.
23 | /// The type of the value.
24 | internal sealed class Cache
25 | where TValue : class
26 | {
27 | private readonly Dictionary cache;
28 |
29 | public Cache()
30 | {
31 | this.cache = new Dictionary();
32 | }
33 |
34 | public TValue Get(TKey key)
35 | {
36 | lock (this.cache)
37 | {
38 | TValue value;
39 | if (this.cache.TryGetValue(key, out value))
40 | {
41 | return value;
42 | }
43 | }
44 |
45 | return null;
46 | }
47 |
48 | public void Add(TKey key, TValue value)
49 | {
50 | lock (this.cache)
51 | {
52 | if (this.cache.ContainsKey(key))
53 | {
54 | return;
55 | }
56 |
57 | this.cache.Add(key, value);
58 | }
59 | }
60 |
61 | internal int Count
62 | {
63 | get { return this.cache.Count; }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/Token.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | ///
18 | /// Class containing avro schema tokens.
19 | ///
20 | internal static class Token
21 | {
22 | public const string Record = "record";
23 | public const string Enum = "enum";
24 | public const string Array = "array";
25 | public const string Map = "map";
26 | public const string Union = "union";
27 | public const string Fixed = "fixed";
28 |
29 | public const string Boolean = "boolean";
30 | public const string Bytes = "bytes";
31 | public const string String = "string";
32 | public const string Null = "null";
33 | public const string Long = "long";
34 | public const string Int = "int";
35 | public const string Float = "float";
36 | public const string Double = "double";
37 |
38 | public const string Type = "type";
39 | public const string Name = "name";
40 | public const string Namespace = "namespace";
41 | public const string Doc = "doc";
42 | public const string Aliases = "aliases";
43 | public const string Fields = "fields";
44 | public const string Order = "order";
45 | public const string Default = "default";
46 | public const string Symbols = "symbols";
47 | public const string Items = "items";
48 | public const string Values = "values";
49 | public const string Size = "size";
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/PrimitiveTypeSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 | using System.Diagnostics.CodeAnalysis;
20 | using System.Globalization;
21 | using Newtonsoft.Json;
22 |
23 | ///
24 | /// Schema for primitive types.
25 | ///
26 | public abstract class PrimitiveTypeSchema : TypeSchema
27 | {
28 | ///
29 | /// Initializes a new instance of the class.
30 | ///
31 | /// Type of the runtime.
32 | /// The attributes.
33 | protected PrimitiveTypeSchema(Type runtimeType, Dictionary attributes)
34 | : base(runtimeType, attributes)
35 | {
36 | }
37 |
38 | ///
39 | /// Converts current not to json according to the avro specification.
40 | ///
41 | /// The writer.
42 | /// The seen schemas.
43 | [SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase",
44 | Justification = "All Avro tokens are ASCII.")]
45 | internal override void ToJsonSafe(JsonTextWriter writer, HashSet seenSchemas)
46 | {
47 | writer.WriteValue(CultureInfo.InvariantCulture.TextInfo.ToLower(Type));
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Encoders/ISkipper.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | using System;
18 |
19 | ///
20 | /// Defines methods for skipping basic Avro types.
21 | ///
22 | public interface ISkipper : IDisposable
23 | {
24 | ///
25 | /// Skips a boolean value from the underlying stream.
26 | ///
27 | void SkipBool();
28 |
29 | ///
30 | /// Skips a double value from the underlying stream.
31 | ///
32 | void SkipDouble();
33 |
34 | ///
35 | /// Skips a float value from the underlying stream.
36 | ///
37 | void SkipFloat();
38 |
39 | ///
40 | /// Skips an integer value from the underlying stream.
41 | ///
42 | void SkipInt();
43 |
44 | ///
45 | /// Skips a long value from the underlying stream.
46 | ///
47 | void SkipLong();
48 |
49 | ///
50 | /// Skips a byte array from the underlying stream.
51 | ///
52 | void SkipByteArray();
53 |
54 | ///
55 | /// Skips a string value from the underlying stream.
56 | ///
57 | void SkipString();
58 |
59 | ///
60 | /// Skips a fixed value from the underlying stream.
61 | ///
62 | /// The size.
63 | void SkipFixed(int size);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Tests/Microsoft.Avro.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Microsoft.Avro.Tests
4 | netcoreapp2.0;net451
5 | Tests Microsoft Avro libraries
6 | Avro
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | ..\external\avro\Avro.dll
34 |
35 |
36 | ..\external\avro\log4net.dll
37 |
38 |
39 | ..\external\protobuf.net\r602\net30\protobuf-net.dll
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/AsStringSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System;
18 | using System.Diagnostics;
19 | using System.Linq.Expressions;
20 | using System.Reflection;
21 | using Microsoft.Hadoop.Avro.Schema;
22 |
23 | ///
24 | /// Serializers C# objects using its ToString/Parse methods into an Avro string.
25 | ///
26 | internal sealed class AsStringSerializer : ObjectSerializerBase
27 | {
28 | ///
29 | /// Initializes a new instance of the class.
30 | ///
31 | /// The schema.
32 | public AsStringSerializer(PrimitiveTypeSchema schema) : base(schema)
33 | {
34 | }
35 |
36 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
37 | {
38 | MethodInfo toString = this.Schema.RuntimeType.GetMethod("ToString", new Type[] { });
39 | return Expression.Call(
40 | encoder,
41 | this.Encode(),
42 | new Expression[] { Expression.Call(value, toString) });
43 | }
44 |
45 | protected override Expression BuildDeserializerSafe(Expression decoder)
46 | {
47 | MethodInfo parse = this.Schema.RuntimeType.GetMethod("Parse", new[] { typeof(string) });
48 | return Expression.Call(
49 | parse,
50 | Expression.Call(decoder, this.Decode()));
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/TypeSerializationInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | using System.Collections.Generic;
18 |
19 | ///
20 | /// Represents serialization information about a C# type.
21 | ///
22 | public sealed class TypeSerializationInfo
23 | {
24 | ///
25 | /// Initializes a new instance of the class.
26 | ///
27 | public TypeSerializationInfo()
28 | {
29 | this.Aliases = new List();
30 | this.Doc = string.Empty;
31 | this.Nullable = false;
32 | }
33 |
34 | ///
35 | /// Gets or sets the Avro name of the type.
36 | ///
37 | public string Name { get; set; }
38 |
39 | ///
40 | /// Gets or sets the Avro namespace of the type.
41 | ///
42 | public string Namespace { get; set; }
43 |
44 | ///
45 | /// Gets the aliases.
46 | ///
47 | public ICollection Aliases { get; private set; }
48 |
49 | ///
50 | /// Gets or sets the doc attribute.
51 | ///
52 | public string Doc { get; set; }
53 |
54 | ///
55 | /// Gets or sets a value indicating whether this type can represent null values.
56 | ///
57 | ///
58 | /// True if nullable; otherwise, false.
59 | ///
60 | public bool Nullable { get; set; }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *~
6 | *.suo
7 | *.user
8 | *.sln.docstates
9 | developer/
10 |
11 | # Build results
12 | binaries/
13 | [Dd]ebug*/
14 | [Rr]elease/
15 | build/
16 |
17 | [Tt]est[Rr]esult
18 | [Bb]uild[Ll]og.*
19 |
20 | *_i.c
21 | *_p.c
22 | *.ilk
23 | *.meta
24 | *.obj
25 | *.pch
26 | *.pdb
27 | *.pgc
28 | *.pgd
29 | *.rsp
30 | *.sbr
31 | *.tlb
32 | *.tli
33 | *.tlh
34 | *.tmp
35 | *.vspscc
36 | *.vssscc
37 | .builds
38 |
39 | *.pidb
40 |
41 | *.log
42 | *.scc
43 | # Visual C++ cache files
44 | ipch/
45 | *.aps
46 | *.ncb
47 | *.opensdf
48 | *.sdf
49 |
50 | # Visual Studio profiler
51 | *.psess
52 | *.vsp
53 |
54 | # Code analysis
55 | *.CodeAnalysisLog.xml
56 |
57 | # Guidance Automation Toolkit
58 | *.gpState
59 |
60 | # ReSharper is a .NET coding add-in
61 | _ReSharper*/
62 |
63 | *.[Rr]e[Ss]harper
64 |
65 | # NCrunch
66 | *.ncrunch*
67 | .*crunch*.local.xml
68 |
69 | # Installshield output folder
70 | [Ee]xpress
71 |
72 | # DocProject is a documentation generator add-in
73 | DocProject/buildhelp/
74 | DocProject/Help/*.HxT
75 | DocProject/Help/*.HxC
76 | DocProject/Help/*.hhc
77 | DocProject/Help/*.hhk
78 | DocProject/Help/*.hhp
79 | DocProject/Help/Html2
80 | DocProject/Help/html
81 |
82 | # Click-Once directory
83 | publish
84 |
85 | # Publish Web Output
86 | *.Publish.xml
87 |
88 | # Others
89 | [Bb]in
90 | [Oo]bj
91 | TestResults
92 | [Tt]est[Rr]esult*
93 | *.Cache
94 | ClientBin
95 | [Ss]tyle[Cc]op.*
96 | ~$*
97 | *.dbmdl
98 |
99 | *.[Pp]ublish.xml
100 |
101 | Generated_Code #added for RIA/Silverlight projects
102 |
103 | # Build tasks
104 | tools/*.dll
105 |
106 | # Sensitive files
107 | *.keys
108 | *.pfx
109 |
110 | # Backup & report files from converting an old project file to a newer
111 | # Visual Studio version. Backup files are not needed, because we have git ;-)
112 | _UpgradeReport_Files/
113 | Backup*/
114 | UpgradeLog*.XML
115 |
116 | # NuGet
117 | packages
118 | packages/repositories.config
119 |
120 | # Mac development
121 | .DS_Store
122 |
123 | # Specification DLLs
124 | *.Specification.dll
125 |
126 | # Generated readme.txt files #
127 | src/*/readme.txt
128 |
129 | build.out
130 | .nuget/
131 |
132 | # Azure Project
133 | csx/
134 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/CodecFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 | using System.Globalization;
20 |
21 | ///
22 | /// Represents a codec factory.
23 | ///
24 | public class CodecFactory
25 | {
26 | private readonly Dictionary> codecs = new Dictionary>
27 | {
28 | { NullCodec.CodecName, () => new NullCodec() },
29 | { DeflateCodec.CodecName, () => new DeflateCodec() }
30 | };
31 |
32 | ///
33 | /// Creates a codec by name.
34 | ///
35 | /// The name of the codec.
36 | /// A new instance of the codec.
37 | /// If is null.
38 | /// If a codec with name does not exists.
39 | public virtual Codec Create(string codecName)
40 | {
41 | if (string.IsNullOrEmpty(codecName))
42 | {
43 | throw new ArgumentNullException("codecName");
44 | }
45 |
46 | if (!this.codecs.ContainsKey(codecName))
47 | {
48 | throw new ArgumentException(
49 | string.Format(CultureInfo.InvariantCulture, "Codec name '{0}' is unknown.", codecName),
50 | "codecName");
51 | }
52 |
53 | return this.codecs[codecName]();
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/NamedEntityAttributes.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 |
20 | ///
21 | /// Standard attributes supported by named schemas.
22 | ///
23 | internal sealed class NamedEntityAttributes
24 | {
25 | ///
26 | /// Initializes a new instance of the class.
27 | ///
28 | /// The name.
29 | /// The aliases.
30 | /// The doc.
31 | public NamedEntityAttributes(SchemaName name, IEnumerable aliases, string doc)
32 | {
33 | if (name == null)
34 | {
35 | throw new ArgumentNullException("name");
36 | }
37 |
38 | if (aliases == null)
39 | {
40 | throw new ArgumentNullException("aliases");
41 | }
42 |
43 | this.Name = name;
44 | this.Aliases = new List(aliases);
45 | this.Doc = string.IsNullOrEmpty(doc) ? string.Empty : doc;
46 | }
47 |
48 | ///
49 | /// Gets the name.
50 | ///
51 | public SchemaName Name { get; private set; }
52 |
53 | ///
54 | /// Gets the aliases.
55 | ///
56 | public List Aliases { get; private set; }
57 |
58 | ///
59 | /// Gets the doc.
60 | ///
61 | public string Doc { get; private set; }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Tools/ExecutionContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | // use this file except in compliance with the License. You may obtain a copy
5 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
6 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
7 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
8 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
9 | // MERCHANTABLITY OR NON-INFRINGEMENT.
10 | // See the Apache Version 2.0 License for specific language governing
11 | // permissions and limitations under the License.
12 | namespace Microsoft.Hadoop.Avro.Tools
13 | {
14 | using System;
15 | using System.Globalization;
16 | using System.IO;
17 |
18 | using Microsoft.Hadoop.Avro.Tools.Properties;
19 |
20 | internal sealed class ExecutionContext : IExecutionContext
21 | {
22 | public void Error(string message)
23 | {
24 | Console.Error.WriteLine(message);
25 | }
26 |
27 | public void Out(string message)
28 | {
29 | Console.Out.WriteLine(message);
30 | }
31 |
32 | public string ReadFile(string filePath)
33 | {
34 | if (!File.Exists(filePath))
35 | {
36 | throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.ErrorPathDoesNotExist, filePath));
37 | }
38 |
39 | try
40 | {
41 | return File.ReadAllText(filePath);
42 | }
43 | catch (IOException)
44 | {
45 | throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.ErrorCouldNotReadPath, filePath));
46 | }
47 | }
48 |
49 | public void WriteFile(string filePath, Stream stream)
50 | {
51 | stream.Seek(0, SeekOrigin.Begin);
52 | using (var file = File.Create(filePath))
53 | {
54 | stream.CopyTo(file);
55 | }
56 | }
57 |
58 | public void SetOutputDirectory(string directoryPath)
59 | {
60 | if (!Directory.Exists(directoryPath))
61 | {
62 | Directory.CreateDirectory(directoryPath);
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Tests/PerformanceTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Tests
16 | {
17 | using System;
18 | using System.Diagnostics;
19 | using System.IO;
20 | using System.Runtime.CompilerServices;
21 | using Xunit;
22 |
23 | [Trait("Category","Performance")]
24 | public sealed class PerformanceTests
25 | {
26 | private const int NumberOfRuns = 100000;
27 |
28 | [Fact]
29 | [MethodImpl(MethodImplOptions.NoOptimization)]
30 | public void Performance_SimpleFlatClass()
31 | {
32 | var serializationTime = new Stopwatch();
33 | var deserializationTime = new Stopwatch();
34 | var expected = SimpleFlatClass.Create();
35 | var serializer = AvroSerializer.Create(new AvroSerializerSettings { Resolver = new AvroDataContractResolver(true) });
36 |
37 | using (var stream = new MemoryStream())
38 | {
39 | serializationTime.Start();
40 | for (var i = 0; i < NumberOfRuns; i++)
41 | {
42 | serializer.Serialize(stream, expected);
43 | }
44 | serializationTime.Stop();
45 |
46 | stream.Seek(0, SeekOrigin.Begin);
47 |
48 | deserializationTime.Start();
49 | for (var i = 0; i < NumberOfRuns; i++)
50 | {
51 | var deserialized = serializer.Deserialize(stream);
52 | }
53 | deserializationTime.Stop();
54 |
55 | Console.WriteLine(serializationTime.ElapsedTicks);
56 | Console.WriteLine(deserializationTime.ElapsedTicks);
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/NullableSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 | using Newtonsoft.Json;
20 |
21 | ///
22 | /// Artificial node for nullable types.
23 | ///
24 | internal sealed class NullableSchema : TypeSchema
25 | {
26 | private readonly TypeSchema valueSchema;
27 |
28 | ///
29 | /// Initializes a new instance of the class.
30 | ///
31 | /// Type of the nullable.
32 | /// The attributes.
33 | /// The value type schema.
34 | internal NullableSchema(
35 | Type nullableType,
36 | IDictionary attributes,
37 | TypeSchema valueSchema)
38 | : base(nullableType, attributes)
39 | {
40 | this.valueSchema = valueSchema;
41 | }
42 |
43 | internal NullableSchema(
44 | Type nullableType,
45 | TypeSchema valueSchema)
46 | : this(nullableType, new Dictionary(), valueSchema)
47 | {
48 | }
49 |
50 | public TypeSchema ValueSchema
51 | {
52 | get { return this.valueSchema; }
53 | }
54 |
55 | internal override string Type
56 | {
57 | get { return this.valueSchema.Type; }
58 | }
59 |
60 | internal override void ToJsonSafe(JsonTextWriter writer, HashSet seenSchemas)
61 | {
62 | this.valueSchema.ToJsonSafe(writer, seenSchemas);
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/SerializerGenerator.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | using System;
18 | using System.Linq.Expressions;
19 | using Microsoft.Hadoop.Avro.Schema;
20 |
21 | internal sealed class SerializerGenerator
22 | {
23 | public Action GenerateSerializer(TypeSchema schema)
24 | {
25 | if (schema == null)
26 | {
27 | throw new ArgumentNullException("schema");
28 | }
29 |
30 | ParameterExpression instance = Expression.Parameter(typeof(T), "instance");
31 | ParameterExpression encoder = Expression.Parameter(typeof(IEncoder), "encoder");
32 |
33 | var result = schema.Serializer.BuildSerializer(encoder, instance);
34 | Type resultingFunctionType = typeof(Action<,>).MakeGenericType(new[] { typeof(IEncoder), typeof(T) });
35 | LambdaExpression lambda = Expression.Lambda(resultingFunctionType, result, encoder, instance);
36 | return lambda.Compile() as Action;
37 | }
38 |
39 | public Func GenerateDeserializer(TypeSchema schema)
40 | {
41 | if (schema == null)
42 | {
43 | throw new ArgumentNullException("schema");
44 | }
45 |
46 | ParameterExpression decoder = Expression.Parameter(typeof(IDecoder), "decoder");
47 |
48 | Expression result = schema.Serializer.BuildDeserializer(decoder);
49 | Type resultingFunctionType = typeof(Func<,>).MakeGenericType(new[] { typeof(IDecoder), typeof(T) });
50 | LambdaExpression lambda = Expression.Lambda(resultingFunctionType, result, decoder);
51 | return lambda.Compile() as Func;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/MicrosoftAvro.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26403.7
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvroTestApp", "AvroTestApp\AvroTestApp.csproj", "{9A34E8A1-23BA-49D3-B189-1320A38E3FFB}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Avro.Core", "Microsoft.Avro.Core\Microsoft.Avro.Core.csproj", "{266CAE56-5DF3-4A0E-BCDC-85384241D18D}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Avro.Tests", "Microsoft.Avro.Tests\Microsoft.Avro.Tests.csproj", "{FC8A5481-9794-4EB2-93BF-B05FC25DD9C3}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Avro.Tools", "Microsoft.Avro.Tools\Microsoft.Avro.Tools.csproj", "{837E6085-427A-40D4-9789-7FEE036F0DCC}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|x64 = Debug|x64
17 | Release|x64 = Release|x64
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {9A34E8A1-23BA-49D3-B189-1320A38E3FFB}.Debug|x64.ActiveCfg = Debug|Any CPU
21 | {9A34E8A1-23BA-49D3-B189-1320A38E3FFB}.Debug|x64.Build.0 = Debug|Any CPU
22 | {9A34E8A1-23BA-49D3-B189-1320A38E3FFB}.Release|x64.ActiveCfg = Release|Any CPU
23 | {9A34E8A1-23BA-49D3-B189-1320A38E3FFB}.Release|x64.Build.0 = Release|Any CPU
24 | {266CAE56-5DF3-4A0E-BCDC-85384241D18D}.Debug|x64.ActiveCfg = Debug|Any CPU
25 | {266CAE56-5DF3-4A0E-BCDC-85384241D18D}.Debug|x64.Build.0 = Debug|Any CPU
26 | {266CAE56-5DF3-4A0E-BCDC-85384241D18D}.Release|x64.ActiveCfg = Release|Any CPU
27 | {266CAE56-5DF3-4A0E-BCDC-85384241D18D}.Release|x64.Build.0 = Release|Any CPU
28 | {FC8A5481-9794-4EB2-93BF-B05FC25DD9C3}.Debug|x64.ActiveCfg = Debug|Any CPU
29 | {FC8A5481-9794-4EB2-93BF-B05FC25DD9C3}.Debug|x64.Build.0 = Debug|Any CPU
30 | {FC8A5481-9794-4EB2-93BF-B05FC25DD9C3}.Release|x64.ActiveCfg = Release|Any CPU
31 | {FC8A5481-9794-4EB2-93BF-B05FC25DD9C3}.Release|x64.Build.0 = Release|Any CPU
32 | {837E6085-427A-40D4-9789-7FEE036F0DCC}.Debug|x64.ActiveCfg = Debug|Any CPU
33 | {837E6085-427A-40D4-9789-7FEE036F0DCC}.Debug|x64.Build.0 = Debug|Any CPU
34 | {837E6085-427A-40D4-9789-7FEE036F0DCC}.Release|x64.ActiveCfg = Release|Any CPU
35 | {837E6085-427A-40D4-9789-7FEE036F0DCC}.Release|x64.Build.0 = Release|Any CPU
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Utils/Templates/EnumTemplate-Methods.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Utils.Templates
16 | {
17 | using Microsoft.Hadoop.Avro.Schema;
18 |
19 | ///
20 | /// The enumeration template.
21 | ///
22 | internal partial class EnumTemplate : ITemplate
23 | {
24 | ///
25 | /// Initializes a new instance of the class.
26 | ///
27 | /// The enum schema.
28 | /// The default namespace.
29 | /// Determines whether the UserDefinedNamespace should be used.
30 | public EnumTemplate(EnumSchema enumSchema, string userDefinedNamespace, bool forceNamespace)
31 | {
32 | this.Schema = enumSchema;
33 | this.UserDefinedNamespace = userDefinedNamespace;
34 | this.ForceNamespace = forceNamespace;
35 | }
36 |
37 | ///
38 | /// Gets or sets the user defined namespace.
39 | ///
40 | ///
41 | /// The user defined namespace.
42 | ///
43 | public string UserDefinedNamespace { get; set; }
44 |
45 | ///
46 | /// Gets or sets the schema.
47 | ///
48 | ///
49 | /// The schema.
50 | ///
51 | public NamedSchema Schema { get; set; }
52 |
53 | ///
54 | /// Gets or sets a value indicating whether the namespace is enforced.
55 | ///
56 | ///
57 | /// true if the namespace is enforced; otherwise, false.
58 | ///
59 | public bool ForceNamespace { get; set; }
60 | }
61 | }
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Utils/Templates/ClassTemplate-Methods.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Utils.Templates
16 | {
17 | using Microsoft.Hadoop.Avro.Schema;
18 |
19 | ///
20 | /// The class generator.
21 | ///
22 | internal partial class ClassTemplate : ITemplate
23 | {
24 | ///
25 | /// Initializes a new instance of the class.
26 | ///
27 | /// The record schema.
28 | /// The default namespace.
29 | /// Determines whether the UserDefinedNamespace should be used.
30 | public ClassTemplate(RecordSchema recordSchema, string userDefinedNamespace, bool forceNamespace)
31 | {
32 | this.Schema = recordSchema;
33 | this.UserDefinedNamespace = userDefinedNamespace;
34 | this.ForceNamespace = forceNamespace;
35 | }
36 |
37 | ///
38 | /// Gets or sets the user defined namespace.
39 | ///
40 | ///
41 | /// The user defined namespace.
42 | ///
43 | public string UserDefinedNamespace { get; set; }
44 |
45 | ///
46 | /// Gets or sets the schema.
47 | ///
48 | ///
49 | /// The schema.
50 | ///
51 | public NamedSchema Schema { get; set; }
52 |
53 | ///
54 | /// Gets or sets a value indicating whether the namespace is enforced.
55 | ///
56 | ///
57 | /// true if the namespace is enforced; otherwise, false.
58 | ///
59 | public bool ForceNamespace { get; set; }
60 | }
61 | }
--------------------------------------------------------------------------------
/AvroTestApp/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License
15 |
16 | namespace AvroTestApp
17 | {
18 | using System;
19 | using System.IO;
20 | using System.Collections.Generic;
21 | using System.Runtime.Serialization;
22 | using Microsoft.Hadoop.Avro.Container;
23 |
24 | [DataContract]
25 | internal struct TestMsg
26 | {
27 | [DataMember]
28 | public int Id;
29 | [DataMember]
30 | public double Amount;
31 | public TestMsg(int id, double amount)
32 | {
33 | Id = id;
34 | Amount = amount;
35 | }
36 | }
37 |
38 | public class Program
39 | {
40 | public static void Main(string[] args)
41 | {
42 | string line = Environment.NewLine;
43 |
44 | string fileName = "Messages.avro";
45 | string filePath = null;
46 | if (Environment.NewLine.Contains("\r"))
47 | {
48 | filePath = new DirectoryInfo(".") + @"\" + fileName;
49 | }
50 | else
51 | {
52 | filePath = new DirectoryInfo(".") + @"/" + fileName;
53 | }
54 |
55 | List msgs = new List();
56 | msgs.Add(new AvroTestApp.TestMsg(1, 189.12));
57 | msgs.Add(new AvroTestApp.TestMsg(2, 345.94));
58 |
59 | using (var dataStream = new FileStream(filePath, FileMode.Create))
60 | {
61 | using (var avroWriter = AvroContainer.CreateWriter(dataStream, Codec.Deflate))
62 | {
63 | using (var seqWriter = new SequentialWriter(avroWriter, msgs.Count))
64 | {
65 | msgs.ForEach(seqWriter.Write);
66 | }
67 | }
68 | dataStream.Dispose();
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/UriSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System.Diagnostics;
18 | using System.Globalization;
19 | using System.Linq.Expressions;
20 | using System.Reflection;
21 | using System.Runtime.Serialization;
22 | using Microsoft.Hadoop.Avro.Schema;
23 |
24 | ///
25 | /// Serializes Uri as Avro string.
26 | ///
27 | internal sealed class UriSerializer : ObjectSerializerBase
28 | {
29 | ///
30 | /// Initializes a new instance of the class.
31 | ///
32 | /// The schema.
33 | public UriSerializer(StringSchema schema) : base(schema)
34 | {
35 | }
36 |
37 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
38 | {
39 | PropertyInfo original = this.Schema.RuntimeType.GetProperty("OriginalString");
40 | return Expression.Call(encoder, this.Encode(), new Expression[] { Expression.Property(value, original) });
41 | }
42 |
43 | protected override Expression BuildDeserializerSafe(Expression decoder)
44 | {
45 | ConstructorInfo constructor = this.Schema.RuntimeType.GetConstructor(new[] { typeof(string) });
46 | if (constructor == null)
47 | {
48 | throw new SerializationException(string.Format(
49 | CultureInfo.InvariantCulture,
50 | "Type '{0}' is considered a 'Uri' and expected to have a constructor with a string parameter.",
51 | this.Schema.RuntimeType));
52 | }
53 |
54 | return Expression.New(constructor, new Expression[] { Expression.Call(decoder, this.Decode()) });
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/GuidSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System;
18 | using System.Linq.Expressions;
19 | using System.Reflection;
20 | using System.Runtime.Serialization;
21 | using Microsoft.Hadoop.Avro.Schema;
22 |
23 | ///
24 | /// Serializes Guid as Avro fixed.
25 | ///
26 | internal sealed class GuidSerializer : ObjectSerializerBase
27 | {
28 | private readonly ConstructorInfo guidConstructor;
29 |
30 | ///
31 | /// Initializes a new instance of the class.
32 | ///
33 | /// The schema.
34 | /// Schema runtime type is expected to be of type guid.
35 | public GuidSerializer(FixedSchema schema) : base(schema)
36 | {
37 | if (schema.RuntimeType != typeof(Guid))
38 | {
39 | throw new SerializationException("Schema runtime type is expected to be of type guid.");
40 | }
41 |
42 | this.guidConstructor = this.Schema.RuntimeType.GetConstructor(new[] { typeof(byte[]) });
43 | }
44 |
45 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
46 | {
47 | Expression toByteArray = Expression.Call(value, this.Schema.RuntimeType.GetMethod("ToByteArray"));
48 | return Expression.Call(encoder, this.Encode("Fixed"), new[] { toByteArray });
49 | }
50 |
51 | protected override Expression BuildDeserializerSafe(Expression decoder)
52 | {
53 | Expression byteArray = Expression.Call(decoder, Decode("Fixed"), new Expression[] { Expression.Constant(this.Schema.Size) });
54 | return Expression.New(this.guidConstructor, byteArray);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/SequentialReader.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 |
20 | ///
21 | /// Represents a sequential reader of Avro objects.
22 | ///
23 | /// The type of objects.
24 | public sealed class SequentialReader : IDisposable
25 | {
26 | private readonly IAvroReader reader;
27 |
28 | ///
29 | /// Initializes a new instance of the class.
30 | ///
31 | /// The reader.
32 | /// Thrown when is null.
33 | public SequentialReader(IAvroReader reader)
34 | {
35 | if (reader == null)
36 | {
37 | throw new ArgumentNullException("reader");
38 | }
39 |
40 | this.reader = reader;
41 | }
42 |
43 | ///
44 | /// Gets the objects.
45 | ///
46 | public IEnumerable Objects
47 | {
48 | get
49 | {
50 | while (this.reader.MoveNext())
51 | {
52 | using (var block = this.reader.Current)
53 | {
54 | foreach (var record in block.Objects)
55 | {
56 | yield return record;
57 | }
58 | }
59 | }
60 | }
61 | }
62 |
63 | ///
64 | /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
65 | ///
66 | public void Dispose()
67 | {
68 | this.reader.Dispose();
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/IAvroWriter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 | using System.Threading.Tasks;
20 |
21 | ///
22 | /// Represents a writer around Avro object container.
23 | ///
24 | /// The type of objects inside the container.
25 | public interface IAvroWriter : IDisposable
26 | {
27 | ///
28 | /// Sets the metadata.
29 | ///
30 | /// The metadata.
31 | void SetMetadata(IDictionary metadata);
32 |
33 | ///
34 | /// Creates a block asynchronously. The block should be disposed by the user
35 | /// when it is not used anymore.
36 | ///
37 | /// A task returning a new block.
38 | Task> CreateBlockAsync();
39 |
40 | ///
41 | /// Creates a block. The block should be disposed by the user
42 | /// when it is not used anymore.
43 | ///
44 | /// A new block.
45 | IAvroWriterBlock CreateBlock();
46 |
47 | ///
48 | /// Writes the block asynchronously.
49 | ///
50 | /// The block.
51 | /// Task containing the position of the written block.
52 | Task WriteBlockAsync(IAvroWriterBlock block);
53 |
54 | ///
55 | /// Writes the block.
56 | ///
57 | /// The block.
58 | /// The position of the written block.
59 | long WriteBlock(IAvroWriterBlock block);
60 |
61 | ///
62 | /// Closes this instance.
63 | ///
64 | void Close();
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Tools/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | // use this file except in compliance with the License. You may obtain a copy
5 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
6 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
7 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
8 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
9 | // MERCHANTABLITY OR NON-INFRINGEMENT.
10 | // See the Apache Version 2.0 License for specific language governing
11 | // permissions and limitations under the License.
12 | namespace Microsoft.Hadoop.Avro.Tools
13 | {
14 | using System;
15 | using System.Diagnostics.CodeAnalysis;
16 | using System.Linq;
17 |
18 | internal static class Program
19 | {
20 | public static int Main(string[] args)
21 | {
22 | return (int)Run(args, new ExecutionContext());
23 | }
24 |
25 | [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Exceptions are logged to stderr.")]
26 | internal static ExitCode Run(string[] args, IExecutionContext context)
27 | {
28 | try
29 | {
30 | var factory = new CommandFactory();
31 | factory.Create(args[0]).Execute(args.Skip(1).ToArray(), context);
32 | return ExitCode.Success;
33 | }
34 | catch (ToolException exception)
35 | {
36 | context.Error(exception.Message);
37 | if (!string.IsNullOrEmpty(exception.Out))
38 | {
39 | context.Out(exception.Out);
40 | }
41 | return exception.ExitCode;
42 | }
43 | catch (Exception)
44 | {
45 | context.Error(Properties.Resources.InvalidArgsErrorMessage);
46 | context.Out(new HelpCommand().GetCommandsList());
47 | return ExitCode.InvalidArguments;
48 | }
49 | }
50 | }
51 |
52 | ///
53 | /// The exit codes.
54 | ///
55 | internal enum ExitCode
56 | {
57 | ///
58 | /// Indicates program success.
59 | ///
60 | Success = 0x0,
61 |
62 | ///
63 | /// Invalid operation.
64 | ///
65 | InvalidOperation = 0x1,
66 |
67 | ///
68 | /// Invalid arguments are provided by the user.
69 | ///
70 | InvalidArguments = 0xA0
71 | }
72 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/StringSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System.Diagnostics.CodeAnalysis;
18 | using System.Linq.Expressions;
19 | using Microsoft.Hadoop.Avro.Schema;
20 |
21 | ///
22 | /// Serializes C# string as Avro string.
23 | ///
24 | internal sealed class StringSerializer : ObjectSerializerBase
25 | {
26 | public StringSerializer(PrimitiveTypeSchema schema) : base(schema)
27 | {
28 | }
29 |
30 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
31 | {
32 | return Expression.Call(encoder, this.Encode(), new[] { value });
33 | }
34 |
35 | protected override Expression BuildDeserializerSafe(Expression decoder)
36 | {
37 | return Expression.Call(decoder, this.Decode());
38 | }
39 |
40 | protected override Expression BuildSkipperSafe(Expression decoder)
41 | {
42 | return Expression.Call(decoder, this.Skip());
43 | }
44 |
45 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
46 | protected override void SerializeSafe(IEncoder encoder, object @object)
47 | {
48 | encoder.Encode((string)@object);
49 | }
50 |
51 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
52 | protected override object DeserializeSafe(IDecoder decoder)
53 | {
54 | return decoder.DecodeString();
55 | }
56 |
57 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
58 | protected override void SkipSafe(IDecoder decoder)
59 | {
60 | decoder.SkipString();
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/Codec.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using System.IO;
19 |
20 | ///
21 | /// Base class for compression codecs.
22 | ///
23 | public abstract class Codec
24 | {
25 | ///
26 | /// Initializes a new instance of the class.
27 | ///
28 | /// The name of the codec.
29 | /// Thrown if the name is null or empty.
30 | protected Codec(string name)
31 | {
32 | if (string.IsNullOrEmpty(name))
33 | {
34 | throw new ArgumentNullException("name");
35 | }
36 |
37 | this.Name = name;
38 | }
39 |
40 | ///
41 | /// Gets the name of the codec.
42 | ///
43 | public string Name { get; private set; }
44 |
45 | ///
46 | /// Wraps a non-compressed stream with the compressed one.
47 | ///
48 | /// Uncompressed stream.
49 | /// Compressed stream.
50 | public abstract Stream GetCompressedStreamOver(Stream uncompressed);
51 |
52 | ///
53 | /// Wraps a compressed stream with the non-compressed one.
54 | ///
55 | /// Compressed Stream.
56 | /// Non-compressed stream.
57 | public abstract Stream GetDecompressedStreamOver(Stream compressed);
58 |
59 | ///
60 | /// Gets the default deflate codec.
61 | ///
62 | public static Codec Deflate
63 | {
64 | get { return new DeflateCodec(); }
65 | }
66 |
67 | ///
68 | /// Gets the default null codec.
69 | ///
70 | public static Codec Null
71 | {
72 | get { return new NullCodec(); }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/AvroBufferWriterBlock.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using System.IO;
19 |
20 | ///
21 | /// Represents Avro writer block.
22 | ///
23 | /// Type of encoded objects.
24 | internal sealed class AvroBufferWriterBlock : IAvroWriterBlock
25 | {
26 | private readonly IAvroSerializer serializer;
27 | private readonly Stream buffer;
28 | private readonly Stream compressed;
29 | private readonly IEncoder encoder;
30 | private int objectCount;
31 |
32 | public AvroBufferWriterBlock(IAvroSerializer serializer, Codec codec)
33 | {
34 | if (serializer == null)
35 | {
36 | throw new ArgumentNullException("serializer");
37 | }
38 | if (codec == null)
39 | {
40 | throw new ArgumentNullException("codec");
41 | }
42 |
43 | this.serializer = serializer;
44 | this.buffer = new MemoryStream();
45 | this.compressed = codec.GetCompressedStreamOver(this.buffer);
46 | this.encoder = new BufferedBinaryEncoder(this.compressed);
47 | this.objectCount = 0;
48 | }
49 |
50 | public long ObjectCount
51 | {
52 | get { return this.objectCount; }
53 | }
54 |
55 | public void Write(T @object)
56 | {
57 | this.serializer.Serialize(this.encoder, @object);
58 | ++this.objectCount;
59 | }
60 |
61 | public void Flush()
62 | {
63 | this.encoder.Flush();
64 | this.compressed.Flush();
65 | this.compressed.Seek(0, SeekOrigin.Begin);
66 | }
67 |
68 | public Stream Content
69 | {
70 | get { return this.compressed; }
71 | }
72 |
73 | public void Dispose()
74 | {
75 | this.encoder.Dispose();
76 | this.compressed.Dispose();
77 | this.buffer.Dispose();
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/LongSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System.Diagnostics.CodeAnalysis;
18 | using System.Linq.Expressions;
19 | using Microsoft.Hadoop.Avro.Schema;
20 |
21 | ///
22 | /// Serializes C# long/ulong into Avro long.
23 | ///
24 | internal sealed class LongSerializer : ObjectSerializerBase
25 | {
26 | public LongSerializer(LongSchema schema) : base(schema)
27 | {
28 | }
29 |
30 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
31 | {
32 | return Expression.Call(
33 | encoder,
34 | this.Encode(),
35 | new Expression[] { Expression.Convert(value, typeof(long)) });
36 | }
37 |
38 | protected override Expression BuildDeserializerSafe(Expression decoder)
39 | {
40 | return Expression.Convert(
41 | Expression.Call(decoder, this.Decode()),
42 | this.Schema.RuntimeType);
43 | }
44 |
45 | protected override Expression BuildSkipperSafe(Expression decoder)
46 | {
47 | return Expression.Call(decoder, this.Skip());
48 | }
49 |
50 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
51 | protected override void SerializeSafe(IEncoder encoder, object @object)
52 | {
53 | encoder.Encode((long)@object);
54 | }
55 |
56 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
57 | protected override object DeserializeSafe(IDecoder decoder)
58 | {
59 | return decoder.DecodeLong();
60 | }
61 |
62 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
63 | protected override void SkipSafe(IDecoder decoder)
64 | {
65 | decoder.SkipLong();
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/AvroEnum.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | using System;
18 | using System.Diagnostics.CodeAnalysis;
19 | using System.Globalization;
20 |
21 | using Microsoft.Hadoop.Avro.Schema;
22 |
23 | ///
24 | /// Represents Avro enumeration.
25 | ///
26 | [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix", Justification = "Represents Avro enumeration.")]
27 | public sealed class AvroEnum
28 | {
29 | private readonly EnumSchema schema;
30 | private int value;
31 |
32 | ///
33 | /// Initializes a new instance of the class.
34 | ///
35 | /// The schema.
36 | public AvroEnum(Schema.Schema schema)
37 | {
38 | this.schema = schema as EnumSchema;
39 | if (this.schema == null)
40 | {
41 | throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Enum schema expected."), "schema");
42 | }
43 | }
44 |
45 | ///
46 | /// Gets the schema.
47 | ///
48 | public EnumSchema Schema
49 | {
50 | get { return this.schema; }
51 | }
52 |
53 | ///
54 | /// Gets or sets the value.
55 | ///
56 | public string Value
57 | {
58 | get
59 | {
60 | return this.schema.GetSymbolByValue(this.value);
61 | }
62 |
63 | set
64 | {
65 | this.value = this.schema.GetValueBySymbol(value);
66 | }
67 | }
68 |
69 | ///
70 | /// Gets or sets the integer value.
71 | ///
72 | ///
73 | /// The integer value.
74 | ///
75 | public int IntegerValue
76 | {
77 | get
78 | {
79 | return this.value;
80 | }
81 |
82 | set
83 | {
84 | this.value = value;
85 | }
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/BooleanSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System.Diagnostics.CodeAnalysis;
18 | using System.Linq.Expressions;
19 | using Microsoft.Hadoop.Avro.Schema;
20 |
21 | ///
22 | /// Serializers C# boolean into Avro boolean.
23 | ///
24 | internal sealed class BooleanSerializer : ObjectSerializerBase
25 | {
26 | ///
27 | /// Initializes a new instance of the class.
28 | ///
29 | /// The schema.
30 | public BooleanSerializer(BooleanSchema schema) : base(schema)
31 | {
32 | }
33 |
34 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
35 | {
36 | return Expression.Call(encoder, this.Encode(), new[] { value });
37 | }
38 |
39 | protected override Expression BuildDeserializerSafe(Expression decoder)
40 | {
41 | return Expression.Call(decoder, this.Decode());
42 | }
43 |
44 | protected override Expression BuildSkipperSafe(Expression decoder)
45 | {
46 | return Expression.Call(decoder, this.Skip());
47 | }
48 |
49 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
50 | protected override void SerializeSafe(IEncoder encoder, object @object)
51 | {
52 | encoder.Encode((bool)@object);
53 | }
54 |
55 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
56 | protected override object DeserializeSafe(IDecoder decoder)
57 | {
58 | return decoder.DecodeBool();
59 | }
60 |
61 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
62 | protected override void SkipSafe(IDecoder decoder)
63 | {
64 | decoder.SkipBool();
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Encoders/IDecoder.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | ///
18 | /// Defines methods for decoding of basic Avro types.
19 | ///
20 | public interface IDecoder : ISkipper
21 | {
22 | ///
23 | /// Decodes a boolean value.
24 | ///
25 | /// Decoded value.
26 | bool DecodeBool();
27 |
28 | ///
29 | /// Decodes an integer value.
30 | ///
31 | /// Decoded value.
32 | int DecodeInt();
33 |
34 | ///
35 | /// Decodes a long value.
36 | ///
37 | /// Decoded value.
38 | long DecodeLong();
39 |
40 | ///
41 | /// Decodes a float value.
42 | ///
43 | /// Decoded value.
44 | float DecodeFloat();
45 |
46 | ///
47 | /// Decodes a double value.
48 | ///
49 | /// Decoded value.
50 | double DecodeDouble();
51 |
52 | ///
53 | /// Decodes a byte array.
54 | ///
55 | /// Decoded value.
56 | byte[] DecodeByteArray();
57 |
58 | ///
59 | /// Decodes a string value.
60 | ///
61 | /// Decoded value.
62 | string DecodeString();
63 |
64 | ///
65 | /// Decodes a fixed byte array.
66 | ///
67 | /// The size of the array.
68 | /// Decoded array.
69 | byte[] DecodeFixed(int size);
70 |
71 | ///
72 | /// Decodes an array chunk.
73 | ///
74 | /// The size of the current chunk.
75 | int DecodeArrayChunk();
76 |
77 | ///
78 | /// Decodes a map chunk.
79 | ///
80 | /// The size of the current chunk.
81 | int DecodeMapChunk();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Tests/TypeExtensionsTest.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 |
16 | namespace Microsoft.Hadoop.Avro.Tests
17 | {
18 | using System;
19 | using System.Collections.Generic;
20 | using System.Collections.ObjectModel;
21 | using Xunit;
22 |
23 | [Trait("Category","TypeExtensions")]
24 | public class TypeExtensionsTest
25 | {
26 | [Fact]
27 | public void CanBeKnownTypeOfTest()
28 | {
29 | // Object itself could not be known type of any type
30 | Assert.False(typeof(object).CanBeKnownTypeOf(typeof(int)));
31 | Assert.True(typeof(int).CanBeKnownTypeOf(typeof(object)));
32 | Assert.False(typeof(object).CanBeKnownTypeOf(typeof(object)));
33 |
34 | Assert.True(typeof(List).CanBeKnownTypeOf(typeof(IEnumerable)));
35 | Assert.True(typeof(Collection).CanBeKnownTypeOf(typeof(IEnumerable)));
36 | Assert.True(typeof(int[]).CanBeKnownTypeOf(typeof(IEnumerable)));
37 |
38 | Assert.False(typeof(IEnumerable).CanBeKnownTypeOf(typeof(IEnumerable)));
39 | Assert.False(typeof(IEnumerable).CanBeKnownTypeOf(typeof(IEnumerable)));
40 | Assert.False(typeof(IEnumerable).CanBeKnownTypeOf(typeof(IEnumerable)));
41 | Assert.False(typeof(IEnumerable).CanBeKnownTypeOf(typeof(IEnumerable)));
42 | Assert.False(typeof(IList).CanBeKnownTypeOf(typeof(int[])));
43 | Assert.False(typeof(int).CanBeKnownTypeOf(typeof(Guid)));
44 | Assert.False(typeof(IList).CanBeKnownTypeOf(typeof(IList)));
45 |
46 | Assert.False(typeof(int[]).CanBeKnownTypeOf(typeof(IList)));
47 | Assert.False(typeof(int[]).CanBeKnownTypeOf(typeof(IList)));
48 | }
49 |
50 | [Fact]
51 | public void GenericIsAssignableTest()
52 | {
53 | Assert.False(typeof(int[]).GenericIsAssignable(typeof(IDictionary)));
54 | Assert.False(typeof(IList).GenericIsAssignable(typeof(IDictionary)));
55 | Assert.False(typeof(IDictionary).GenericIsAssignable(typeof(IList)));
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/ByteArraySerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System.Diagnostics.CodeAnalysis;
18 | using System.Linq.Expressions;
19 | using Microsoft.Hadoop.Avro.Schema;
20 |
21 | ///
22 | /// Serializers C# byte arrays into Avro byte arrays.
23 | ///
24 | internal sealed class ByteArraySerializer : ObjectSerializerBase
25 | {
26 | ///
27 | /// Initializes a new instance of the class.
28 | ///
29 | /// The schema.
30 | public ByteArraySerializer(BytesSchema schema) : base(schema)
31 | {
32 | }
33 |
34 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
35 | {
36 | return Expression.Call(encoder, this.Encode(), new[] { value });
37 | }
38 |
39 | protected override Expression BuildDeserializerSafe(Expression decoder)
40 | {
41 | return Expression.Call(decoder, this.Decode());
42 | }
43 |
44 | protected override Expression BuildSkipperSafe(Expression decoder)
45 | {
46 | return Expression.Call(decoder, this.Skip());
47 | }
48 |
49 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
50 | protected override void SerializeSafe(IEncoder encoder, object @object)
51 | {
52 | encoder.Encode((byte[])@object);
53 | }
54 |
55 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
56 | protected override object DeserializeSafe(IDecoder decoder)
57 | {
58 | return decoder.DecodeByteArray();
59 | }
60 |
61 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
62 | protected override void SkipSafe(IDecoder decoder)
63 | {
64 | decoder.SkipByteArray();
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/TypeSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 | using Microsoft.Hadoop.Avro.Serializers;
20 |
21 | ///
22 | /// Base class for all type schemas.
23 | /// For more details please see the specification.
24 | ///
25 | public abstract class TypeSchema : Schema
26 | {
27 | private readonly Type runtimeType;
28 |
29 | ///
30 | /// Initializes a new instance of the class.
31 | ///
32 | /// Type of the runtime.
33 | /// The attributes.
34 | protected TypeSchema(Type runtimeType, IDictionary attributes)
35 | : base(attributes)
36 | {
37 | if (runtimeType == null)
38 | {
39 | throw new ArgumentNullException("runtimeType");
40 | }
41 |
42 | this.runtimeType = runtimeType;
43 | }
44 |
45 | ///
46 | /// Gets the runtime type.
47 | ///
48 | public Type RuntimeType
49 | {
50 | get { return this.runtimeType; }
51 | }
52 |
53 | ///
54 | /// Gets the type of the schema as string.
55 | ///
56 | internal abstract string Type { get; }
57 |
58 | ///
59 | /// Gets or sets the builder.
60 | ///
61 | internal IObjectSerializer Serializer { get; set; }
62 |
63 | ///
64 | /// Creates schema from JSON string.
65 | ///
66 | /// The schema.
67 | /// Created schema.
68 | public static TypeSchema Create(string schemaInJson)
69 | {
70 | if (string.IsNullOrEmpty(schemaInJson))
71 | {
72 | throw new ArgumentNullException("schemaInJson");
73 | }
74 | return new JsonSchemaBuilder().BuildSchema(schemaInJson);
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/FloatSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System.Diagnostics.CodeAnalysis;
18 | using System.Linq.Expressions;
19 | using Microsoft.Hadoop.Avro.Schema;
20 |
21 | ///
22 | /// Serializes C# float into Avro float.
23 | ///
24 | internal sealed class FloatSerializer : ObjectSerializerBase
25 | {
26 | ///
27 | /// Initializes a new instance of the class.
28 | ///
29 | /// The schema.
30 | public FloatSerializer(FloatSchema schema) : base(schema)
31 | {
32 | }
33 |
34 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
35 | {
36 | return Expression.Call(encoder, this.Encode(), new Expression[] { Expression.Convert(value, typeof(float)) });
37 | }
38 |
39 | protected override Expression BuildDeserializerSafe(Expression decoder)
40 | {
41 | return Expression.Convert(Expression.Call(decoder, this.Decode()), this.Schema.RuntimeType);
42 | }
43 |
44 | protected override Expression BuildSkipperSafe(Expression decoder)
45 | {
46 | return Expression.Call(decoder, this.Skip());
47 | }
48 |
49 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
50 | protected override void SerializeSafe(IEncoder encoder, object @object)
51 | {
52 | encoder.Encode((float)@object);
53 | }
54 |
55 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
56 | protected override object DeserializeSafe(IDecoder decoder)
57 | {
58 | return decoder.DecodeFloat();
59 | }
60 |
61 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
62 | protected override void SkipSafe(IDecoder decoder)
63 | {
64 | decoder.SkipFloat();
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Utils/GeneratorCore.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Utils
16 | {
17 | using System;
18 | using System.IO;
19 | using System.Text;
20 |
21 | using Microsoft.Hadoop.Avro.Schema;
22 | using Microsoft.Hadoop.Avro.Utils.Templates;
23 |
24 | ///
25 | /// Generates CSharp code from an Avro schema.
26 | ///
27 | internal sealed class GeneratorCore
28 | {
29 | ///
30 | /// Reads the schema and generates the code to the stream.
31 | ///
32 | /// The schema.
33 | /// The default namespace.
34 | /// Determines whether the defaultNamespace should be used.
35 | /// The stream.
36 | public static void Generate(Schema schema, string defaultNamespace, bool forceNamespace, Stream stream)
37 | {
38 | var recordSchema = schema as RecordSchema;
39 | var enumSchema = schema as EnumSchema;
40 | string code;
41 | if (recordSchema != null)
42 | {
43 | code = GenerateCore(recordSchema, defaultNamespace, forceNamespace);
44 | }
45 | else if (enumSchema != null)
46 | {
47 | code = GenerateCore(enumSchema, defaultNamespace, forceNamespace);
48 | }
49 | else
50 | {
51 | throw new ArgumentException("Unsupported schema: only record and enum schemas are supported.");
52 | }
53 |
54 | var encoding = new UTF8Encoding();
55 | byte[] bytes = encoding.GetBytes(code);
56 | stream.Write(bytes, 0, bytes.Length);
57 | }
58 |
59 | private static string GenerateCore(RecordSchema schema, string defaultNamespace, bool forceNamespace)
60 | {
61 | return new ClassTemplate(schema, defaultNamespace, forceNamespace).TransformText();
62 | }
63 |
64 | private static string GenerateCore(EnumSchema schema, string defaultNamespace, bool forceNamespace)
65 | {
66 | return new EnumTemplate(schema, defaultNamespace, forceNamespace).TransformText();
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/AvroBufferReaderBlock.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 | using System.IO;
20 |
21 | ///
22 | /// Represents Avro reader block.
23 | ///
24 | /// Type of encoded objects.
25 | internal sealed class AvroBufferReaderBlock : IAvroReaderBlock
26 | {
27 | private readonly IAvroSerializer serializer;
28 | private readonly Codec codec;
29 | private readonly int objectCount;
30 | private readonly byte[] rawBlock;
31 |
32 | public AvroBufferReaderBlock(IAvroSerializer serializer, Codec codec, byte[] rawBlock, int objectCount)
33 | {
34 | if (serializer == null)
35 | {
36 | throw new ArgumentNullException("serializer");
37 | }
38 | if (codec == null)
39 | {
40 | throw new ArgumentNullException("codec");
41 | }
42 | if (rawBlock == null)
43 | {
44 | throw new ArgumentNullException("rawBlock");
45 | }
46 | if (objectCount < 0)
47 | {
48 | throw new ArgumentOutOfRangeException("objectCount");
49 | }
50 |
51 | this.serializer = serializer;
52 | this.codec = codec;
53 | this.rawBlock = rawBlock;
54 | this.objectCount = objectCount;
55 | }
56 |
57 | public IEnumerable Objects
58 | {
59 | get
60 | {
61 | int remainingObjects = this.objectCount;
62 | using (var buffer = new MemoryStream(this.rawBlock))
63 | using (var decompressedBuffer = this.codec.GetDecompressedStreamOver(buffer))
64 | using (var decoder = new BufferedBinaryDecoder(decompressedBuffer))
65 | {
66 | while (remainingObjects != 0)
67 | {
68 | remainingObjects--;
69 | yield return this.serializer.Deserialize(decoder);
70 | }
71 | }
72 | }
73 | }
74 |
75 | public void Dispose()
76 | {
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/IObjectSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System.Linq.Expressions;
18 |
19 | ///
20 | /// Main interface that allows serialization of an object with generation support.
21 | ///
22 | internal interface IObjectSerializer
23 | {
24 | #region +++Generated serializer+++
25 | ///
26 | /// Builds the serializer.
27 | ///
28 | /// The encoder.
29 | /// The object.
30 | ///
31 | /// Expression that serializes the value into the given encoder.
32 | ///
33 | Expression BuildSerializer(Expression encoder, Expression @object);
34 |
35 | ///
36 | /// Builds the de-serializer.
37 | ///
38 | /// The decoder.
39 | ///
40 | /// Expression that de-serializes the value using the given decoder.
41 | ///
42 | Expression BuildDeserializer(Expression decoder);
43 |
44 | ///
45 | /// Builds a skipper for the corresponding type.
46 | ///
47 | /// The decoder.
48 | ///
49 | /// Expression that skips the value using the given decoder.
50 | ///
51 | Expression BuildSkipper(Expression decoder);
52 | #endregion
53 |
54 | #region +++Runtime serializer+++
55 | ///
56 | /// Serializes the specified object.
57 | ///
58 | /// The encoder.
59 | /// The object.
60 | void Serialize(IEncoder encoder, object @object);
61 |
62 | ///
63 | /// Deserializes the object.
64 | ///
65 | /// The decoder.
66 | /// Deserialized object.
67 | object Deserialize(IDecoder decoder);
68 |
69 | ///
70 | /// Skips the object using the encoder.
71 | ///
72 | /// The decoder.
73 | void Skip(IDecoder decoder);
74 | #endregion
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/IAvroSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | using System.IO;
18 | using Microsoft.Hadoop.Avro.Schema;
19 |
20 | ///
21 | /// Serializes and deserializes an instance of a type into a stream using Avro binary format.
22 | /// Can be used for serialization of C# types attributed with Data Contract/Member attributes
23 | /// as well as AvroRecord with a manually specified schema.
24 | ///
25 | /// Type of objects to serialize, deserialize.
26 | public interface IAvroSerializer
27 | {
28 | ///
29 | /// Gets the schema tree of the reader.
30 | /// Can be different from the writer schema, if some schema update occurred between reading and writing.
31 | ///
32 | TypeSchema ReaderSchema { get; }
33 |
34 | ///
35 | /// Gets the schema tree of the writer.
36 | /// Can be different from the reader schema, if some schema update occurred between reading and writing.
37 | ///
38 | TypeSchema WriterSchema { get; }
39 |
40 | ///
41 | /// Serializes the object into the .
42 | ///
43 | /// The output stream.
44 | /// The object to serialize.
45 | void Serialize(Stream stream, T value);
46 |
47 | ///
48 | /// Serializes the object using the specified .
49 | ///
50 | /// The encoder.
51 | /// The object to serialize.
52 | void Serialize(IEncoder encoder, T value);
53 |
54 | ///
55 | /// Deserializes an object from the .
56 | ///
57 | /// The stream.
58 | /// The deserialized object.
59 | T Deserialize(Stream stream);
60 |
61 | ///
62 | /// Deserializes an object from the specified .
63 | ///
64 | /// The decoder.
65 | /// The deserialized object.
66 | T Deserialize(IDecoder decoder);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/DoubleSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System.Diagnostics.CodeAnalysis;
18 | using System.Linq.Expressions;
19 | using Microsoft.Hadoop.Avro.Schema;
20 |
21 | ///
22 | /// Serializes C# double into Avro double type.
23 | ///
24 | internal sealed class DoubleSerializer : ObjectSerializerBase
25 | {
26 | ///
27 | /// Initializes a new instance of the class.
28 | ///
29 | /// The schema.
30 | public DoubleSerializer(DoubleSchema schema) : base(schema)
31 | {
32 | }
33 |
34 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
35 | {
36 | return Expression.Call(
37 | encoder,
38 | this.Encode(),
39 | new Expression[] { Expression.Convert(value, typeof(double)) });
40 | }
41 |
42 | protected override Expression BuildDeserializerSafe(Expression decoder)
43 | {
44 | return Expression.Convert(
45 | Expression.Call(decoder, this.Decode()),
46 | this.Schema.RuntimeType);
47 | }
48 |
49 | protected override Expression BuildSkipperSafe(Expression decoder)
50 | {
51 | return Expression.Call(decoder, this.Skip());
52 | }
53 |
54 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
55 | protected override void SerializeSafe(IEncoder encoder, object @object)
56 | {
57 | encoder.Encode((double)@object);
58 | }
59 |
60 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
61 | protected override object DeserializeSafe(IDecoder decoder)
62 | {
63 | return decoder.DecodeDouble();
64 | }
65 |
66 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
67 | protected override void SkipSafe(IDecoder decoder)
68 | {
69 | decoder.SkipDouble();
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Resources/StringResources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18052
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Microsoft.Hadoop.Avro.Resources {
12 | using System.Reflection;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class StringResources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal StringResources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp =
43 | new global::System.Resources.ResourceManager("Microsoft.Hadoop.Avro.Resources.StringResources", typeof(StringResources).GetTypeInfo().Assembly);
44 | resourceMan = temp;
45 | }
46 | return resourceMan;
47 | }
48 | }
49 |
50 | ///
51 | /// Overrides the current thread's CurrentUICulture property for all
52 | /// resource lookups using this strongly typed resource class.
53 | ///
54 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
55 | internal static global::System.Globalization.CultureInfo Culture {
56 | get {
57 | return resourceCulture;
58 | }
59 | set {
60 | resourceCulture = value;
61 | }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/IFieldSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System.Linq.Expressions;
18 |
19 | ///
20 | /// Main interface that allows building a serializer/de-serializer using expressions.
21 | ///
22 | internal interface IFieldSerializer
23 | {
24 | #region +++Generated serializer+++
25 | ///
26 | /// Builds the serializer.
27 | ///
28 | /// The encoder.
29 | /// The object.
30 | ///
31 | /// Expression that serializes the value into the given encoder.
32 | ///
33 | Expression BuildSerializer(Expression encoder, Expression @object);
34 |
35 | ///
36 | /// Builds the de-serializer.
37 | ///
38 | /// The decoder.
39 | /// The object.
40 | ///
41 | /// Expression that de-serializes the value using the given decoder.
42 | ///
43 | Expression BuildDeserializer(Expression decoder, Expression @object);
44 |
45 | ///
46 | /// Builds a skipper for the corresponding type.
47 | ///
48 | /// The decoder.
49 | /// Expression that skips the value using the given decoder.
50 | Expression BuildSkipper(Expression decoder);
51 | #endregion
52 |
53 | #region +++Runtime serializer+++
54 | ///
55 | /// Serializes the specified object.
56 | ///
57 | /// The encoder.
58 | /// The object.
59 | void Serialize(IEncoder encoder, object @object);
60 |
61 | ///
62 | /// Deserializes the object.
63 | ///
64 | /// The decoder.
65 | /// The object.
66 | void Deserialize(IDecoder decoder, object @object);
67 |
68 | ///
69 | /// Skips the object using the encoder.
70 | ///
71 | /// The decoder.
72 | void Skip(IDecoder decoder);
73 | #endregion
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/NullSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System.Diagnostics.CodeAnalysis;
18 | using System.Globalization;
19 | using System.Linq.Expressions;
20 | using System.Runtime.Serialization;
21 | using Microsoft.Hadoop.Avro.Schema;
22 |
23 | internal sealed class NullSerializer : ObjectSerializerBase
24 | {
25 | public NullSerializer(NullSchema schema) : base(schema)
26 | {
27 | }
28 |
29 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
30 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
31 | {
32 | return Expression.IfThen(
33 | Expression.NotEqual(value, Expression.Constant(null, value.Type)),
34 | Expression.Throw(Expression.Constant(new SerializationException()), typeof(SerializationException)));
35 | }
36 |
37 | protected override Expression BuildDeserializerSafe(Expression decoder)
38 | {
39 | if (this.Schema.RuntimeType.CanContainNull())
40 | {
41 | return Expression.Constant(null, this.Schema.RuntimeType);
42 | }
43 |
44 | var exception = new SerializationException(
45 | string.Format(
46 | CultureInfo.InvariantCulture,
47 | "Unexpected null value for the object of type '{0}'. Please check the schema.",
48 | this.Schema.RuntimeType));
49 | return Expression.Throw(Expression.Constant(exception), this.Schema.RuntimeType);
50 | }
51 |
52 | protected override Expression BuildSkipperSafe(Expression decoder)
53 | {
54 | return Expression.Empty();
55 | }
56 |
57 | protected override void SerializeSafe(IEncoder encoder, object @object)
58 | {
59 | if (@object != null)
60 | {
61 | throw new SerializationException(string.Format(CultureInfo.InvariantCulture, "Not null object is serialized as null."));
62 | }
63 | }
64 |
65 | protected override object DeserializeSafe(IDecoder decoder)
66 | {
67 | return null;
68 | }
69 |
70 | protected override void SkipSafe(IDecoder decoder)
71 | {
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/IntSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System;
18 | using System.Diagnostics.CodeAnalysis;
19 | using System.Globalization;
20 | using System.Linq.Expressions;
21 | using Microsoft.Hadoop.Avro.Schema;
22 |
23 | ///
24 | /// Serializes C# int/short/byte/u... into Avro int.
25 | ///
26 | internal sealed class IntSerializer : ObjectSerializerBase
27 | {
28 | public IntSerializer(IntSchema schema) : base(schema)
29 | {
30 | }
31 |
32 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
33 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
34 | {
35 | return Expression.Call(
36 | encoder,
37 | this.Encode(),
38 | new[]
39 | {
40 | value.Type == typeof(int) ? value : Expression.Convert(value, typeof(int))
41 | });
42 | }
43 |
44 | protected override Expression BuildDeserializerSafe(Expression decoder)
45 | {
46 | return Expression.Convert(Expression.Call(decoder, this.Decode()), this.Schema.RuntimeType);
47 | }
48 |
49 | protected override Expression BuildSkipperSafe(Expression decoder)
50 | {
51 | return Expression.Call(decoder, this.Skip());
52 | }
53 |
54 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
55 | protected override void SerializeSafe(IEncoder encoder, object @object)
56 | {
57 | encoder.Encode(Convert.ToInt32(@object, CultureInfo.InvariantCulture));
58 | }
59 |
60 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
61 | protected override object DeserializeSafe(IDecoder decoder)
62 | {
63 | return decoder.DecodeInt();
64 | }
65 |
66 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Internal + done in base class.")]
67 | protected override void SkipSafe(IDecoder decoder)
68 | {
69 | decoder.SkipInt();
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Utils/Templates/ClassTemplate.tt:
--------------------------------------------------------------------------------
1 | <#@ template language="C#" linePragmas="false" visibility="internal"#>
2 | <#@ import namespace="System" #>
3 | <#@ import namespace="System.Collections.Generic" #>
4 | <#@ import namespace="System.Globalization" #>
5 | <#@ import namespace="System.Linq" #>
6 | <#@ import namespace="Microsoft.Hadoop.Avro.Schema" #>
7 | //
8 | namespace <#= Utilities.GetNamespace(this, this.Schema.Namespace) #>
9 | {
10 | using System;
11 | using System.Collections.Generic;
12 | using System.Runtime.Serialization;
13 | using Microsoft.Hadoop.Avro;
14 |
15 | ///
16 | /// Used to serialize and deserialize Avro record <#= Utilities.Validate(this.Schema.FullName) #>.
17 | ///
18 | [DataContract(Namespace = "<#= this.Schema.Namespace #>")]<# GenerateKnownTypesAttributes(((RecordSchema)this.Schema).Fields); #>
19 |
20 | public partial class <#= Utilities.Validate(this.Schema.Name) #>
21 | {
22 | private const string JsonSchema = @"<#= this.Schema.ToString().Replace("\"", "\"\"") #>";
23 |
24 | ///
25 | /// Gets the schema.
26 | ///
27 | public static string Schema
28 | {
29 | get
30 | {
31 | return JsonSchema;
32 | }
33 | }
34 | <# foreach (var field in ((RecordSchema)this.Schema).Fields)
35 | {
36 | #>
37 | ///
38 | /// Gets or sets the <#= field.Name #> field.
39 | ///
40 | [DataMember]<# GenerateTypeAttributes(field.TypeSchema); #>
41 |
42 | public <# GenerateType(field.TypeSchema, true, false, false); #> <#= field.Name #> { get; set; }
43 | <#
44 | }
45 | #>
46 |
47 | ///
48 | /// Initializes a new instance of the class.
49 | ///
50 | public <#= this.Schema.Name #>()
51 | {
52 | <# foreach (var field in ((RecordSchema)this.Schema).Fields)
53 | {
54 | if(field.HasDefaultValue)
55 | {
56 | #> this.<#=field.Name#> = <# GenerateDefaultValue(field.TypeSchema, field.DefaultValue); #>;
57 | <# }
58 | } #>
59 | }
60 | <# if(((RecordSchema)this.Schema).Fields.Any()) { #>
61 |
62 | ///
63 | /// Initializes a new instance of the class.
64 | ///
65 | <# foreach (var field in ((RecordSchema)this.Schema).Fields)
66 | {
67 | #> /// The <#=field.Name.FirstLetterToLower()#>.
68 | <#
69 | }#> public <#= this.Schema.Name #>(<# var count = ((RecordSchema)this.Schema).Fields.Count; foreach (var field in ((RecordSchema)this.Schema).Fields) { GenerateType(field.TypeSchema, true, false, false);#> <#=field.Name.FirstLetterToLower()#><#if(--count > 0) #>, <#; }#>)
70 | {
71 | <# foreach (var field in ((RecordSchema)this.Schema).Fields)
72 | {
73 | #> this.<#=field.Name#> = <#=field.Name.FirstLetterToLower()#>;
74 | <# } #>
75 | }
76 | <#}#>
77 | }
78 | }
79 | <#@ include file="Utilities/TypeTemplate.ttinclude" #>
80 | <#@ include file="Utilities/DefaultValueTemplate.ttinclude" #>
--------------------------------------------------------------------------------
/external/protobuf.net/r602/WhatFilesDoNeed.txt:
--------------------------------------------------------------------------------
1 | protobuf-net can be used on multiple platforms, and many different builds are available.
2 |
3 | In particular, though, there are 2 main uses:
4 |
5 | - the "full" version, which includes as much type-model / runtime support as will work on your chosen platform
6 | - the "core only" version, which includes just the fundamental reader/writer API and core objects
7 |
8 | If you are on a rich framework like full .NET, the "full" version is entirely appropriate and will work fine.
9 |
10 | However, if you are on a restricted framework (Silverlight, Phone 7, WinRT, etc) then many operations would either
11 | be slow, or impossible. To address this, protobuf-net provides these frameworks with a "precompile" facility,
12 | which moves all of the impossible / slow steps to a build-time operation, emitting a serialiation dll you
13 | can reference and use (now very fast etc) from your chosen framework.
14 |
15 | More information about the precompiler is here:
16 | http://marcgravell.blogspot.co.uk/2012/07/introducing-protobuf-net-precompiler.html
17 |
18 | protobuf-net also includes a utility for processing ".proto" files (the schema DSL used by multiple protobuf
19 | implementations) into C# and VB.NET; this is the ProtoGen tool.
20 |
21 | Neither precompile nor ProtoGen need to be deployed with your application.
22 |
23 |
24 | So: what do I need?
25 |
26 | example: running on .NET 4.0
27 |
28 | solution: copy the files from Full\net30. Note that protobuf-net does not require any 4.0 features, so using "net30" will
29 | give you all of protobuf-net including WCF support (which is the difference between "net20" and "net30").
30 |
31 |
32 | example: running on Silverlight 4
33 |
34 | option 1: copy the files from Full\sl4, and accept that it isn't quite as optimal as it could be - but perfectly fine
35 | for light-to-moderate serialization usage.
36 |
37 | option 2: copy the files from CoreOnly\sl4, and use "precompile" (in the Precompile folder) at build-time to generate
38 | a serialization assembly (this also needs to be referenced and deployed from you application).
39 |
40 | Additional:
41 |
42 | Note that each framework contains 3 files:
43 |
44 | - protobuf-net.dll the library itself
45 | - protobuf-net.xml intellisense xml, used by thre IDE when developing
46 | - protobuf-net.pdb debugging symbols, useful when debugging
47 |
48 | Of these - the only one you **need** to deploy is the dll; the pdb may be useful for investigating crash reports. The
49 | xml is used only by the IDE.
50 |
51 | Folders:
52 |
53 | cf20 compact framework 2.0
54 | cf35 compact framework 3.5
55 | ios iPad/iPod/iPhone via MonoTouch
56 | net11 regular .NET 1.1 (excluded generics)
57 | net20 regular .NET 2.0 (excludes WCF hooks)
58 | net30 regular .NET 3.0 or above (including 3.5, 4.0, 4.5, ...)
59 | netcore45 windows store apps / windows runtime 4.5
60 | portable portable class library (phone 7, xna, silverlight)
61 | sl4 silverlight 4 or above
62 | wp71 windows phone 7.1
63 | unity specific to unity (avoids missing "interlocked" methods)
64 |
65 | License:
66 |
67 | The full license is shown separately, but boils down to "do what you like with it, don't sue me,
68 | don't blame me if it goes horribly wrong, don't claim you wrote protobuf-net"
69 |
70 | Finally:
71 |
72 | All feedback welcome.
--------------------------------------------------------------------------------
/external/protobuf.net/r602/What Files Do I Need.txt:
--------------------------------------------------------------------------------
1 | protobuf-net can be used on multiple platforms, and many different builds are available.
2 |
3 | In particular, though, there are 2 main uses:
4 |
5 | - the "full" version, which includes as much type-model / runtime support as will work on your chosen platform
6 | - the "core only" version, which includes just the fundamental reader/writer API and core objects
7 |
8 | If you are on a rich framework like full .NET, the "full" version is entirely appropriate and will work fine.
9 |
10 | However, if you are on a restricted framework (Silverlight, Phone 7, WinRT, etc) then many operations would either
11 | be slow, or impossible. To address this, protobuf-net provides these frameworks with a "precompile" facility,
12 | which moves all of the impossible / slow steps to a build-time operation, emitting a serialiation dll you
13 | can reference and use (now very fast etc) from your chosen framework.
14 |
15 | More information about the precompiler is here:
16 | http://marcgravell.blogspot.co.uk/2012/07/introducing-protobuf-net-precompiler.html
17 |
18 | protobuf-net also includes a utility for processing ".proto" files (the schema DSL used by multiple protobuf
19 | implementations) into C# and VB.NET; this is the ProtoGen tool.
20 |
21 | Neither precompile nor ProtoGen need to be deployed with your application.
22 |
23 |
24 | So: what do I need?
25 |
26 | example: running on .NET 4.0
27 |
28 | solution: copy the files from Full\net30. Note that protobuf-net does not require any 4.0 features, so using "net30" will
29 | give you all of protobuf-net including WCF support (which is the difference between "net20" and "net30").
30 |
31 |
32 | example: running on Silverlight 4
33 |
34 | option 1: copy the files from Full\sl4, and accept that it isn't quite as optimal as it could be - but perfectly fine
35 | for light-to-moderate serialization usage.
36 |
37 | option 2: copy the files from CoreOnly\sl4, and use "precompile" (in the Precompile folder) at build-time to generate
38 | a serialization assembly (this also needs to be referenced and deployed from you application).
39 |
40 | Additional:
41 |
42 | Note that each framework contains 3 files:
43 |
44 | - protobuf-net.dll the library itself
45 | - protobuf-net.xml intellisense xml, used by thre IDE when developing
46 | - protobuf-net.pdb debugging symbols, useful when debugging
47 |
48 | Of these - the only one you **need** to deploy is the dll; the pdb may be useful for investigating crash reports. The
49 | xml is used only by the IDE.
50 |
51 | Folders:
52 |
53 | cf20 compact framework 2.0
54 | cf35 compact framework 3.5
55 | ios iPad/iPod/iPhone via MonoTouch
56 | net11 regular .NET 1.1 (excluded generics)
57 | net20 regular .NET 2.0 (excludes WCF hooks)
58 | net30 regular .NET 3.0 or above (including 3.5, 4.0, 4.5, ...)
59 | netcore45 windows store apps / windows runtime 4.5
60 | portable portable class library (phone 7, xna, silverlight)
61 | sl4 silverlight 4 or above
62 | wp71 windows phone 7.1
63 | unity specific to unity (avoids missing "interlocked" methods)
64 |
65 | License:
66 |
67 | The full license is shown separately, but boils down to "do what you like with it, don't sue me,
68 | don't blame me if it goes horribly wrong, don't claim you wrote protobuf-net"
69 |
70 | Finally:
71 |
72 | All feedback welcome.
--------------------------------------------------------------------------------
/Microsoft.Avro.Tests/MockExecutionContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | // use this file except in compliance with the License. You may obtain a copy
5 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
6 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
7 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
8 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
9 | // MERCHANTABLITY OR NON-INFRINGEMENT.
10 | // See the Apache Version 2.0 License for specific language governing
11 | // permissions and limitations under the License.
12 |
13 | namespace Microsoft.Hadoop.Avro.Tests
14 | {
15 | using System;
16 | using System.IO;
17 | using System.Text;
18 |
19 | using Microsoft.Hadoop.Avro.Tools;
20 |
21 | internal sealed class MockExecutionContext : IExecutionContext
22 | {
23 | public static string ErrorMessage { get; set; }
24 |
25 | public static string OutMessage { get; private set; }
26 |
27 | public static string FileToRead { get; private set; }
28 |
29 | public static string FileToReadContent { get; set; }
30 |
31 | public static string FileToWrite { get; private set; }
32 |
33 | public static string FileToWriteContent { get; private set; }
34 |
35 | public static string DirectoryToSet { get; set; }
36 |
37 | public static Exception OnReadException { get; set; }
38 |
39 | public static Exception OnWriteException { get; set; }
40 |
41 | public static Exception OnSetDirectoryException { get; set; }
42 |
43 | public static void Initialize()
44 | {
45 | ErrorMessage = null;
46 | OutMessage = null;
47 | FileToRead = null;
48 | FileToReadContent = null;
49 | FileToWrite = null;
50 | FileToWriteContent = null;
51 | DirectoryToSet = null;
52 | OnReadException = null;
53 | OnWriteException = null;
54 | OnSetDirectoryException = null;
55 | }
56 |
57 | public void Error(string message)
58 | {
59 | ErrorMessage += message;
60 | }
61 |
62 | public void Out(string message)
63 | {
64 | OutMessage += message;
65 | }
66 |
67 | public string ReadFile(string filePath)
68 | {
69 | FileToRead = filePath;
70 | if (OnReadException != null)
71 | {
72 | throw OnReadException;
73 | }
74 | return FileToReadContent;
75 | }
76 |
77 | public void WriteFile(string filePath, Stream stream)
78 | {
79 | FileToWrite = filePath;
80 | stream.Seek(0, SeekOrigin.Begin);
81 | FileToWriteContent = new StreamReader(stream, Encoding.Unicode).ReadToEnd();
82 | if (OnWriteException != null)
83 | {
84 | throw OnWriteException;
85 | }
86 | }
87 |
88 | public void SetOutputDirectory(string directoryPath)
89 | {
90 | DirectoryToSet = directoryPath;
91 | if (OnSetDirectoryException != null)
92 | {
93 | throw OnSetDirectoryException;
94 | }
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Tests/TestClasses/AvroCustomContractResolver.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Tests
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 |
20 | ///
21 | /// Allows using standard and
22 | /// attributes for defining what types/properties/fields
23 | /// should be serialized.
24 | ///
25 | public class AvroCustomContractResolver : AvroDataContractResolver
26 | {
27 | ///
28 | /// Gets the known types out of an abstract type or interface that could be present in the tree of
29 | /// objects serialized with this contract resolver.
30 | ///
31 | /// The abstract type.
32 | ///
33 | /// An enumerable of known types.
34 | ///
35 | /// The type argument is null.
36 | public override IEnumerable GetKnownTypes(Type type)
37 | {
38 | if (type == null)
39 | {
40 | throw new ArgumentNullException("type");
41 | }
42 |
43 | if (type == typeof (object))
44 | {
45 | return new HashSet {typeof (int), typeof (string)};
46 | }
47 |
48 | return new HashSet(type.GetAllKnownTypes());
49 | }
50 |
51 | ///
52 | /// Gets the serialization information about the type.
53 | /// This information is used for creation of the corresponding schema node.
54 | ///
55 | /// The type to resolve.
56 | ///
57 | /// Serialization information about the type.
58 | ///
59 | /// The type argument is null.
60 | public override TypeSerializationInfo ResolveType(Type type)
61 | {
62 | if (type == null)
63 | {
64 | throw new ArgumentNullException("type");
65 | }
66 |
67 | if (type == typeof (object))
68 | {
69 | return new TypeSerializationInfo
70 | {
71 | Name = StripAvroNonCompatibleCharacters(type.AvroSchemaName()),
72 | Namespace = StripAvroNonCompatibleCharacters(type.Namespace),
73 | Nullable = false
74 | };
75 | }
76 |
77 | return base.ResolveType(type);
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/IAvroSurrogate.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | using System;
18 |
19 | ///
20 | /// Provides the methods needed to substitute one type for another by the IAvroSerializer
21 | /// during serialization and deserialization of C# types.
22 | ///
23 | public interface IAvroSurrogate
24 | {
25 | ///
26 | /// During serialization deserialization returns a type that substitutes the specified type.
27 | ///
28 | /// The CLR type to substitute.
29 | ///
30 | /// The to substitute for the value. This type must be serializable by the . For example, it must be marked with the attribute or other mechanisms that the serializer recognizes.
31 | ///
32 | Type GetSurrogateType(Type type);
33 |
34 | ///
35 | /// During deserialization, returns an object that is a substitute for the specified object.
36 | ///
37 | /// The deserialized object to be substituted.
38 | /// The that the substituted object should be assigned to.
39 | ///
40 | /// The substituted deserialized object. This object must be of a type that is serializable by the . For example, it must be marked with the attribute or other mechanisms that the serializer recognizes.
41 | ///
42 | object GetDeserializedObject(object obj, Type targetType);
43 |
44 | ///
45 | /// During serialization returns an object that substitutes the specified object.
46 | ///
47 | /// The object to substitute.
48 | /// The that the substituted object should be assigned to.
49 | ///
50 | /// The substituted object that will be serialized. The object must be serializable by the . For example, it must be marked with the attribute or other mechanisms that the serializer recognizes.
51 | ///
52 | object GetObjectToSerialize(object obj, Type targetType);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/NamedSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 | using System.Collections.ObjectModel;
20 |
21 | ///
22 | /// Class representing an named schema: record, enumeration or fixed.
23 | /// For more details please see the specification.
24 | ///
25 | public abstract class NamedSchema : TypeSchema
26 | {
27 | private readonly NamedEntityAttributes attributes;
28 |
29 | ///
30 | /// Initializes a new instance of the class.
31 | ///
32 | /// The name attributes.
33 | /// Type of the runtime.
34 | /// The attributes.
35 | internal NamedSchema(
36 | NamedEntityAttributes nameAttributes,
37 | Type runtimeType,
38 | Dictionary attributes)
39 | : base(runtimeType, attributes)
40 | {
41 | if (nameAttributes == null)
42 | {
43 | throw new ArgumentNullException("nameAttributes");
44 | }
45 |
46 | this.attributes = nameAttributes;
47 | }
48 |
49 | ///
50 | /// Gets the full name.
51 | ///
52 | public string FullName
53 | {
54 | get { return this.attributes.Name.FullName; }
55 | }
56 |
57 | ///
58 | /// Gets the name.
59 | ///
60 | public string Name
61 | {
62 | get { return this.attributes.Name.Name; }
63 | }
64 |
65 | ///
66 | /// Gets the namespace.
67 | ///
68 | public string Namespace
69 | {
70 | get { return this.attributes.Name.Namespace; }
71 | }
72 |
73 | ///
74 | /// Gets the aliases.
75 | ///
76 | public ReadOnlyCollection Aliases
77 | {
78 | get { return this.attributes.Aliases.AsReadOnly(); }
79 | }
80 |
81 | ///
82 | /// Gets the doc.
83 | ///
84 | public string Doc
85 | {
86 | get { return this.attributes.Doc; }
87 | }
88 |
89 | ///
90 | /// Gets the type of the schema as string.
91 | ///
92 | internal override string Type
93 | {
94 | get { return this.FullName; }
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/FixedSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 | using Newtonsoft.Json;
20 |
21 | ///
22 | /// Represents a fixed schema.
23 | /// For more details please see the specification.
24 | ///
25 | public sealed class FixedSchema : NamedSchema
26 | {
27 | private readonly int size;
28 |
29 | internal FixedSchema(NamedEntityAttributes namedEntityAttributes, int size, Type runtimeType)
30 | : this(namedEntityAttributes, size, runtimeType, new Dictionary())
31 | {
32 | }
33 |
34 | ///
35 | /// Initializes a new instance of the class.
36 | ///
37 | /// The named schema attributes.
38 | /// The size.
39 | /// Type of the runtime.
40 | /// The attributes.
41 | internal FixedSchema(
42 | NamedEntityAttributes namedEntityAttributes,
43 | int size,
44 | Type runtimeType,
45 | Dictionary attributes) : base(namedEntityAttributes, runtimeType, attributes)
46 | {
47 | if (size <= 0)
48 | {
49 | throw new ArgumentOutOfRangeException("size");
50 | }
51 |
52 | this.size = size;
53 | }
54 |
55 | ///
56 | /// Gets the size.
57 | ///
58 | public int Size
59 | {
60 | get { return this.size; }
61 | }
62 |
63 | ///
64 | /// Converts current not to JSON according to the avro specification.
65 | ///
66 | /// The writer.
67 | /// The seen schemas.
68 | internal override void ToJsonSafe(JsonTextWriter writer, HashSet seenSchemas)
69 | {
70 | if (seenSchemas.Contains(this))
71 | {
72 | writer.WriteValue(this.FullName);
73 | return;
74 | }
75 |
76 | seenSchemas.Add(this);
77 | writer.WriteStartObject();
78 | writer.WriteProperty("type", "fixed");
79 | writer.WriteProperty("name", this.FullName);
80 | writer.WriteOptionalProperty("aliases", this.Aliases);
81 | writer.WriteProperty("size", this.Size);
82 | writer.WriteEndObject();
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/ArraySchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 | using Newtonsoft.Json;
20 |
21 | ///
22 | /// Schema representing an array.
23 | /// For more details please see the specification.
24 | ///
25 | public sealed class ArraySchema : TypeSchema
26 | {
27 | private readonly TypeSchema itemSchema;
28 |
29 | ///
30 | /// Initializes a new instance of the class.
31 | ///
32 | /// The item.
33 | /// Type of the runtime.
34 | /// The attributes.
35 | internal ArraySchema(
36 | TypeSchema item,
37 | Type runtimeType,
38 | Dictionary attributes)
39 | : base(runtimeType, attributes)
40 | {
41 | if (item == null)
42 | {
43 | throw new ArgumentNullException("item");
44 | }
45 |
46 | this.itemSchema = item;
47 | }
48 |
49 | ///
50 | /// Initializes a new instance of the class.
51 | ///
52 | /// The item.
53 | /// Type of the runtime.
54 | internal ArraySchema(
55 | TypeSchema item,
56 | Type runtimeType)
57 | : this(item, runtimeType, new Dictionary())
58 | {
59 | }
60 |
61 | ///
62 | /// Gets the item schema.
63 | ///
64 | public TypeSchema ItemSchema
65 | {
66 | get { return this.itemSchema; }
67 | }
68 |
69 | ///
70 | /// Converts current not to JSON according to the avro specification.
71 | ///
72 | /// The writer.
73 | /// The seen schemas.
74 | internal override void ToJsonSafe(JsonTextWriter writer, HashSet seenSchemas)
75 | {
76 | writer.WriteStartObject();
77 | writer.WriteProperty("type", "array");
78 | writer.WritePropertyName("items");
79 | this.itemSchema.ToJson(writer, seenSchemas);
80 | writer.WriteEndObject();
81 | }
82 |
83 | ///
84 | /// Gets the type of the schema as string.
85 | ///
86 | internal override string Type
87 | {
88 | get { return Token.Array; }
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Encoders/IEncoder.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro
16 | {
17 | using System;
18 | using System.IO;
19 |
20 | ///
21 | /// Defines methods for encoding of basic Avro types.
22 | ///
23 | public interface IEncoder : IDisposable
24 | {
25 | ///
26 | /// Encodes a boolean value.
27 | ///
28 | /// Value to encode.
29 | void Encode(bool value);
30 |
31 | ///
32 | /// Encodes an integer value.
33 | ///
34 | /// Value to encode.
35 | void Encode(int value);
36 |
37 | ///
38 | /// Encodes a long value.
39 | ///
40 | /// Value to encode.
41 | void Encode(long value);
42 |
43 | ///
44 | /// Encodes a float value.
45 | ///
46 | /// Value to encode.
47 | void Encode(float value);
48 |
49 | ///
50 | /// Encodes a double value.
51 | ///
52 | /// Value to encode.
53 | void Encode(double value);
54 |
55 | ///
56 | /// Encodes a byte array as bytes Avro type.
57 | ///
58 | /// Value to encode.
59 | void Encode(byte[] value);
60 |
61 | ///
62 | /// Encodes a string value.
63 | ///
64 | /// Value to encode.
65 | void Encode(string value);
66 |
67 | ///
68 | /// Encodes a byte array as fixed Avro type.
69 | ///
70 | /// The value.
71 | void EncodeFixed(byte[] value);
72 |
73 | ///
74 | /// Encodes an array chunk of .
75 | ///
76 | /// The chunk size.
77 | void EncodeArrayChunk(int size);
78 |
79 | ///
80 | /// Encodes a map chunk of .
81 | ///
82 | /// Chunk size.
83 | void EncodeMapChunk(int size);
84 |
85 | ///
86 | /// Encodes a stream as bytes Avro type.
87 | ///
88 | /// The stream.
89 | void Encode(Stream stream);
90 |
91 | ///
92 | /// Clears all buffers for this encoder and causes any buffered data to be written to
93 | /// the underlying stream/device.
94 | ///
95 | void Flush();
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Container/DecompressionStream.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Container
16 | {
17 | using System;
18 | using System.IO;
19 | using System.IO.Compression;
20 |
21 | ///
22 | /// Wrapper around a stream supporting decompression on read.
23 | ///
24 | internal sealed class DecompressionStream : Stream
25 | {
26 | private readonly DeflateStream decompressed;
27 |
28 | public DecompressionStream(Stream compressed)
29 | {
30 | this.decompressed = new DeflateStream(compressed, CompressionMode.Decompress, true);
31 | }
32 |
33 | public override bool CanRead
34 | {
35 | get { return true; }
36 | }
37 |
38 | public override bool CanSeek
39 | {
40 | get { return true; }
41 | }
42 |
43 | public override bool CanWrite
44 | {
45 | get { return false; }
46 | }
47 |
48 | public override void Flush()
49 | {
50 | this.decompressed.Dispose();
51 | }
52 |
53 | public override long Length
54 | {
55 | get { return this.decompressed.Length; }
56 | }
57 |
58 | public override long Position
59 | {
60 | get
61 | {
62 | return this.decompressed.Position;
63 | }
64 |
65 | set
66 | {
67 | throw new NotSupportedException();
68 | }
69 | }
70 |
71 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Validated in base", MessageId = "0")]
72 | public override int Read(byte[] buffer, int offset, int count)
73 | {
74 | return this.decompressed.Read(buffer, offset, count);
75 | }
76 |
77 | public override long Seek(long offset, SeekOrigin origin)
78 | {
79 | throw new NotSupportedException();
80 | }
81 |
82 | public override void SetLength(long value)
83 | {
84 | throw new NotSupportedException();
85 | }
86 |
87 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Validated in base", MessageId = "0")]
88 | public override void Write(byte[] buffer, int offset, int count)
89 | {
90 | throw new NotSupportedException();
91 | }
92 |
93 | protected override void Dispose(bool disposing)
94 | {
95 | base.Dispose(disposing);
96 |
97 | if (disposing)
98 | {
99 | this.decompressed.Dispose();
100 | }
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Serializers/SurrogateSerializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Serializers
16 | {
17 | using System;
18 | using System.Linq.Expressions;
19 | using System.Reflection;
20 | using Microsoft.Hadoop.Avro.Schema;
21 |
22 | ///
23 | /// Surrogate serializer.
24 | ///
25 | internal sealed class SurrogateSerializer : ObjectSerializerBase
26 | {
27 | private readonly AvroSerializerSettings settings;
28 |
29 | ///
30 | /// Initializes a new instance of the class.
31 | ///
32 | /// The settings.
33 | /// The schema.
34 | public SurrogateSerializer(AvroSerializerSettings settings, SurrogateSchema schema) : base(schema)
35 | {
36 | if (settings == null)
37 | {
38 | throw new ArgumentNullException("settings");
39 | }
40 | this.settings = settings;
41 | }
42 |
43 | protected override Expression BuildSerializerSafe(Expression encoder, Expression value)
44 | {
45 | var surrogate = Expression.Constant(this.settings.Surrogate);
46 | MethodInfo serialize = typeof(IAvroSurrogate).GetMethod("GetObjectToSerialize");
47 |
48 | Expression castValue = this.Schema.RuntimeType.GetTypeInfo().IsValueType ? Expression.Convert(value, typeof(object)) : value;
49 |
50 | Expression obj = Expression.TypeAs(
51 | Expression.Call(surrogate, serialize, new[] { castValue, Expression.Constant(this.Schema.SurrogateType) }),
52 | this.Schema.SurrogateType);
53 |
54 | var tmp = Expression.Variable(this.Schema.SurrogateType, Guid.NewGuid().ToString());
55 | var assignment = Expression.Assign(tmp, obj);
56 | Expression serialized = this.Schema.Surrogate.Serializer.BuildSerializer(encoder, tmp);
57 | return Expression.Block(new[] { tmp }, new[] { assignment, serialized });
58 | }
59 |
60 | protected override Expression BuildDeserializerSafe(Expression decoder)
61 | {
62 | Expression obj = this.Schema.Surrogate.Serializer.BuildDeserializer(decoder);
63 |
64 | var surrogate = Expression.Constant(this.settings.Surrogate);
65 | MethodInfo deserialize = typeof(IAvroSurrogate).GetMethod("GetDeserializedObject");
66 |
67 | Expression deserialized = Expression.Call(surrogate, deserialize, new[] { obj, Expression.Constant(this.Schema.RuntimeType) });
68 | return this.Schema.RuntimeType.GetTypeInfo().IsValueType
69 | ? Expression.Convert(deserialized, this.Schema.RuntimeType)
70 | : Expression.TypeAs(deserialized, this.Schema.RuntimeType);
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Microsoft.Avro.Core/Schema/SurrogateSchema.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 | namespace Microsoft.Hadoop.Avro.Schema
16 | {
17 | using System;
18 | using System.Collections.Generic;
19 | using Newtonsoft.Json;
20 |
21 | ///
22 | /// Node for surrogate types.
23 | ///
24 | internal sealed class SurrogateSchema : TypeSchema
25 | {
26 | private readonly Type surrogateType;
27 | private readonly TypeSchema surrogateSchema;
28 |
29 | internal SurrogateSchema(Type originalType, Type surrogateType, TypeSchema surrogateSchema)
30 | : this(originalType, surrogateType, new Dictionary(), surrogateSchema)
31 | {
32 | }
33 |
34 | ///
35 | /// Initializes a new instance of the class.
36 | ///
37 | /// Type of the original.
38 | /// Type of the surrogate.
39 | /// The attributes.
40 | /// The surrogate schema.
41 | internal SurrogateSchema(
42 | Type originalType,
43 | Type surrogateType,
44 | IDictionary attributes,
45 | TypeSchema surrogateSchema)
46 | : base(originalType, attributes)
47 | {
48 | if (originalType == null)
49 | {
50 | throw new ArgumentNullException("originalType");
51 | }
52 | if (surrogateType == null)
53 | {
54 | throw new ArgumentNullException("surrogateType");
55 | }
56 | if (surrogateSchema == null)
57 | {
58 | throw new ArgumentNullException("surrogateSchema");
59 | }
60 |
61 | this.surrogateType = surrogateType;
62 | this.surrogateSchema = surrogateSchema;
63 | }
64 |
65 | ///
66 | /// Gets the type of the original.
67 | ///
68 | public Type SurrogateType
69 | {
70 | get { return this.surrogateType; }
71 | }
72 |
73 | ///
74 | /// Gets the surrogate schema.
75 | ///
76 | public TypeSchema Surrogate
77 | {
78 | get { return this.surrogateSchema; }
79 | }
80 |
81 | ///
82 | /// Converts current not to JSON according to the avro specification.
83 | ///
84 | /// The writer.
85 | /// The seen schemas.
86 | internal override void ToJsonSafe(JsonTextWriter writer, HashSet seenSchemas)
87 | {
88 | this.surrogateSchema.ToJson(writer, seenSchemas);
89 | }
90 |
91 | ///
92 | /// Gets the type of the schema as string.
93 | ///
94 | internal override string Type
95 | {
96 | get { return this.surrogateSchema.Type; }
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------