├── .gitignore
├── protobuf-net
├── GlobalSuppressions.cs
├── Meta.meta
├── Compiler.meta
├── Serializers.meta
├── Serializers
│ ├── ISerializerProxy.cs
│ ├── ArrayDecorator.cs.meta
│ ├── BlobSerializer.cs.meta
│ ├── ByteSerializer.cs.meta
│ ├── CharSerializer.cs.meta
│ ├── DoubleSerializer.cs.meta
│ ├── EnumSerializer.cs.meta
│ ├── FieldDecorator.cs.meta
│ ├── GuidSerializer.cs.meta
│ ├── IProtoSerializer.cs.meta
│ ├── ISerializerProxy.cs.meta
│ ├── Int16Serializer.cs.meta
│ ├── Int32Serializer.cs.meta
│ ├── Int64Serializer.cs.meta
│ ├── ListDecorator.cs.meta
│ ├── MapDecorator.cs.meta
│ ├── NullDecorator.cs.meta
│ ├── SByteSerializer.cs.meta
│ ├── SingleSerializer.cs.meta
│ ├── StringSerializer.cs.meta
│ ├── TagDecorator.cs.meta
│ ├── TupleSerializer.cs.meta
│ ├── TypeSerializer.cs.meta
│ ├── UInt16Serializer.cs.meta
│ ├── UInt32Serializer.cs.meta
│ ├── UInt64Serializer.cs.meta
│ ├── UriDecorator.cs.meta
│ ├── BooleanSerializer.cs.meta
│ ├── CompiledSerializer.cs.meta
│ ├── DateTimeSerializer.cs.meta
│ ├── DecimalSerializer.cs.meta
│ ├── DefaultValueDecorator.cs.meta
│ ├── IProtoTypeSerializer.cs.meta
│ ├── NetObjectSerializer.cs.meta
│ ├── ParseableSerializer.cs.meta
│ ├── PropertyDecorator.cs.meta
│ ├── ProtoDecoratorBase.cs.meta
│ ├── ReflectedUriDecorator.cs.meta
│ ├── SubItemSerializer.cs.meta
│ ├── SurrogateSerializer.cs.meta
│ ├── SystemTypeSerializer.cs.meta
│ ├── TimeSpanSerializer.cs.meta
│ ├── MemberSpecifiedDecorator.cs.meta
│ ├── ImmutableCollectionDecorator.cs.meta
│ ├── IProtoTypeSerializer.cs
│ ├── CharSerializer.cs
│ ├── ProtoDecoratorBase.cs
│ ├── ByteSerializer.cs
│ ├── StringSerializer.cs
│ ├── Int32Serializer.cs
│ ├── DoubleSerializer.cs
│ ├── Int16Serializer.cs
│ ├── Int64Serializer.cs
│ ├── SByteSerializer.cs
│ ├── UInt32Serializer.cs
│ ├── UInt64Serializer.cs
│ ├── SingleSerializer.cs
│ ├── BooleanSerializer.cs
│ ├── GuidSerializer.cs
│ ├── UInt16Serializer.cs
│ ├── SystemTypeSerializer.cs
│ ├── DecimalSerializer.cs
│ ├── BlobSerializer.cs
│ ├── TimeSpanSerializer.cs
│ ├── UriDecorator.cs
│ ├── NetObjectSerializer.cs
│ ├── DateTimeSerializer.cs
│ ├── ReflectedUriDecorator.cs
│ ├── MemberSpecifiedDecorator.cs
│ ├── IProtoSerializer.cs
│ ├── CompiledSerializer.cs
│ ├── TagDecorator.cs
│ ├── FieldDecorator.cs
│ ├── ParseableSerializer.cs
│ ├── SubItemSerializer.cs
│ ├── NullDecorator.cs
│ └── SurrogateSerializer.cs
├── ServiceModel.meta
├── Compiler
│ ├── CompilerDelegates.cs
│ ├── Local.cs.meta
│ ├── CompilerContext.cs.meta
│ ├── CompilerDelegates.cs.meta
│ └── Local.cs
├── Helpers.cs.meta
├── PType.cs.meta
├── WireType.cs.meta
├── BclHelpers.cs.meta
├── BufferPool.cs.meta
├── DataFormat.cs.meta
├── Extensible.cs.meta
├── IExtensible.cs.meta
├── IExtension.cs.meta
├── Meta
│ ├── MetaType.cs.meta
│ ├── SubType.cs.meta
│ ├── AttributeMap.cs.meta
│ ├── BasicList.cs.meta
│ ├── CallbackSet.cs.meta
│ ├── ProtoSyntax.cs.meta
│ ├── TypeModel.cs.meta
│ ├── ValueMember.cs.meta
│ ├── RuntimeTypeModel.cs.meta
│ ├── TypeFormatEventArgs.cs.meta
│ ├── ProtoSyntax.cs
│ ├── TypeFormatEventArgs.cs
│ ├── SubType.cs
│ └── CallbackSet.cs
├── PrefixStyle.cs.meta
├── ProtoReader.cs.meta
├── ProtoWriter.cs.meta
├── Serializer.cs.meta
├── SubItemToken.cs.meta
├── BufferExtension.cs.meta
├── CallbackAttributes.cs.meta
├── DiscriminatedUnion.cs.meta
├── ExtensibleUtil.cs.meta
├── GlobalSuppressions.cs.meta
├── ImplicitFields.cs.meta
├── KeyValuePairProxy.cs.meta
├── NetObjectCache.cs.meta
├── ProtoEnumAttribute.cs.meta
├── ProtoException.cs.meta
├── ProtoMapAttribute.cs.meta
├── ProtoContractAttribute.cs.meta
├── ProtoConverterAttribute.cs.meta
├── ProtoIgnoreAttribute.cs.meta
├── ProtoIncludeAttribute.cs.meta
├── ProtoMemberAttribute.cs.meta
├── ProtobufPropertyHelper.cs.meta
├── SerializationContext.cs.meta
├── ServiceModel
│ ├── XmlProtoSerializer.cs.meta
│ ├── ProtoBehaviorAttribute.cs.meta
│ ├── ProtoEndpointBehavior.cs.meta
│ ├── ProtoOperationBehavior.cs.meta
│ ├── ProtoBehaviorExtensionElement.cs.meta
│ ├── ProtoBehaviorExtensionElement.cs
│ ├── ProtoBehaviorAttribute.cs
│ ├── ProtoOperationBehavior.cs
│ └── ProtoEndpointBehavior.cs
├── SubItemToken.cs
├── ProtoConverterAttribute.cs
├── PrefixStyle.cs
├── IExtensible.cs
├── ProtoException.cs
├── ProtoMapAttribute.cs
├── ImplicitFields.cs
├── ProtoEnumAttribute.cs
├── WireType.cs
├── ProtobufPropertyHelper.cs
├── ProtoIgnoreAttribute.cs
├── PType.cs
├── CallbackAttributes.cs
├── DataFormat.cs
├── KeyValuePairProxy.cs
├── IExtension.cs
├── BufferExtension.cs
├── SerializationContext.cs
├── ProtoIncludeAttribute.cs
├── BufferPool.cs
└── ExtensibleUtil.cs
├── README.md.meta
├── Editor.meta
├── protobuf-net.meta
├── Editor
├── protobuf-net.Reflection.meta
└── protobuf-net.Reflection
│ ├── TokenType.cs
│ ├── Token.cs.meta
│ ├── Descriptor.cs.meta
│ ├── Parsers.cs.meta
│ ├── Peekable.cs.meta
│ ├── TokenType.cs.meta
│ ├── CodeGenerator.cs.meta
│ ├── CustomOptions.cs.meta
│ ├── NameNormalizer.cs.meta
│ ├── TokenExtensions.cs.meta
│ ├── CSharpCodeGenerator.cs.meta
│ ├── CodeGenerator.OneOfStub.cs.meta
│ ├── Peekable.cs
│ ├── Token.cs
│ ├── CustomOptions.cs
│ └── CodeGenerator.OneOfStub.cs
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | .DS_Store
3 |
--------------------------------------------------------------------------------
/protobuf-net/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JasonXuDeveloper/protobuf-net-v2-for-ILRuntime/HEAD/protobuf-net/GlobalSuppressions.cs
--------------------------------------------------------------------------------
/README.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5ed34dfe77bf9423abaccfaf56b96a11
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 87950530345e444d184e35ebb2f94c79
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/protobuf-net.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7f3ee12a3ecf24ae09e28b807e45091e
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/protobuf-net/Meta.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9c4216751b79d4aaebb28f881166a0e7
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/protobuf-net/Compiler.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9d6b22bb7fd624df3b5208819f486e1a
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 45599ac07e8194068853bc74c30e78de
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ISerializerProxy.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 |
3 | namespace ProtoBuf.Serializers
4 | {
5 | interface ISerializerProxy
6 | {
7 | IProtoSerializer Serializer { get; }
8 | }
9 | }
10 | #endif
--------------------------------------------------------------------------------
/protobuf-net/ServiceModel.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: de176b9e152924fff8f08dff87189511
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0dbd969617c8f4f46ac5ba4c188445da
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/TokenType.cs:
--------------------------------------------------------------------------------
1 | namespace ProtoBuf.Reflection
2 | {
3 | internal enum TokenType
4 | {
5 | None,
6 | Whitespace,
7 | StringLiteral,
8 | AlphaNumeric,
9 | Symbol
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/protobuf-net/Compiler/CompilerDelegates.cs:
--------------------------------------------------------------------------------
1 | #if FEAT_COMPILER
2 | namespace ProtoBuf.Compiler
3 | {
4 | internal delegate void ProtoSerializer(object value, ProtoWriter dest);
5 | internal delegate object ProtoDeserializer(object value, ProtoReader source);
6 | }
7 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Helpers.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a347cb3ba13da4d32af67cae3bd90527
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/PType.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d42cd62e44cd246d68a69961a8084dd1
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/WireType.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d9c8158f82052473ca0cdcdf74bb058b
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/BclHelpers.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: df0eee323bef04bec8d6fe2f07b98cde
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/BufferPool.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 008443d8d68fb420ca05a3d1eb8b8198
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/DataFormat.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1222e9883ecb14a40ab64681ad64cfef
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Extensible.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 02176178147da486f818e23cc4691aa6
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/IExtensible.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: bf41219ffa67c45deaf7120a27c6f9cc
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/IExtension.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 94cadec77842c4b67960d508e4ddd9bc
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/MetaType.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 19ea8ca19feda48698d4fedfbf3fab69
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/SubType.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ec6c6ef7c03384e3587f71afd0bd3923
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/PrefixStyle.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 00e6758c4a8fe43f69a06f0bc1c6f50e
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoReader.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0caaace320e6a4aa78ee2045d8d09ad7
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoWriter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1108f45862e1f4a58a24e6113bc9dc1c
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 10a846f5244234b0f95ecf08dd7cb785
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/SubItemToken.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 63a04426811454c0fab7226fd5846bb9
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/BufferExtension.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: aa4193c31892744c8a98f0c38b6bff3c
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/CallbackAttributes.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2bacf88deacc1456fb72ccc118c5bc1f
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Compiler/Local.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f71e8b1aadf614915a65edd232bfc52f
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/DiscriminatedUnion.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 587b251a2dde74fffa1c5763728a9228
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ExtensibleUtil.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 10b37258f8b1f45c89d7866c891994f3
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/GlobalSuppressions.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2e156dfe3f94f48f19de5de4113fa637
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ImplicitFields.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d4d08464ae2b34a019537ca2cb6b5d15
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/KeyValuePairProxy.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c102cfcb770dd48d2af85a9a8383bda5
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/AttributeMap.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: afd745c9c8e9f4a87999150ac9506e30
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/BasicList.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 088629fb110014479ae26cb94beb4780
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/CallbackSet.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ad427a4f0651d474dacd2da6870ad618
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/ProtoSyntax.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cf793ffe256ad4789aa499c84818ff04
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/TypeModel.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d18cee8d546fd489897254ed573d3ef6
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/ValueMember.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7aae08b425c5f47359bb71da0ff9df19
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/NetObjectCache.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b6fa7469b64bf4ed38da473d23acfafb
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoEnumAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 773945fabb10c47439171e42c4bd0d8f
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoException.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ed8d2458d966048628686bde5eb6febc
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoMapAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2408409ad0219432f947bc435ec16700
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/Token.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a623115395e9e4875a03a152e9fd2e05
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/RuntimeTypeModel.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 55c1d5cc4da3b449aa7702508876f478
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoContractAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5dc2b35b68cb24651a7a79f310112f7c
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoConverterAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f1a586e75875c44adbd99161cd5b6ef9
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoIgnoreAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a4dcaac265af24091b0662e33af261fb
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoIncludeAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 52477ff6ecedf4a1ca691f44b3358ac6
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoMemberAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1085f7c43bb0142cca641cf8477cf413
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ProtobufPropertyHelper.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 699da8e75802c49fc9c419a1c5b38b3a
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/SerializationContext.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b9fc743bc63264276971909bce066739
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/Descriptor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6ef94f2daec6349ada5e83873322c977
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/Parsers.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5fe73db609d634d87936f0816449e9c9
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/Peekable.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7f56267e1b56746c18e01785cb2a37fd
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/TokenType.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e3baa193bac4e4ec08c31ebc0257dcdd
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Compiler/CompilerContext.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: bb6d579ef323e4ca5a85b166a0dee99c
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Compiler/CompilerDelegates.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 682cb358bcc4d4bc98ea41f2c0735a93
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/TypeFormatEventArgs.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ec7e07bf4649d4c848560fd79da69b9b
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ArrayDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 01717eae2154f46c8afbac29a49dda13
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/BlobSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 877d725bdf156418bac2baf5dc661a38
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ByteSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cb3f5d9a47c8441eb8f5a68143f86aa6
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/CharSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 44d20846cf6a84b5694f331f4429c92d
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/DoubleSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3b57c3046de044d5aa686fc7a4fd089a
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/EnumSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9a54b091dab0c4a2a91baae8da2e37e8
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/FieldDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 942d7a0ba678f41df9361a0fe7e4d95a
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/GuidSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a726135acc2584bf7b856ab30244af57
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/IProtoSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fa68a0c1c3de741e2921383632cad14c
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ISerializerProxy.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: de0c728fa09ec4a10971f1abef09fd18
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/Int16Serializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1b512087f0a684b9196c285bfac8d6e0
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/Int32Serializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7773ba5554d4c4c0388062616a6c8d93
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/Int64Serializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3b244ac295d2e421a97170009c388cfc
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ListDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ad886575d7c7b4072828b833c38a5b64
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/MapDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6fd096c53cca048fa8eead9151155625
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/NullDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a6939483c6dea4cd3a924a086d2bf4db
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/SByteSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0c95e9e58b9054a6e9d8b39aaf0b1500
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/SingleSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 453f9a0b23ac640b996f7fec48652549
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/StringSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: acdb1e187aa2a4f1ba91566468279247
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/TagDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d9ea350e1359048eda08886d15af7f98
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/TupleSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 491bf6e6ea5144a479259ea36696e810
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/TypeSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f78c24760bf834276b40d7400ec41a0d
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/UInt16Serializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7232b61b27c47494ab1e1e303f91790c
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/UInt32Serializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 92207f171a671412a9bbc1d403c2b5be
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/UInt64Serializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a0a6d0d86b6b84593aa6bb6202b91e87
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/UriDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1efe482e7f16d4aa69011106bd2235a6
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/CodeGenerator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cae37d09138854b45b3e8710d0cf31a0
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/CustomOptions.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 189459971c8b749c494de76c722b4c3e
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/NameNormalizer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 73723d82dd1e7479094aa555f13192bf
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/TokenExtensions.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d7dda2444352f477c9e3fb8b8d99f36c
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/BooleanSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d9a9945708958464a986c897a0d1abb4
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/CompiledSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1988c9e28d97b4e7f9f38864a2acdadc
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/DateTimeSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 702f4a40b884d4d6fb8cd2c74be32e00
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/DecimalSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 756a4df1b685f4c339b98c937f681471
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/DefaultValueDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3e2d56b487f2b4f0e92a2ecf8ea90053
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/IProtoTypeSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 216fb7c7f249242da9d23c3c5d863ae1
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/NetObjectSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 66a317cb2126d4b70969b0267c61ec76
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ParseableSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 616cafdf6faad4123a18fc7806c67f99
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/PropertyDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fb3a5f7b9a6f94afe9e77a3c2f113da0
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ProtoDecoratorBase.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 71e8526a54ce848fbbcaa18516fa2322
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ReflectedUriDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5ca18c18974ea4ba3b6c7899d0368d16
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/SubItemSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0604e4d2fda084036a71375d8ec6b018
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/SurrogateSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ab4db99049eef476d91d3cbb09a097fa
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/SystemTypeSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0d008efecf23a482ab5a5c0f2d100ac3
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/TimeSpanSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d7e08e22a41ef445c960f306d498c1c8
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ServiceModel/XmlProtoSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2a354656d94a64df3a8229c6f57d7113
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/CSharpCodeGenerator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1b2db3af94fd04f1c86f7ba7a3c65830
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/MemberSpecifiedDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4bfbb12c0ca3d4653a013914be225301
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ServiceModel/ProtoBehaviorAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3d2c125cc1f3c453a8bea2b47b0635f7
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ServiceModel/ProtoEndpointBehavior.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3e4ea62a6e963420b95e6557814aa6bd
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ServiceModel/ProtoOperationBehavior.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5d6f82d70f95345aab021caae9e796f9
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/CodeGenerator.OneOfStub.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4ab2e4b3f586f4d889c42499bebe6614
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ImmutableCollectionDecorator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2cfa766418a1149f8a75344f128ed753
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/ServiceModel/ProtoBehaviorExtensionElement.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 498011c55b89b4d70b572d74861c3291
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/protobuf-net/SubItemToken.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace ProtoBuf
3 | {
4 | ///
5 | /// Used to hold particulars relating to nested objects. This is opaque to the caller - simply
6 | /// give back the token you are given at the end of an object.
7 | ///
8 | public struct SubItemToken
9 | {
10 | internal readonly long value64;
11 | internal SubItemToken(int value) { value64 = value;}
12 | internal SubItemToken(long value) { value64 = value;}
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/ProtoSyntax.cs:
--------------------------------------------------------------------------------
1 | namespace ProtoBuf.Meta
2 | {
3 | ///
4 | /// Indiate the variant of the protobuf .proto DSL syntax to use
5 | ///
6 | public enum ProtoSyntax
7 | {
8 | ///
9 | /// https://developers.google.com/protocol-buffers/docs/proto
10 | ///
11 | Proto2 = 0,
12 | ///
13 | /// https://developers.google.com/protocol-buffers/docs/proto3
14 | ///
15 | Proto3 = 1,
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoConverterAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ProtoBuf
4 | {
5 | ///
6 | /// Indicates that a static member should be considered the same as though
7 | /// were an implicit / explicit conversion operator; in particular, this
8 | /// is useful for conversions that operator syntax does not allow, such as
9 | /// to/from interface types.
10 | ///
11 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
12 | public class ProtoConverterAttribute : Attribute {}
13 | }
--------------------------------------------------------------------------------
/protobuf-net/Serializers/IProtoTypeSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using ProtoBuf.Meta;
3 | namespace ProtoBuf.Serializers
4 | {
5 | interface IProtoTypeSerializer : IProtoSerializer
6 | {
7 | bool HasCallbacks(TypeModel.CallbackType callbackType);
8 | bool CanCreateInstance();
9 | #if !FEAT_IKVM
10 | object CreateInstance(ProtoReader source);
11 | void Callback(object value, TypeModel.CallbackType callbackType, SerializationContext context);
12 | #endif
13 | #if FEAT_COMPILER
14 | void EmitCallback(Compiler.CompilerContext ctx, Compiler.Local valueFrom, TypeModel.CallbackType callbackType);
15 | #endif
16 | #if FEAT_COMPILER
17 | void EmitCreateInstance(Compiler.CompilerContext ctx);
18 | #endif
19 | }
20 | }
21 | #endif
--------------------------------------------------------------------------------
/protobuf-net/PrefixStyle.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace ProtoBuf
3 | {
4 | ///
5 | /// Specifies the type of prefix that should be applied to messages.
6 | ///
7 | public enum PrefixStyle
8 | {
9 | ///
10 | /// No length prefix is applied to the data; the data is terminated only be the end of the stream.
11 | ///
12 | None,
13 | ///
14 | /// A base-128 length prefix is applied to the data (efficient for short messages).
15 | ///
16 | Base128,
17 | ///
18 | /// A fixed-length (little-endian) length prefix is applied to the data (useful for compatibility).
19 | ///
20 | Fixed32,
21 | ///
22 | /// A fixed-length (big-endian) length prefix is applied to the data (useful for compatibility).
23 | ///
24 | Fixed32BigEndian
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 JasonXuDeveloper - 傑
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/protobuf-net/IExtensible.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace ProtoBuf
3 | {
4 |
5 |
6 | ///
7 | /// Indicates that the implementing type has support for protocol-buffer
8 | /// extensions.
9 | ///
10 | /// Can be implemented by deriving from Extensible.
11 | public interface IExtensible
12 | {
13 | ///
14 | /// Retrieves the extension object for the current
15 | /// instance, optionally creating it if it does not already exist.
16 | ///
17 | /// Should a new extension object be
18 | /// created if it does not already exist?
19 | /// The extension object if it exists (or was created), or null
20 | /// if the extension object does not exist or is not available.
21 | /// The createIfMissing argument is false during serialization,
22 | /// and true during deserialization upon encountering unexpected fields.
23 | IExtension GetExtensionObject(bool createIfMissing);
24 | }
25 |
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | #if PLAT_BINARYFORMATTER && !(WINRT || PHONE8 || COREFX)
4 | using System.Runtime.Serialization;
5 | #endif
6 | namespace ProtoBuf
7 | {
8 | ///
9 | /// Indicates an error during serialization/deserialization of a proto stream.
10 | ///
11 | #if PLAT_BINARYFORMATTER && !(WINRT || PHONE8 || COREFX)
12 | [Serializable]
13 | #endif
14 | public class ProtoException : Exception
15 | {
16 | /// Creates a new ProtoException instance.
17 | public ProtoException() { }
18 |
19 | /// Creates a new ProtoException instance.
20 | public ProtoException(string message) : base(message) { }
21 |
22 | /// Creates a new ProtoException instance.
23 | public ProtoException(string message, Exception innerException) : base(message, innerException) { }
24 |
25 | #if PLAT_BINARYFORMATTER && !(WINRT || PHONE8 || COREFX)
26 | /// Creates a new ProtoException instance.
27 | protected ProtoException(SerializationInfo info, StreamingContext context) : base(info, context) { }
28 | #endif
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoMapAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ProtoBuf
4 | {
5 | ///
6 | /// Controls the formatting of elements in a dictionary, and indicates that
7 | /// "map" rules should be used: duplicates *replace* earlier values, rather
8 | /// than throwing an exception
9 | ///
10 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
11 | public class ProtoMapAttribute : Attribute
12 | {
13 | ///
14 | /// Describes the data-format used to store the key
15 | ///
16 | public DataFormat KeyFormat { get; set; }
17 | ///
18 | /// Describes the data-format used to store the value
19 | ///
20 | public DataFormat ValueFormat { get; set; }
21 |
22 | ///
23 | /// Disables "map" handling; dictionaries will use ".Add(key,value)" instead of "[key] = value",
24 | /// which means duplicate keys will cause an exception (instead of retaining the final value); if
25 | /// a proto schema is emitted, it will be produced using "repeated" instead of "map"
26 | ///
27 | public bool DisableMap { get; set; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/protobuf-net/ImplicitFields.cs:
--------------------------------------------------------------------------------
1 | namespace ProtoBuf
2 | {
3 | ///
4 | /// Specifies the method used to infer field tags for members of the type
5 | /// under consideration. Tags are deduced using the invariant alphabetic
6 | /// sequence of the members' names; this makes implicit field tags very brittle,
7 | /// and susceptible to changes such as field names (normally an isolated
8 | /// change).
9 | ///
10 | public enum ImplicitFields
11 | {
12 | ///
13 | /// No members are serialized implicitly; all members require a suitable
14 | /// attribute such as [ProtoMember]. This is the recmomended mode for
15 | /// most scenarios.
16 | ///
17 | None = 0,
18 | ///
19 | /// Public properties and fields are eligible for implicit serialization;
20 | /// this treats the public API as a contract. Ordering beings from ImplicitFirstTag.
21 | ///
22 | AllPublic= 1,
23 | ///
24 | /// Public and non-public fields are eligible for implicit serialization;
25 | /// this acts as a state/implementation serializer. Ordering beings from ImplicitFirstTag.
26 | ///
27 | AllFields = 2
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/CharSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 |
9 | #endif
10 |
11 |
12 | namespace ProtoBuf.Serializers
13 | {
14 | sealed class CharSerializer : UInt16Serializer
15 | {
16 | #if FEAT_IKVM
17 | readonly Type expectedType;
18 | #else
19 | static readonly Type expectedType = typeof(char);
20 | #endif
21 | public CharSerializer(ProtoBuf.Meta.TypeModel model) : base(model)
22 | {
23 | #if FEAT_IKVM
24 | expectedType = model.MapType(typeof(char));
25 | #endif
26 | }
27 | public override Type ExpectedType { get { return expectedType; } }
28 |
29 | #if !FEAT_IKVM
30 | public override void Write(object value, ProtoWriter dest)
31 | {
32 | ProtoWriter.WriteUInt16((ushort)(char)value, dest);
33 | }
34 | public override object Read(object value, ProtoReader source)
35 | {
36 | Helpers.DebugAssert(value == null); // since replaces
37 | return (char)source.ReadUInt16();
38 | }
39 | #endif
40 | // no need for any special IL here; ushort and char are
41 | // interchangeable as long as there is no boxing/unboxing
42 | }
43 | }
44 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ProtoDecoratorBase.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | #if FEAT_IKVM
4 | using Type = IKVM.Reflection.Type;
5 | using IKVM.Reflection;
6 | #else
7 |
8 | #endif
9 |
10 | namespace ProtoBuf.Serializers
11 | {
12 | abstract class ProtoDecoratorBase : IProtoSerializer
13 | {
14 | public abstract Type ExpectedType { get; }
15 | protected readonly IProtoSerializer Tail;
16 | protected ProtoDecoratorBase(IProtoSerializer tail) { this.Tail = tail; }
17 | public abstract bool ReturnsValue { get; }
18 | public abstract bool RequiresOldValue { get; }
19 | #if !FEAT_IKVM
20 | public abstract void Write(object value, ProtoWriter dest);
21 | public abstract object Read(object value, ProtoReader source);
22 | #endif
23 |
24 | #if FEAT_COMPILER
25 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom) { EmitWrite(ctx, valueFrom); }
26 | protected abstract void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom);
27 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom) { EmitRead(ctx, valueFrom); }
28 | protected abstract void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom);
29 | #endif
30 | }
31 | }
32 | #endif
--------------------------------------------------------------------------------
/protobuf-net/ProtoEnumAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ProtoBuf
4 | {
5 | ///
6 | /// Used to define protocol-buffer specific behavior for
7 | /// enumerated values.
8 | ///
9 | [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
10 | public sealed class ProtoEnumAttribute : Attribute
11 | {
12 | ///
13 | /// Gets or sets the specific value to use for this enum during serialization.
14 | ///
15 | public int Value
16 | {
17 | get { return enumValue; }
18 | set { this.enumValue = value; hasValue = true; }
19 | }
20 |
21 | ///
22 | /// Indicates whether this instance has a customised value mapping
23 | ///
24 | /// true if a specific value is set
25 | public bool HasValue() { return hasValue; }
26 |
27 | private bool hasValue;
28 | private int enumValue;
29 |
30 | ///
31 | /// Gets or sets the defined name of the enum, as used in .proto
32 | /// (this name is not used during serialization).
33 | ///
34 | public string Name { get { return name; } set { name = value; } }
35 | private string name;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/protobuf-net/ServiceModel/ProtoBehaviorExtensionElement.cs:
--------------------------------------------------------------------------------
1 | #if FEAT_SERVICEMODEL && PLAT_XMLSERIALIZER
2 | using System;
3 | using System.ServiceModel.Configuration;
4 |
5 | namespace ProtoBuf.ServiceModel
6 | {
7 | ///
8 | /// Configuration element to swap out DatatContractSerilaizer with the XmlProtoSerializer for a given endpoint.
9 | ///
10 | ///
11 | public class ProtoBehaviorExtension : BehaviorExtensionElement
12 | {
13 | ///
14 | /// Creates a new ProtoBehaviorExtension instance.
15 | ///
16 | public ProtoBehaviorExtension()
17 | {
18 | }
19 |
20 | ///
21 | /// Gets the type of behavior.
22 | ///
23 | public override Type BehaviorType
24 | {
25 | get
26 | {
27 | return typeof(ProtoEndpointBehavior);
28 | }
29 | }
30 |
31 | ///
32 | /// Creates a behavior extension based on the current configuration settings.
33 | ///
34 | /// The behavior extension.
35 | protected override object CreateBehavior()
36 | {
37 | return new ProtoEndpointBehavior();
38 | }
39 | }
40 | }
41 | #endif
--------------------------------------------------------------------------------
/protobuf-net/WireType.cs:
--------------------------------------------------------------------------------
1 | namespace ProtoBuf
2 | {
3 | ///
4 | /// Indicates the encoding used to represent an individual value in a protobuf stream
5 | ///
6 | public enum WireType
7 | {
8 | ///
9 | /// Represents an error condition
10 | ///
11 | None = -1,
12 |
13 | ///
14 | /// Base-128 variant-length encoding
15 | ///
16 | Variant = 0,
17 |
18 | ///
19 | /// Fixed-length 8-byte encoding
20 | ///
21 | Fixed64 = 1,
22 |
23 | ///
24 | /// Length-variant-prefixed encoding
25 | ///
26 | String = 2,
27 |
28 | ///
29 | /// Indicates the start of a group
30 | ///
31 | StartGroup = 3,
32 |
33 | ///
34 | /// Indicates the end of a group
35 | ///
36 | EndGroup = 4,
37 |
38 | ///
39 | /// Fixed-length 4-byte encoding
40 | /// 10
41 | Fixed32 = 5,
42 |
43 | ///
44 | /// This is not a formal wire-type in the "protocol buffers" spec, but
45 | /// denotes a variant integer that should be interpreted using
46 | /// zig-zag semantics (so -ve numbers aren't a significant overhead)
47 | ///
48 | SignedVariant = WireType.Variant | (1 << 3),
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/protobuf-net/ServiceModel/ProtoBehaviorAttribute.cs:
--------------------------------------------------------------------------------
1 | #if FEAT_SERVICEMODEL && PLAT_XMLSERIALIZER
2 | using System;
3 | using System.ServiceModel.Description;
4 | using System.ServiceModel.Dispatcher;
5 |
6 | namespace ProtoBuf.ServiceModel
7 | {
8 | ///
9 | /// Uses protocol buffer serialization on the specified operation; note that this
10 | /// must be enabled on both the client and server.
11 | ///
12 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
13 | public sealed class ProtoBehaviorAttribute : Attribute, IOperationBehavior
14 | {
15 | void IOperationBehavior.AddBindingParameters(OperationDescription operationDescription, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
16 | { }
17 |
18 | void IOperationBehavior.ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
19 | {
20 | IOperationBehavior innerBehavior = new ProtoOperationBehavior(operationDescription);
21 | innerBehavior.ApplyClientBehavior(operationDescription, clientOperation);
22 | }
23 |
24 | void IOperationBehavior.ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
25 | {
26 | IOperationBehavior innerBehavior = new ProtoOperationBehavior(operationDescription);
27 | innerBehavior.ApplyDispatchBehavior(operationDescription, dispatchOperation);
28 | }
29 |
30 | void IOperationBehavior.Validate(OperationDescription operationDescription)
31 | { }
32 | }
33 | }
34 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ByteSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | #endif
7 |
8 |
9 |
10 | namespace ProtoBuf.Serializers
11 | {
12 | sealed class ByteSerializer : IProtoSerializer
13 | {
14 | public Type ExpectedType { get { return expectedType; } }
15 |
16 | #if FEAT_IKVM
17 | readonly Type expectedType;
18 | #else
19 | static readonly Type expectedType = typeof(byte);
20 | #endif
21 | public ByteSerializer(ProtoBuf.Meta.TypeModel model)
22 | {
23 | #if FEAT_IKVM
24 | expectedType = model.MapType(typeof(byte));
25 | #endif
26 | }
27 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
28 | bool IProtoSerializer.ReturnsValue { get { return true; } }
29 | #if !FEAT_IKVM
30 | public void Write(object value, ProtoWriter dest)
31 | {
32 | ProtoWriter.WriteByte((byte)value, dest);
33 | }
34 | public object Read(object value, ProtoReader source)
35 | {
36 | Helpers.DebugAssert(value == null); // since replaces
37 | return source.ReadByte();
38 | }
39 | #endif
40 |
41 | #if FEAT_COMPILER
42 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
43 | {
44 | ctx.EmitBasicWrite("WriteByte", valueFrom);
45 | }
46 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
47 | {
48 | ctx.EmitBasicRead("ReadByte", ExpectedType);
49 | }
50 | #endif
51 |
52 | }
53 | }
54 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/StringSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | #if FEAT_IKVM
4 | using Type = IKVM.Reflection.Type;
5 | using IKVM.Reflection;
6 | #else
7 |
8 | #endif
9 |
10 | namespace ProtoBuf.Serializers
11 | {
12 | sealed class StringSerializer : IProtoSerializer
13 | {
14 | #if FEAT_IKVM
15 | readonly Type expectedType;
16 | #else
17 | static readonly Type expectedType = typeof(string);
18 | #endif
19 | public StringSerializer(ProtoBuf.Meta.TypeModel model)
20 | {
21 | #if FEAT_IKVM
22 | expectedType = model.MapType(typeof(string));
23 | #endif
24 | }
25 | public Type ExpectedType { get { return expectedType; } }
26 | public void Write(object value, ProtoWriter dest)
27 | {
28 | ProtoWriter.WriteString((string)value, dest);
29 | }
30 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
31 | bool IProtoSerializer.ReturnsValue { get { return true; } }
32 |
33 | public object Read(object value, ProtoReader source)
34 | {
35 | Helpers.DebugAssert(value == null); // since replaces
36 | return source.ReadString();
37 | }
38 | #if FEAT_COMPILER
39 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
40 | {
41 | ctx.EmitBasicWrite("WriteString", valueFrom);
42 | }
43 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
44 | {
45 | ctx.EmitBasicRead("ReadString", ExpectedType);
46 | }
47 | #endif
48 | }
49 | }
50 | #endif
--------------------------------------------------------------------------------
/protobuf-net/ProtobufPropertyHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace ProtoBuf
5 | {
6 | public class ProtobufPropertyHelper
7 | {
8 | static ProtobufPropertyHelper m_current;
9 | static ProtobufPropertyHelper current
10 | {
11 | get
12 | {
13 | if (m_current == null)
14 | m_current = new ProtobufPropertyHelper();
15 | return m_current;
16 | }
17 | }
18 | Dictionary m_types = new Dictionary();
19 |
20 | private ProtobufPropertyHelper() { }
21 |
22 | void RegisterMemberTypeInternal(string metaIndex, Type type)
23 | {
24 | if (!m_types.ContainsKey(metaIndex))
25 | {
26 | m_types.Add(metaIndex,type);
27 | }
28 | else
29 | throw new SystemException(string.Format("PropertyMeta : {0} is registered!",metaIndex));
30 | }
31 |
32 | Type FindMemberTypeInternal(string metaIndex)
33 | {
34 | Type type = null;
35 | if (!m_types.TryGetValue(metaIndex, out type))
36 | {
37 | throw new SystemException(string.Format("PropertyMeta : {0} is not registered!", metaIndex));
38 | }
39 | return type;
40 | }
41 |
42 | public static void RegisterMemberType(string metaIndex, Type type)
43 | {
44 | current.RegisterMemberTypeInternal(metaIndex, type);
45 | }
46 |
47 | public static Type FindMemberType(string metaIndex)
48 | {
49 | return current.FindMemberTypeInternal(metaIndex);
50 | }
51 | }
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/Int32Serializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 |
9 | #endif
10 |
11 | namespace ProtoBuf.Serializers
12 | {
13 | sealed class Int32Serializer : IProtoSerializer
14 | {
15 | #if FEAT_IKVM
16 | readonly Type expectedType;
17 | #else
18 | static readonly Type expectedType = typeof(int);
19 | #endif
20 | public Int32Serializer(ProtoBuf.Meta.TypeModel model)
21 | {
22 | #if FEAT_IKVM
23 | expectedType = model.MapType(typeof(int));
24 | #endif
25 | }
26 | public Type ExpectedType { get { return expectedType; } }
27 |
28 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
29 | bool IProtoSerializer.ReturnsValue { get { return true; } }
30 | #if !FEAT_IKVM
31 | public object Read(object value, ProtoReader source)
32 | {
33 | Helpers.DebugAssert(value == null); // since replaces
34 | return source.ReadInt32();
35 | }
36 | public void Write(object value, ProtoWriter dest)
37 | {
38 | ProtoWriter.WriteInt32((int)value, dest);
39 | }
40 | #endif
41 | #if FEAT_COMPILER
42 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
43 | {
44 | ctx.EmitBasicWrite("WriteInt32", valueFrom);
45 | }
46 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
47 | {
48 | ctx.EmitBasicRead("ReadInt32", ExpectedType);
49 | }
50 | #endif
51 |
52 | }
53 | }
54 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/DoubleSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | #if FEAT_IKVM
4 | using Type = IKVM.Reflection.Type;
5 | using IKVM.Reflection;
6 | #else
7 |
8 | #endif
9 |
10 | namespace ProtoBuf.Serializers
11 | {
12 | sealed class DoubleSerializer : IProtoSerializer
13 | {
14 | #if FEAT_IKVM
15 | readonly Type expectedType;
16 | #else
17 | static readonly Type expectedType = typeof(double);
18 | #endif
19 | public DoubleSerializer(ProtoBuf.Meta.TypeModel model)
20 | {
21 | #if FEAT_IKVM
22 | expectedType = model.MapType(typeof(double));
23 | #endif
24 | }
25 |
26 | public Type ExpectedType { get { return expectedType; } }
27 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
28 | bool IProtoSerializer.ReturnsValue { get { return true; } }
29 | #if !FEAT_IKVM
30 | public object Read(object value, ProtoReader source)
31 | {
32 | Helpers.DebugAssert(value == null); // since replaces
33 | return source.ReadDouble();
34 | }
35 | public void Write(object value, ProtoWriter dest)
36 | {
37 | ProtoWriter.WriteDouble((double)value, dest);
38 | }
39 | #endif
40 | #if FEAT_COMPILER
41 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
42 | {
43 | ctx.EmitBasicWrite("WriteDouble", valueFrom);
44 | }
45 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
46 | {
47 | ctx.EmitBasicRead("ReadDouble", ExpectedType);
48 | }
49 | #endif
50 | }
51 | }
52 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/Int16Serializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 |
9 | #endif
10 |
11 | namespace ProtoBuf.Serializers
12 | {
13 | sealed class Int16Serializer : IProtoSerializer
14 | {
15 | #if FEAT_IKVM
16 | readonly Type expectedType;
17 | #else
18 | static readonly Type expectedType = typeof(short);
19 | #endif
20 | public Int16Serializer(ProtoBuf.Meta.TypeModel model)
21 | {
22 | #if FEAT_IKVM
23 | expectedType = model.MapType(typeof(short));
24 | #endif
25 | }
26 | public Type ExpectedType { get { return expectedType; } }
27 |
28 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
29 | bool IProtoSerializer.ReturnsValue { get { return true; } }
30 | #if !FEAT_IKVM
31 | public object Read(object value, ProtoReader source)
32 | {
33 | Helpers.DebugAssert(value == null); // since replaces
34 | return source.ReadInt16();
35 | }
36 | public void Write(object value, ProtoWriter dest)
37 | {
38 | ProtoWriter.WriteInt16((short)value, dest);
39 | }
40 | #endif
41 | #if FEAT_COMPILER
42 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
43 | {
44 | ctx.EmitBasicWrite("WriteInt16", valueFrom);
45 | }
46 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
47 | {
48 | ctx.EmitBasicRead("ReadInt16", ExpectedType);
49 | }
50 | #endif
51 |
52 | }
53 | }
54 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/Int64Serializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | #if FEAT_IKVM
4 | using Type = IKVM.Reflection.Type;
5 | using IKVM.Reflection;
6 | #else
7 |
8 | #endif
9 |
10 | namespace ProtoBuf.Serializers
11 | {
12 | sealed class Int64Serializer : IProtoSerializer
13 | {
14 | #if FEAT_IKVM
15 | readonly Type expectedType;
16 | #else
17 | static readonly Type expectedType = typeof(long);
18 | #endif
19 | public Int64Serializer(ProtoBuf.Meta.TypeModel model)
20 | {
21 | #if FEAT_IKVM
22 | expectedType = model.MapType(typeof(long));
23 | #endif
24 | }
25 |
26 | public Type ExpectedType { get { return expectedType; } }
27 |
28 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
29 | bool IProtoSerializer.ReturnsValue { get { return true; } }
30 | #if !FEAT_IKVM
31 | public object Read(object value, ProtoReader source)
32 | {
33 | Helpers.DebugAssert(value == null); // since replaces
34 | return source.ReadInt64();
35 | }
36 | public void Write(object value, ProtoWriter dest)
37 | {
38 | ProtoWriter.WriteInt64((long)value, dest);
39 | }
40 | #endif
41 | #if FEAT_COMPILER
42 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
43 | {
44 | ctx.EmitBasicWrite("WriteInt64", valueFrom);
45 | }
46 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
47 | {
48 | ctx.EmitBasicRead("ReadInt64", ExpectedType);
49 | }
50 | #endif
51 | }
52 | }
53 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/SByteSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 |
9 | #endif
10 |
11 | namespace ProtoBuf.Serializers
12 | {
13 | sealed class SByteSerializer : IProtoSerializer
14 | {
15 | #if FEAT_IKVM
16 | readonly Type expectedType;
17 | #else
18 | static readonly Type expectedType = typeof(sbyte);
19 | #endif
20 | public SByteSerializer(ProtoBuf.Meta.TypeModel model)
21 | {
22 | #if FEAT_IKVM
23 | expectedType = model.MapType(typeof(sbyte));
24 | #endif
25 | }
26 | public Type ExpectedType { get { return expectedType; } }
27 |
28 |
29 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
30 | bool IProtoSerializer.ReturnsValue { get { return true; } }
31 | #if !FEAT_IKVM
32 | public object Read(object value, ProtoReader source)
33 | {
34 | Helpers.DebugAssert(value == null); // since replaces
35 | return source.ReadSByte();
36 | }
37 | public void Write(object value, ProtoWriter dest)
38 | {
39 | ProtoWriter.WriteSByte((sbyte)value, dest);
40 | }
41 | #endif
42 | #if FEAT_COMPILER
43 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
44 | {
45 | ctx.EmitBasicWrite("WriteSByte", valueFrom);
46 | }
47 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
48 | {
49 | ctx.EmitBasicRead("ReadSByte", ExpectedType);
50 | }
51 | #endif
52 |
53 | }
54 | }
55 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/UInt32Serializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 |
9 | #endif
10 |
11 |
12 | namespace ProtoBuf.Serializers
13 | {
14 | sealed class UInt32Serializer : IProtoSerializer
15 | {
16 | #if FEAT_IKVM
17 | readonly Type expectedType;
18 | #else
19 | static readonly Type expectedType = typeof(uint);
20 | #endif
21 | public UInt32Serializer(ProtoBuf.Meta.TypeModel model)
22 | {
23 | #if FEAT_IKVM
24 | expectedType = model.MapType(typeof(uint));
25 | #endif
26 | }
27 | public Type ExpectedType { get { return expectedType; } }
28 |
29 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
30 | bool IProtoSerializer.ReturnsValue { get { return true; } }
31 | #if !FEAT_IKVM
32 | public object Read(object value, ProtoReader source)
33 | {
34 | Helpers.DebugAssert(value == null); // since replaces
35 | return source.ReadUInt32();
36 | }
37 | public void Write(object value, ProtoWriter dest)
38 | {
39 | ProtoWriter.WriteUInt32((uint)value, dest);
40 | }
41 | #endif
42 | #if FEAT_COMPILER
43 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
44 | {
45 | ctx.EmitBasicWrite("WriteUInt32", valueFrom);
46 | }
47 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
48 | {
49 | ctx.EmitBasicRead("ReadUInt32", ctx.MapType(typeof(uint)));
50 | }
51 | #endif
52 | }
53 | }
54 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/UInt64Serializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 |
9 | #endif
10 |
11 | namespace ProtoBuf.Serializers
12 | {
13 | sealed class UInt64Serializer : IProtoSerializer
14 | {
15 | #if FEAT_IKVM
16 | readonly Type expectedType;
17 | #else
18 | static readonly Type expectedType = typeof(ulong);
19 | #endif
20 | public UInt64Serializer(ProtoBuf.Meta.TypeModel model)
21 | {
22 | #if FEAT_IKVM
23 | expectedType = model.MapType(typeof(ulong));
24 | #endif
25 | }
26 | public Type ExpectedType { get { return expectedType; } }
27 |
28 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
29 | bool IProtoSerializer.ReturnsValue { get { return true; } }
30 |
31 | #if !FEAT_IKVM
32 | public object Read(object value, ProtoReader source)
33 | {
34 | Helpers.DebugAssert(value == null); // since replaces
35 | return source.ReadUInt64();
36 | }
37 | public void Write(object value, ProtoWriter dest)
38 | {
39 | ProtoWriter.WriteUInt64((ulong)value, dest);
40 | }
41 | #endif
42 |
43 | #if FEAT_COMPILER
44 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
45 | {
46 | ctx.EmitBasicWrite("WriteUInt64", valueFrom);
47 | }
48 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
49 | {
50 | ctx.EmitBasicRead("ReadUInt64", ExpectedType);
51 | }
52 | #endif
53 | }
54 | }
55 | #endif
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/Peekable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace ProtoBuf.Reflection
5 | {
6 | internal sealed class Peekable : IDisposable
7 | {
8 | public override string ToString()
9 | {
10 | T val;
11 | return Peek(out val) ? (val?.ToString() ?? "(null)") : "(EOF)";
12 | }
13 | private readonly IEnumerator _iter;
14 | private T _peek, _prev;
15 | private bool _havePeek, _eof;
16 | public Peekable(IEnumerable sequence)
17 | {
18 | _iter = sequence.GetEnumerator();
19 | }
20 | public T Previous => _prev;
21 | public bool Consume()
22 | {
23 | T val;
24 | bool haveData = _havePeek || Peek(out val);
25 | _prev = _peek;
26 | _havePeek = false;
27 | return haveData;
28 | }
29 | public bool Peek(out T next)
30 | {
31 | if (!_havePeek)
32 | {
33 | if (_iter.MoveNext())
34 | {
35 | _prev = _peek;
36 | _peek = _iter.Current;
37 | _havePeek = true;
38 | }
39 | else
40 | {
41 | _eof = true;
42 | _havePeek = false;
43 | }
44 | }
45 | if (_eof)
46 | {
47 | next = default(T);
48 | return false;
49 | }
50 | next = _peek;
51 | return true;
52 | }
53 | public void Dispose() => _iter?.Dispose();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoIgnoreAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ProtoBuf
4 | {
5 | ///
6 | /// Indicates that a member should be excluded from serialization; this
7 | /// is only normally used when using implict fields.
8 | ///
9 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field,
10 | AllowMultiple = false, Inherited = true)]
11 | public class ProtoIgnoreAttribute : Attribute {}
12 |
13 | ///
14 | /// Indicates that a member should be excluded from serialization; this
15 | /// is only normally used when using implict fields. This allows
16 | /// ProtoIgnoreAttribute usage
17 | /// even for partial classes where the individual members are not
18 | /// under direct control.
19 | ///
20 | [AttributeUsage(AttributeTargets.Class,
21 | AllowMultiple = true, Inherited = false)]
22 | public sealed class ProtoPartialIgnoreAttribute : ProtoIgnoreAttribute
23 | {
24 | ///
25 | /// Creates a new ProtoPartialIgnoreAttribute instance.
26 | ///
27 | /// Specifies the member to be ignored.
28 | public ProtoPartialIgnoreAttribute(string memberName)
29 | : base()
30 | {
31 | if (Helpers.IsNullOrEmpty(memberName)) throw new ArgumentNullException("memberName");
32 | this.memberName = memberName;
33 | }
34 | ///
35 | /// The name of the member to be ignored.
36 | ///
37 | public string MemberName { get { return memberName; } }
38 | private readonly string memberName;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/SingleSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | using ProtoBuf.Meta;
4 |
5 | #if FEAT_IKVM
6 | using Type = IKVM.Reflection.Type;
7 | using IKVM.Reflection;
8 | #else
9 |
10 | #endif
11 |
12 |
13 | namespace ProtoBuf.Serializers
14 | {
15 | sealed class SingleSerializer : IProtoSerializer
16 | {
17 | #if FEAT_IKVM
18 | readonly Type expectedType;
19 | #else
20 | static readonly Type expectedType = typeof(float);
21 | #endif
22 | public Type ExpectedType { get { return expectedType; } }
23 |
24 | public SingleSerializer(TypeModel model)
25 | {
26 | #if FEAT_IKVM
27 | expectedType = model.MapType(typeof(float));
28 | #endif
29 | }
30 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
31 | bool IProtoSerializer.ReturnsValue { get { return true; } }
32 | #if !FEAT_IKVM
33 | public object Read(object value, ProtoReader source)
34 | {
35 | Helpers.DebugAssert(value == null); // since replaces
36 | return source.ReadSingle();
37 | }
38 | public void Write(object value, ProtoWriter dest)
39 | {
40 | ProtoWriter.WriteSingle((float)value, dest);
41 | }
42 | #endif
43 |
44 | #if FEAT_COMPILER
45 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
46 | {
47 | ctx.EmitBasicWrite("WriteSingle", valueFrom);
48 | }
49 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
50 | {
51 | ctx.EmitBasicRead("ReadSingle", ExpectedType);
52 | }
53 | #endif
54 | }
55 | }
56 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/BooleanSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 |
9 | #endif
10 |
11 |
12 |
13 |
14 |
15 | namespace ProtoBuf.Serializers
16 | {
17 | sealed class BooleanSerializer : IProtoSerializer
18 | {
19 | #if FEAT_IKVM
20 | readonly Type expectedType;
21 | #else
22 | static readonly Type expectedType = typeof(bool);
23 | #endif
24 | public BooleanSerializer(ProtoBuf.Meta.TypeModel model)
25 | {
26 | #if FEAT_IKVM
27 | expectedType = model.MapType(typeof(bool));
28 | #endif
29 | }
30 | public Type ExpectedType { get { return expectedType; } }
31 |
32 | #if !FEAT_IKVM
33 | public void Write(object value, ProtoWriter dest)
34 | {
35 | ProtoWriter.WriteBoolean((bool)value, dest);
36 | }
37 | public object Read(object value, ProtoReader source)
38 | {
39 | Helpers.DebugAssert(value == null); // since replaces
40 | return source.ReadBoolean();
41 | }
42 | #endif
43 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
44 | bool IProtoSerializer.ReturnsValue { get { return true; } }
45 | #if FEAT_COMPILER
46 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
47 | {
48 | ctx.EmitBasicWrite("WriteBoolean", valueFrom);
49 | }
50 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
51 | {
52 | ctx.EmitBasicRead("ReadBoolean", ExpectedType);
53 | }
54 | #endif
55 | }
56 | }
57 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/GuidSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | #endif
7 |
8 |
9 | namespace ProtoBuf.Serializers
10 | {
11 | sealed class GuidSerializer : IProtoSerializer
12 | {
13 | #if FEAT_IKVM
14 | readonly Type expectedType;
15 | #else
16 | static readonly Type expectedType = typeof(Guid);
17 | #endif
18 | public GuidSerializer(ProtoBuf.Meta.TypeModel model)
19 | {
20 | #if FEAT_IKVM
21 | expectedType = model.MapType(typeof(Guid));
22 | #endif
23 | }
24 |
25 | public Type ExpectedType { get { return expectedType; } }
26 |
27 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
28 | bool IProtoSerializer.ReturnsValue { get { return true; } }
29 |
30 | #if !FEAT_IKVM
31 | public void Write(object value, ProtoWriter dest)
32 | {
33 | BclHelpers.WriteGuid((Guid)value, dest);
34 | }
35 | public object Read(object value, ProtoReader source)
36 | {
37 | Helpers.DebugAssert(value == null); // since replaces
38 | return BclHelpers.ReadGuid(source);
39 | }
40 | #endif
41 |
42 | #if FEAT_COMPILER
43 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
44 | {
45 | ctx.EmitWrite(ctx.MapType(typeof(BclHelpers)), "WriteGuid", valueFrom);
46 | }
47 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
48 | {
49 | ctx.EmitBasicRead(ctx.MapType(typeof(BclHelpers)), "ReadGuid", ExpectedType);
50 | }
51 | #endif
52 |
53 | }
54 | }
55 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/UInt16Serializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 |
9 | #endif
10 |
11 |
12 | namespace ProtoBuf.Serializers
13 | {
14 | class UInt16Serializer : IProtoSerializer
15 | {
16 | #if FEAT_IKVM
17 | readonly Type expectedType;
18 | #else
19 | static readonly Type expectedType = typeof(ushort);
20 | #endif
21 | public UInt16Serializer(ProtoBuf.Meta.TypeModel model)
22 | {
23 | #if FEAT_IKVM
24 | expectedType = model.MapType(typeof(ushort));
25 | #endif
26 | }
27 | public virtual Type ExpectedType { get { return expectedType; } }
28 |
29 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
30 | bool IProtoSerializer.ReturnsValue { get { return true; } }
31 | #if !FEAT_IKVM
32 | public virtual object Read(object value, ProtoReader source)
33 | {
34 | Helpers.DebugAssert(value == null); // since replaces
35 | return source.ReadUInt16();
36 | }
37 | public virtual void Write(object value, ProtoWriter dest)
38 | {
39 | ProtoWriter.WriteUInt16((ushort)value, dest);
40 | }
41 | #endif
42 | #if FEAT_COMPILER
43 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
44 | {
45 | ctx.EmitBasicWrite("WriteUInt16", valueFrom);
46 | }
47 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
48 | {
49 | ctx.EmitBasicRead("ReadUInt16", ctx.MapType(typeof(ushort)));
50 | }
51 | #endif
52 | }
53 | }
54 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/SystemTypeSerializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | #if !NO_RUNTIME
4 |
5 | #if FEAT_IKVM
6 | using Type = IKVM.Reflection.Type;
7 | using IKVM.Reflection;
8 | #else
9 |
10 | #endif
11 |
12 | namespace ProtoBuf.Serializers
13 | {
14 | sealed class SystemTypeSerializer : IProtoSerializer
15 | {
16 | #if FEAT_IKVM
17 | readonly Type expectedType;
18 | #else
19 | static readonly Type expectedType = typeof(System.Type);
20 | #endif
21 | public SystemTypeSerializer(ProtoBuf.Meta.TypeModel model)
22 | {
23 | #if FEAT_IKVM
24 | expectedType = model.MapType(typeof(System.Type));
25 | #endif
26 | }
27 | public Type ExpectedType { get { return expectedType; } }
28 |
29 | #if !FEAT_IKVM
30 | void IProtoSerializer.Write(object value, ProtoWriter dest)
31 | {
32 | ProtoWriter.WriteType((Type)value, dest);
33 | }
34 |
35 | object IProtoSerializer.Read(object value, ProtoReader source)
36 | {
37 | Helpers.DebugAssert(value == null); // since replaces
38 | return source.ReadType();
39 | }
40 | #endif
41 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
42 | bool IProtoSerializer.ReturnsValue { get { return true; } }
43 |
44 | #if FEAT_COMPILER
45 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
46 | {
47 | ctx.EmitBasicWrite("WriteType", valueFrom);
48 | }
49 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
50 | {
51 | ctx.EmitBasicRead("ReadType", ExpectedType);
52 | }
53 | #endif
54 | }
55 | }
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/protobuf-net/PType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using ILRuntime.Reflection;
5 | using ILRuntime.Runtime.Intepreter;
6 | using UnityEngine;
7 |
8 | namespace ProtoBuf
9 | {
10 | public static class PType
11 | {
12 | private static ILRuntime.Runtime.Enviorment.AppDomain appdomain;
13 | private static readonly Dictionary ilruntimeTypes = new Dictionary();
14 |
15 | public static Type FindType(string metaName)
16 | {
17 | ilruntimeTypes.TryGetValue(metaName, out Type type);
18 | return type;
19 | }
20 |
21 | public static object CreateInstance(Type type)
22 | {
23 | if (!(type is ILRuntimeType)) return Activator.CreateInstance(type);
24 | string typeName = type.FullName;
25 | if (FindType(typeName) != null)
26 | {
27 | return appdomain.Instantiate(typeName);
28 | }
29 |
30 | if (typeName != null && appdomain.LoadedTypes.ContainsKey(typeName))
31 | {
32 | ilruntimeTypes[typeName] = type;
33 | return appdomain.Instantiate(typeName);
34 | }
35 |
36 | return null;
37 | }
38 |
39 | public static Type GetPType(object o)
40 | {
41 | Type type;
42 | if (o is ILTypeInstance ins)
43 | {
44 | type = ins.Type.ReflectionType;
45 | }
46 | else
47 | {
48 | type = o.GetType();
49 | }
50 |
51 | return type;
52 | }
53 |
54 | public static void RegisterILRuntimeCLRRedirection(ILRuntime.Runtime.Enviorment.AppDomain domain)
55 | {
56 | appdomain = domain;
57 | var allTypes = domain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
58 | foreach (var type in allTypes)
59 | {
60 | if (type.FullName != null) ilruntimeTypes[type.FullName] = type;
61 | }
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/protobuf-net/Serializers/DecimalSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | #if FEAT_IKVM
4 | using Type = IKVM.Reflection.Type;
5 | using IKVM.Reflection;
6 | #else
7 |
8 | #endif
9 |
10 |
11 |
12 | namespace ProtoBuf.Serializers
13 | {
14 | sealed class DecimalSerializer : IProtoSerializer
15 | {
16 | #if FEAT_IKVM
17 | readonly Type expectedType;
18 | #else
19 | static readonly Type expectedType = typeof(decimal);
20 | #endif
21 | public DecimalSerializer(ProtoBuf.Meta.TypeModel model)
22 | {
23 | #if FEAT_IKVM
24 | expectedType = model.MapType(typeof(decimal));
25 | #endif
26 | }
27 | public Type ExpectedType { get { return expectedType; } }
28 |
29 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
30 | bool IProtoSerializer.ReturnsValue { get { return true; } }
31 | #if !FEAT_IKVM
32 | public object Read(object value, ProtoReader source)
33 | {
34 | Helpers.DebugAssert(value == null); // since replaces
35 | return BclHelpers.ReadDecimal(source);
36 | }
37 | public void Write(object value, ProtoWriter dest)
38 | {
39 | BclHelpers.WriteDecimal((decimal)value, dest);
40 | }
41 | #endif
42 | #if FEAT_COMPILER
43 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
44 | {
45 | ctx.EmitWrite(ctx.MapType(typeof(BclHelpers)), "WriteDecimal", valueFrom);
46 | }
47 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
48 | {
49 | ctx.EmitBasicRead(ctx.MapType(typeof(BclHelpers)), "ReadDecimal", ExpectedType);
50 | }
51 | #endif
52 |
53 | }
54 | }
55 | #endif
--------------------------------------------------------------------------------
/protobuf-net/CallbackAttributes.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace ProtoBuf
5 | {
6 | /// Specifies a method on the root-contract in an hierarchy to be invoked before serialization.
7 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
8 | #if !CF && !SILVERLIGHT && !MONODROID && !WINRT && !IOS && !PORTABLE && !COREFX
9 | [ImmutableObject(true)]
10 | #endif
11 | public sealed class ProtoBeforeSerializationAttribute : Attribute { }
12 |
13 | /// Specifies a method on the root-contract in an hierarchy to be invoked after serialization.
14 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
15 | #if !CF && !SILVERLIGHT && !MONODROID && !WINRT && !IOS && !PORTABLE && !COREFX
16 | [ImmutableObject(true)]
17 | #endif
18 | public sealed class ProtoAfterSerializationAttribute : Attribute { }
19 |
20 | /// Specifies a method on the root-contract in an hierarchy to be invoked before deserialization.
21 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
22 | #if !CF && !SILVERLIGHT && !MONODROID && !WINRT && !IOS && !PORTABLE && !COREFX
23 | [ImmutableObject(true)]
24 | #endif
25 | public sealed class ProtoBeforeDeserializationAttribute : Attribute { }
26 |
27 | /// Specifies a method on the root-contract in an hierarchy to be invoked after deserialization.
28 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
29 | #if !CF && !SILVERLIGHT && !MONODROID && !WINRT && !IOS && !PORTABLE && !COREFX
30 | [ImmutableObject(true)]
31 | #endif
32 | public sealed class ProtoAfterDeserializationAttribute : Attribute { }
33 | }
34 |
--------------------------------------------------------------------------------
/protobuf-net/DataFormat.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace ProtoBuf
3 | {
4 | ///
5 | /// Sub-format to use when serializing/deserializing data
6 | ///
7 | public enum DataFormat
8 | {
9 | ///
10 | /// Uses the default encoding for the data-type.
11 | ///
12 | Default,
13 |
14 | ///
15 | /// When applied to signed integer-based data (including Decimal), this
16 | /// indicates that zigzag variant encoding will be used. This means that values
17 | /// with small magnitude (regardless of sign) take a small amount
18 | /// of space to encode.
19 | ///
20 | ZigZag,
21 |
22 | ///
23 | /// When applied to signed integer-based data (including Decimal), this
24 | /// indicates that two's-complement variant encoding will be used.
25 | /// This means that any -ve number will take 10 bytes (even for 32-bit),
26 | /// so should only be used for compatibility.
27 | ///
28 | TwosComplement,
29 |
30 | ///
31 | /// When applied to signed integer-based data (including Decimal), this
32 | /// indicates that a fixed amount of space will be used.
33 | ///
34 | FixedSize,
35 |
36 | ///
37 | /// When applied to a sub-message, indicates that the value should be treated
38 | /// as group-delimited.
39 | ///
40 | Group,
41 |
42 | ///
43 | /// When applied to members of types such as DateTime or TimeSpan, specifies
44 | /// that the "well known" standardized representation should be use; DateTime uses Timestamp,
45 | ///
46 | ///
47 | WellKnown
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/protobuf-net/KeyValuePairProxy.cs:
--------------------------------------------------------------------------------
1 | //#if !NO_GENERICS
2 | //using System.Collections.Generic;
3 |
4 | //namespace ProtoBuf
5 | //{
6 | // ///
7 | // /// Mutable version of the common key/value pair struct; used during serialization. This type is intended for internal use only and should not
8 | // /// be used by calling code; it is required to be public for implementation reasons.
9 | // ///
10 | // [ProtoContract]
11 | // public struct KeyValuePairSurrogate
12 | // {
13 | // private TKey key;
14 | // private TValue value;
15 | // ///
16 | // /// The key of the pair.
17 | // ///
18 | // [ProtoMember(1, IsRequired = true)]
19 | // public TKey Key { get { return key; } set { key = value; } }
20 | // ///
21 | // /// The value of the pair.
22 | // ///
23 | // [ProtoMember(2)]
24 | // public TValue Value{ get { return value; } set { this.value = value; } }
25 | // private KeyValuePairSurrogate(TKey key, TValue value)
26 | // {
27 | // this.key = key;
28 | // this.value = value;
29 | // }
30 | // ///
31 | // /// Convert a surrogate instance to a standard pair instance.
32 | // ///
33 | // public static implicit operator KeyValuePair (KeyValuePairSurrogate value)
34 | // {
35 | // return new KeyValuePair(value.key, value.value);
36 | // }
37 | // ///
38 | // /// Convert a standard pair instance to a surrogate instance.
39 | // ///
40 | // public static implicit operator KeyValuePairSurrogate(KeyValuePair value)
41 | // {
42 | // return new KeyValuePairSurrogate(value.Key, value.Value);
43 | // }
44 | // }
45 | //}
46 | //#endif
--------------------------------------------------------------------------------
/protobuf-net/ServiceModel/ProtoOperationBehavior.cs:
--------------------------------------------------------------------------------
1 | #if FEAT_SERVICEMODEL && PLAT_XMLSERIALIZER && !NO_GENERICS
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Runtime.Serialization;
5 | using System.ServiceModel.Description;
6 | using System.Xml;
7 | using ProtoBuf.Meta;
8 |
9 | namespace ProtoBuf.ServiceModel
10 | {
11 | ///
12 | /// Describes a WCF operation behaviour that can perform protobuf serialization
13 | ///
14 | public sealed class ProtoOperationBehavior : DataContractSerializerOperationBehavior
15 | {
16 | private TypeModel model;
17 | ///
18 | /// The type-model that should be used with this behaviour
19 | ///
20 | public TypeModel Model
21 | {
22 | get { return model; }
23 | set {
24 | if (value == null) throw new ArgumentNullException(nameof(value));
25 | model = value;
26 | }
27 |
28 | }
29 | ///
30 | /// Create a new ProtoOperationBehavior instance
31 | ///
32 | public ProtoOperationBehavior(OperationDescription operation) : base(operation)
33 | {
34 | #if !NO_RUNTIME
35 | model = RuntimeTypeModel.Default;
36 | #endif
37 | }
38 | //public ProtoOperationBehavior(OperationDescription operation, DataContractFormatAttribute dataContractFormat) : base(operation, dataContractFormat) { }
39 |
40 | ///
41 | /// Creates a protobuf serializer if possible (falling back to the default WCF serializer)
42 | ///
43 | public override XmlObjectSerializer CreateSerializer(Type type, System.Xml.XmlDictionaryString name, System.Xml.XmlDictionaryString ns, IList knownTypes)
44 | {
45 | if (model == null) throw new InvalidOperationException("No Model instance has been assigned to the ProtoOperationBehavior");
46 | return XmlProtoSerializer.TryCreate(model, type) ?? base.CreateSerializer(type, name, ns, knownTypes);
47 | }
48 | }
49 | }
50 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/BlobSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | #if COREFX
4 | using System.Reflection;
5 | #endif
6 | #if FEAT_COMPILER
7 | using System.Reflection.Emit;
8 | #endif
9 |
10 | #if FEAT_IKVM
11 | using Type = IKVM.Reflection.Type;
12 | #endif
13 |
14 |
15 | namespace ProtoBuf.Serializers
16 | {
17 | sealed class BlobSerializer : IProtoSerializer
18 | {
19 | public Type ExpectedType { get { return expectedType; } }
20 |
21 | #if FEAT_IKVM
22 | readonly Type expectedType;
23 | #else
24 | static readonly Type expectedType = typeof(byte[]);
25 | #endif
26 | public BlobSerializer(ProtoBuf.Meta.TypeModel model, bool overwriteList)
27 | {
28 | #if FEAT_IKVM
29 | expectedType = model.MapType(typeof(byte[]));
30 | #endif
31 | this.overwriteList = overwriteList;
32 | }
33 | private readonly bool overwriteList;
34 | #if !FEAT_IKVM
35 | public object Read(object value, ProtoReader source)
36 | {
37 | return ProtoReader.AppendBytes(overwriteList ? null : (byte[])value, source);
38 | }
39 | public void Write(object value, ProtoWriter dest)
40 | {
41 | ProtoWriter.WriteBytes((byte[])value, dest);
42 | }
43 | #endif
44 | bool IProtoSerializer.RequiresOldValue { get { return !overwriteList; } }
45 | bool IProtoSerializer.ReturnsValue { get { return true; } }
46 | #if FEAT_COMPILER
47 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
48 | {
49 | ctx.EmitBasicWrite("WriteBytes", valueFrom);
50 | }
51 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
52 | {
53 | if (overwriteList)
54 | {
55 | ctx.LoadNullRef();
56 | }
57 | else
58 | {
59 | ctx.LoadValue(valueFrom);
60 | }
61 | ctx.LoadReaderWriter();
62 | ctx.EmitCall(ctx.MapType(typeof(ProtoReader))
63 | .GetMethod("AppendBytes"));
64 | }
65 | #endif
66 | }
67 | }
68 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Compiler/Local.cs:
--------------------------------------------------------------------------------
1 | #if FEAT_COMPILER
2 | using System;
3 | #if FEAT_IKVM
4 | using IKVM.Reflection.Emit;
5 | using Type = IKVM.Reflection.Type;
6 | #else
7 | using System.Reflection.Emit;
8 | #endif
9 |
10 | namespace ProtoBuf.Compiler
11 | {
12 | internal sealed class Local : IDisposable
13 | {
14 | // public static readonly Local InputValue = new Local(null, null);
15 | LocalBuilder value;
16 | public Type Type { get { return type; } }
17 | public Local AsCopy()
18 | {
19 | if (ctx == null) return this; // can re-use if context-free
20 | return new Local(value, this.type);
21 | }
22 | internal LocalBuilder Value
23 | {
24 | get
25 | {
26 | if (value == null)
27 | {
28 | throw new ObjectDisposedException(GetType().Name);
29 | }
30 | return value;
31 | }
32 | }
33 | CompilerContext ctx;
34 | public void Dispose()
35 | {
36 | if (ctx != null)
37 | {
38 | // only *actually* dispose if this is context-bound; note that non-bound
39 | // objects are cheekily re-used, and *must* be left intact agter a "using" etc
40 | ctx.ReleaseToPool(value);
41 | value = null;
42 | ctx = null;
43 | }
44 |
45 | }
46 | private Local(LocalBuilder value, Type type)
47 | {
48 | this.value = value;
49 | this.type = type;
50 | }
51 | private readonly Type type;
52 | internal Local(Compiler.CompilerContext ctx, Type type)
53 | {
54 | this.ctx = ctx;
55 | if (ctx != null) { value = ctx.GetFromPool(type); }
56 | this.type = type;
57 | }
58 |
59 | internal bool IsSame(Local other)
60 | {
61 | if((object)this == (object)other) return true;
62 |
63 | object ourVal = value; // use prop to ensure obj-disposed etc
64 | return other != null && ourVal == (object)(other.value);
65 | }
66 | }
67 |
68 |
69 | }
70 | #endif
--------------------------------------------------------------------------------
/protobuf-net/IExtension.cs:
--------------------------------------------------------------------------------
1 |
2 | using System.IO;
3 | namespace ProtoBuf
4 | {
5 | ///
6 | /// Provides addition capability for supporting unexpected fields during
7 | /// protocol-buffer serialization/deserialization. This allows for loss-less
8 | /// round-trip/merge, even when the data is not fully understood.
9 | ///
10 | public interface IExtension
11 | {
12 | ///
13 | /// Requests a stream into which any unexpected fields can be persisted.
14 | ///
15 | /// A new stream suitable for storing data.
16 | Stream BeginAppend();
17 |
18 | ///
19 | /// Indicates that all unexpected fields have now been stored. The
20 | /// implementing class is responsible for closing the stream. If
21 | /// "commit" is not true the data may be discarded.
22 | ///
23 | /// The stream originally obtained by BeginAppend.
24 | /// True if the append operation completed successfully.
25 | void EndAppend(Stream stream, bool commit);
26 |
27 | ///
28 | /// Requests a stream of the unexpected fields previously stored.
29 | ///
30 | /// A prepared stream of the unexpected fields.
31 | Stream BeginQuery();
32 |
33 | ///
34 | /// Indicates that all unexpected fields have now been read. The
35 | /// implementing class is responsible for closing the stream.
36 | ///
37 | /// The stream originally obtained by BeginQuery.
38 | void EndQuery(Stream stream);
39 |
40 | ///
41 | /// Requests the length of the raw binary stream; this is used
42 | /// when serializing sub-entities to indicate the expected size.
43 | ///
44 | /// The length of the binary stream representing unexpected data.
45 | int GetLength();
46 | }
47 |
48 | ///
49 | /// Provides the ability to remove all existing extension data
50 | ///
51 | public interface IExtensionResettable : IExtension
52 | {
53 | ///
54 | /// Remove all existing extension data
55 | ///
56 | void Reset();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/TimeSpanSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 |
9 | #endif
10 |
11 |
12 |
13 | namespace ProtoBuf.Serializers
14 | {
15 | sealed class TimeSpanSerializer : IProtoSerializer
16 | {
17 | #if FEAT_IKVM
18 | readonly Type expectedType;
19 | #else
20 | static readonly Type expectedType = typeof(TimeSpan);
21 | #endif
22 | private readonly bool wellKnown;
23 | public TimeSpanSerializer(DataFormat dataFormat, ProtoBuf.Meta.TypeModel model)
24 | {
25 | #if FEAT_IKVM
26 | expectedType = model.MapType(typeof(TimeSpan));
27 | #endif
28 | wellKnown = dataFormat == DataFormat.WellKnown;
29 | }
30 | public Type ExpectedType => expectedType;
31 |
32 | bool IProtoSerializer.RequiresOldValue => false;
33 | bool IProtoSerializer.ReturnsValue => true;
34 | #if !FEAT_IKVM
35 | public object Read(object value, ProtoReader source)
36 | {
37 | if (wellKnown)
38 | {
39 | return BclHelpers.ReadDuration(source);
40 | }
41 | else
42 | {
43 | Helpers.DebugAssert(value == null); // since replaces
44 | return BclHelpers.ReadTimeSpan(source);
45 | }
46 | }
47 | public void Write(object value, ProtoWriter dest)
48 | {
49 | if (wellKnown)
50 | {
51 | BclHelpers.WriteDuration((TimeSpan)value, dest);
52 | }
53 | else
54 | {
55 | BclHelpers.WriteTimeSpan((TimeSpan)value, dest);
56 | }
57 | }
58 | #endif
59 | #if FEAT_COMPILER
60 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
61 | {
62 | ctx.EmitWrite(ctx.MapType(typeof(BclHelpers)),
63 | wellKnown ? nameof(BclHelpers.WriteDuration) : nameof(BclHelpers.WriteTimeSpan), valueFrom);
64 | }
65 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
66 | {
67 | if (wellKnown) ctx.LoadValue(valueFrom);
68 | ctx.EmitBasicRead(ctx.MapType(typeof(BclHelpers)),
69 | wellKnown ? nameof(BclHelpers.ReadDuration) : nameof(BclHelpers.ReadTimeSpan),
70 | ExpectedType);
71 | }
72 | #endif
73 |
74 | }
75 | }
76 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/UriDecorator.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | //using ProtoBuf.Compiler;
5 | #if FEAT_IKVM
6 | using Type = IKVM.Reflection.Type;
7 | using IKVM.Reflection;
8 | #else
9 |
10 | #endif
11 |
12 | namespace ProtoBuf.Serializers
13 | {
14 | sealed class UriDecorator : ProtoDecoratorBase
15 | {
16 | #if FEAT_IKVM
17 | readonly Type expectedType;
18 | #else
19 | static readonly Type expectedType = typeof(Uri);
20 | #endif
21 | public UriDecorator(ProtoBuf.Meta.TypeModel model, IProtoSerializer tail) : base(tail)
22 | {
23 | #if FEAT_IKVM
24 | expectedType = model.MapType(typeof(Uri));
25 | #endif
26 | }
27 | public override Type ExpectedType { get { return expectedType; } }
28 | public override bool RequiresOldValue { get { return false; } }
29 | public override bool ReturnsValue { get { return true; } }
30 |
31 |
32 | #if !FEAT_IKVM
33 | public override void Write(object value, ProtoWriter dest)
34 | {
35 | Tail.Write(((Uri)value).OriginalString, dest);
36 | }
37 |
38 | public override object Read(object value, ProtoReader source)
39 | {
40 | Helpers.DebugAssert(value == null); // not expecting incoming
41 | string s = (string)Tail.Read(null, source);
42 | return s.Length == 0 ? null : new Uri(s, UriKind.RelativeOrAbsolute);
43 | }
44 | #endif
45 |
46 | #if FEAT_COMPILER
47 | protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
48 | {
49 | ctx.LoadValue(valueFrom);
50 | ctx.LoadValue(typeof(Uri).GetProperty("OriginalString"));
51 | Tail.EmitWrite(ctx, null);
52 | }
53 | protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
54 | {
55 | Tail.EmitRead(ctx, valueFrom);
56 | ctx.CopyValue();
57 | Compiler.CodeLabel @nonEmpty = ctx.DefineLabel(), @end = ctx.DefineLabel();
58 | ctx.LoadValue(typeof(string).GetProperty("Length"));
59 | ctx.BranchIfTrue(@nonEmpty, true);
60 | ctx.DiscardValue();
61 | ctx.LoadNullRef();
62 | ctx.Branch(@end, true);
63 | ctx.MarkLabel(@nonEmpty);
64 | ctx.LoadValue((int)UriKind.RelativeOrAbsolute);
65 | ctx.EmitCtor(ctx.MapType(typeof(Uri)), ctx.MapType(typeof(string)), ctx.MapType(typeof(UriKind)));
66 | ctx.MarkLabel(@end);
67 | }
68 | #endif
69 | }
70 | }
71 | #endif
72 |
--------------------------------------------------------------------------------
/protobuf-net/Meta/TypeFormatEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ProtoBuf.Meta
4 | {
5 | ///
6 | /// Event arguments needed to perform type-formatting functions; this could be resolving a Type to a string suitable for serialization, or could
7 | /// be requesting a Type from a string. If no changes are made, a default implementation will be used (from the assembly-qualified names).
8 | ///
9 | public class TypeFormatEventArgs : EventArgs
10 | {
11 | private Type type;
12 | private string formattedName;
13 | private readonly bool typeFixed;
14 | ///
15 | /// The type involved in this map; if this is initially null, a Type is expected to be provided for the string in FormattedName.
16 | ///
17 | public Type Type
18 | {
19 | get { return type; }
20 | set
21 | {
22 | if(type != value)
23 | {
24 | if (typeFixed) throw new InvalidOperationException("The type is fixed and cannot be changed");
25 | type = value;
26 | }
27 | }
28 | }
29 | ///
30 | /// The formatted-name involved in this map; if this is initially null, a formatted-name is expected from the type in Type.
31 | ///
32 | public string FormattedName
33 | {
34 | get { return formattedName; }
35 | set
36 | {
37 | if (formattedName != value)
38 | {
39 | if (!typeFixed) throw new InvalidOperationException("The formatted-name is fixed and cannot be changed");
40 | formattedName = value;
41 | }
42 | }
43 | }
44 | internal TypeFormatEventArgs(string formattedName)
45 | {
46 | if (Helpers.IsNullOrEmpty(formattedName)) throw new ArgumentNullException("formattedName");
47 | this.formattedName = formattedName;
48 | // typeFixed = false; <== implicit
49 | }
50 | internal TypeFormatEventArgs(System.Type type)
51 | {
52 | if (type == null) throw new ArgumentNullException("type");
53 | this.type = type;
54 | typeFixed = true;
55 | }
56 |
57 | }
58 | ///
59 | /// Delegate type used to perform type-formatting functions; the sender originates as the type-model.
60 | ///
61 | public delegate void TypeFormatEventHandler(object sender, TypeFormatEventArgs args);
62 | }
63 |
--------------------------------------------------------------------------------
/protobuf-net/BufferExtension.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace ProtoBuf
4 | {
5 | ///
6 | /// Provides a simple buffer-based implementation of an extension object.
7 | ///
8 | public sealed class BufferExtension : IExtension, IExtensionResettable
9 | {
10 | private byte[] buffer;
11 |
12 |
13 | void IExtensionResettable.Reset()
14 | {
15 | buffer = null;
16 | }
17 |
18 | int IExtension.GetLength()
19 | {
20 | return buffer == null ? 0 : buffer.Length;
21 | }
22 |
23 | Stream IExtension.BeginAppend()
24 | {
25 | return new MemoryStream();
26 | }
27 |
28 | void IExtension.EndAppend(Stream stream, bool commit)
29 | {
30 | using (stream)
31 | {
32 | int len;
33 | if (commit && (len = (int)stream.Length) > 0)
34 | {
35 | MemoryStream ms = (MemoryStream)stream;
36 |
37 | if (buffer == null)
38 | { // allocate new buffer
39 | buffer = ms.ToArray();
40 | }
41 | else
42 | { // resize and copy the data
43 | // note: Array.Resize not available on CF
44 | int offset = buffer.Length;
45 | byte[] tmp = new byte[offset + len];
46 | Helpers.BlockCopy(buffer, 0, tmp, 0, offset);
47 |
48 | #if PORTABLE || WINRT // no GetBuffer() - fine, we'll use Read instead
49 | int bytesRead;
50 | long oldPos = ms.Position;
51 | ms.Position = 0;
52 | while (len > 0 && (bytesRead = ms.Read(tmp, offset, len)) > 0)
53 | {
54 | len -= bytesRead;
55 | offset += bytesRead;
56 | }
57 | if(len != 0) throw new EndOfStreamException();
58 | ms.Position = oldPos;
59 | #else
60 | Helpers.BlockCopy(Helpers.GetBuffer(ms), 0, tmp, offset, len);
61 | #endif
62 | buffer = tmp;
63 | }
64 | }
65 | }
66 | }
67 |
68 | Stream IExtension.BeginQuery()
69 | {
70 | return buffer == null ? Stream.Null : new MemoryStream(buffer);
71 | }
72 |
73 | void IExtension.EndQuery(Stream stream)
74 | {
75 | using (stream) { } // just clean up
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/NetObjectSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | using ProtoBuf.Meta;
4 |
5 | #if FEAT_IKVM
6 | using Type = IKVM.Reflection.Type;
7 | using IKVM.Reflection;
8 | #else
9 |
10 | #endif
11 |
12 | namespace ProtoBuf.Serializers
13 | {
14 |
15 | sealed class NetObjectSerializer : IProtoSerializer
16 | {
17 | private readonly int key;
18 | private readonly Type type;
19 |
20 | private readonly BclHelpers.NetObjectOptions options;
21 |
22 | public NetObjectSerializer(TypeModel model, Type type, int key, BclHelpers.NetObjectOptions options)
23 | {
24 | bool dynamicType = (options & BclHelpers.NetObjectOptions.DynamicType) != 0;
25 | this.key = dynamicType ? -1 : key;
26 | this.type = dynamicType ? model.MapType(typeof(object)) : type;
27 | this.options = options;
28 | }
29 |
30 | public Type ExpectedType
31 | {
32 | get { return type; }
33 | }
34 | public bool ReturnsValue
35 | {
36 | get { return true; }
37 | }
38 | public bool RequiresOldValue
39 | {
40 | get { return true; }
41 | }
42 | #if !FEAT_IKVM
43 | public object Read(object value, ProtoReader source)
44 | {
45 | return BclHelpers.ReadNetObject(value, source, key, type == typeof(object) ? null : type, options);
46 | }
47 | public void Write(object value, ProtoWriter dest)
48 | {
49 | BclHelpers.WriteNetObject(value, dest, key, options);
50 | }
51 | #endif
52 |
53 | #if FEAT_COMPILER
54 | public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
55 | {
56 | ctx.LoadValue(valueFrom);
57 | ctx.CastToObject(type);
58 | ctx.LoadReaderWriter();
59 | ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
60 | if (type == ctx.MapType(typeof(object))) ctx.LoadNullRef();
61 | else ctx.LoadValue(type);
62 | ctx.LoadValue((int)options);
63 | ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("ReadNetObject"));
64 | ctx.CastFromObject(type);
65 | }
66 | public void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
67 | {
68 | ctx.LoadValue(valueFrom);
69 | ctx.CastToObject(type);
70 | ctx.LoadReaderWriter();
71 | ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
72 | ctx.LoadValue((int)options);
73 | ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("WriteNetObject"));
74 | }
75 | #endif
76 | }
77 | }
78 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/DateTimeSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 |
9 | #endif
10 |
11 | namespace ProtoBuf.Serializers
12 | {
13 | sealed class DateTimeSerializer : IProtoSerializer
14 | {
15 | #if FEAT_IKVM
16 | readonly Type expectedType;
17 | #else
18 | static readonly Type expectedType = typeof(DateTime);
19 | #endif
20 | public Type ExpectedType => expectedType;
21 |
22 | bool IProtoSerializer.RequiresOldValue => false;
23 | bool IProtoSerializer.ReturnsValue => true;
24 |
25 | private readonly bool includeKind, wellKnown;
26 | public DateTimeSerializer(DataFormat dataFormat, ProtoBuf.Meta.TypeModel model)
27 | {
28 | #if FEAT_IKVM
29 | expectedType = model.MapType(typeof(DateTime));
30 | #endif
31 | wellKnown = dataFormat == DataFormat.WellKnown;
32 | includeKind = model != null && model.SerializeDateTimeKind();
33 | }
34 | #if !FEAT_IKVM
35 | public object Read(object value, ProtoReader source)
36 | {
37 | if(wellKnown)
38 | {
39 | return BclHelpers.ReadTimestamp(source);
40 | }
41 | else
42 | {
43 | Helpers.DebugAssert(value == null); // since replaces
44 | return BclHelpers.ReadDateTime(source);
45 | }
46 | }
47 | public void Write(object value, ProtoWriter dest)
48 | {
49 | if(wellKnown)
50 | BclHelpers.WriteTimestamp((DateTime)value, dest);
51 | else if(includeKind)
52 | BclHelpers.WriteDateTimeWithKind((DateTime)value, dest);
53 | else
54 | BclHelpers.WriteDateTime((DateTime)value, dest);
55 | }
56 | #endif
57 | #if FEAT_COMPILER
58 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
59 | {
60 | ctx.EmitWrite(ctx.MapType(typeof(BclHelpers)),
61 | wellKnown ? nameof(BclHelpers.WriteTimestamp)
62 | : includeKind ? nameof(BclHelpers.WriteDateTimeWithKind) : nameof(BclHelpers.WriteDateTime), valueFrom);
63 | }
64 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
65 | {
66 | if (wellKnown) ctx.LoadValue(valueFrom);
67 | ctx.EmitBasicRead(ctx.MapType(typeof(BclHelpers)),
68 | wellKnown ? nameof(BclHelpers.ReadTimestamp) : nameof(BclHelpers.ReadDateTime),
69 | ExpectedType);
70 | }
71 | #endif
72 |
73 | }
74 | }
75 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ReflectedUriDecorator.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | #if PORTABLE
3 | using System;
4 | using System.Reflection;
5 |
6 | namespace ProtoBuf.Serializers
7 | {
8 | ///
9 | /// Manipulates with uris via reflection rather than strongly typed objects.
10 | /// This is because in PCLs, the Uri type may not match (WinRT uses Internal/Uri, .Net uses System/Uri)
11 | ///
12 | sealed class ReflectedUriDecorator : ProtoDecoratorBase
13 | {
14 | private readonly Type expectedType;
15 |
16 | private readonly PropertyInfo absoluteUriProperty;
17 |
18 | private readonly ConstructorInfo typeConstructor;
19 |
20 | public ReflectedUriDecorator(Type type, ProtoBuf.Meta.TypeModel model, IProtoSerializer tail) : base(tail)
21 | {
22 | expectedType = type;
23 |
24 | absoluteUriProperty = expectedType.GetProperty("AbsoluteUri");
25 | typeConstructor = expectedType.GetConstructor(new Type[] { typeof(string) });
26 | }
27 | public override Type ExpectedType { get { return expectedType; } }
28 | public override bool RequiresOldValue { get { return false; } }
29 | public override bool ReturnsValue { get { return true; } }
30 |
31 | public override void Write(object value, ProtoWriter dest)
32 | {
33 | Tail.Write(absoluteUriProperty.GetValue(value, null), dest);
34 | }
35 | public override object Read(object value, ProtoReader source)
36 | {
37 | Helpers.DebugAssert(value == null); // not expecting incoming
38 | string s = (string)Tail.Read(null, source);
39 |
40 | return s.Length == 0 ? null : typeConstructor.Invoke(new object[] { s });
41 | }
42 |
43 | #if FEAT_COMPILER
44 | protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
45 | {
46 | ctx.LoadValue(valueFrom);
47 | ctx.LoadValue(absoluteUriProperty);
48 | Tail.EmitWrite(ctx, null);
49 | }
50 | protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
51 | {
52 | Tail.EmitRead(ctx, valueFrom);
53 | ctx.CopyValue();
54 | Compiler.CodeLabel @nonEmpty = ctx.DefineLabel(), @end = ctx.DefineLabel();
55 | ctx.LoadValue(typeof(string).GetProperty("Length"));
56 | ctx.BranchIfTrue(@nonEmpty, true);
57 | ctx.DiscardValue();
58 | ctx.LoadNullRef();
59 | ctx.Branch(@end, true);
60 | ctx.MarkLabel(@nonEmpty);
61 | ctx.EmitCtor(expectedType, ctx.MapType(typeof(string)));
62 | ctx.MarkLabel(@end);
63 |
64 | }
65 | #endif
66 | }
67 | }
68 | #endif
69 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/MemberSpecifiedDecorator.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | #if FEAT_IKVM
4 | using Type = IKVM.Reflection.Type;
5 | using IKVM.Reflection;
6 | #else
7 | using System.Reflection;
8 | #endif
9 |
10 |
11 |
12 | namespace ProtoBuf.Serializers
13 | {
14 | sealed class MemberSpecifiedDecorator : ProtoDecoratorBase
15 | {
16 |
17 | public override Type ExpectedType { get { return Tail.ExpectedType; } }
18 | public override bool RequiresOldValue { get { return Tail.RequiresOldValue; } }
19 | public override bool ReturnsValue { get { return Tail.ReturnsValue; } }
20 | private readonly MethodInfo getSpecified, setSpecified;
21 | public MemberSpecifiedDecorator(MethodInfo getSpecified, MethodInfo setSpecified, IProtoSerializer tail)
22 | : base(tail)
23 | {
24 | if (getSpecified == null && setSpecified == null) throw new InvalidOperationException();
25 | this.getSpecified = getSpecified;
26 | this.setSpecified = setSpecified;
27 | }
28 | #if !FEAT_IKVM
29 | public override void Write(object value, ProtoWriter dest)
30 | {
31 | if(getSpecified == null || (bool)getSpecified.Invoke(value, null))
32 | {
33 | Tail.Write(value, dest);
34 | }
35 | }
36 | public override object Read(object value, ProtoReader source)
37 | {
38 | object result = Tail.Read(value, source);
39 | if (setSpecified != null) setSpecified.Invoke(value, new object[] { true });
40 | return result;
41 | }
42 | #endif
43 |
44 | #if FEAT_COMPILER
45 | protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
46 | {
47 | if (getSpecified == null)
48 | {
49 | Tail.EmitWrite(ctx, valueFrom);
50 | return;
51 | }
52 | using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
53 | {
54 | ctx.LoadAddress(loc, ExpectedType);
55 | ctx.EmitCall(getSpecified);
56 | Compiler.CodeLabel done = ctx.DefineLabel();
57 | ctx.BranchIfFalse(done, false);
58 | Tail.EmitWrite(ctx, loc);
59 | ctx.MarkLabel(done);
60 | }
61 |
62 | }
63 | protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
64 | {
65 | if (setSpecified == null)
66 | {
67 | Tail.EmitRead(ctx, valueFrom);
68 | return;
69 | }
70 | using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
71 | {
72 | Tail.EmitRead(ctx, loc);
73 | ctx.LoadAddress(loc, ExpectedType);
74 | ctx.LoadValue(1); // true
75 | ctx.EmitCall(setSpecified);
76 | }
77 | }
78 | #endif
79 | }
80 | }
81 | #endif
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/Token.cs:
--------------------------------------------------------------------------------
1 | using Google.Protobuf.Reflection;
2 | using System;
3 |
4 | namespace ProtoBuf.Reflection
5 | {
6 | internal struct Token
7 | {
8 |
9 | public static bool operator ==(Token x, Token y)
10 | {
11 | return x.Offset == y.Offset && x.File == y.File;
12 | }
13 | public static bool operator !=(Token x, Token y)
14 | {
15 | return x.Offset != y.Offset || x.File != y.File;
16 | }
17 | public override int GetHashCode() => Offset;
18 | public override bool Equals(object obj) => (obj is Token) && ((Token)obj).Offset == this.Offset;
19 | public bool Equals(Token token) => token.Offset == this.Offset;
20 | public int Offset { get; }
21 | public int LineNumber { get; }
22 | public string File { get; }
23 | public int ColumnNumber { get; }
24 | public TokenType Type { get; }
25 | public string Value { get; }
26 | public string LineContents { get; }
27 | internal Token(string value, int lineNumber, int columnNumber, TokenType type, string lineContents, int offset, string file)
28 | {
29 | Value = value;
30 | LineNumber = lineNumber;
31 | ColumnNumber = columnNumber;
32 | File = file;
33 | Type = type;
34 | LineContents = lineContents;
35 | Offset = offset;
36 | }
37 | public override string ToString() => $"({LineNumber},{ColumnNumber}) '{Value}'";
38 |
39 |
40 | internal Exception Throw(string error = null, bool isError = true)
41 | {
42 | throw new ParserException(this, string.IsNullOrWhiteSpace(error) ? $"syntax error: '{Value}'" : error, isError);
43 | }
44 |
45 | internal void Assert(TokenType type, string value = null)
46 | {
47 | if (value != null)
48 | {
49 | if (type != Type || value != Value)
50 | {
51 | Throw($"expected {type} '{value}'");
52 | }
53 |
54 | }
55 | else
56 | {
57 | if (type != Type)
58 | {
59 | Throw($"expected {type}");
60 | }
61 | }
62 | }
63 |
64 | internal bool Is(TokenType type, string value = null)
65 | {
66 | if (type != Type) return false;
67 | if (value != null && value != Value) return false;
68 | return true;
69 | }
70 |
71 | internal void RequireProto2(ParserContext ctx)
72 | {
73 | if(ctx.Syntax != FileDescriptorProto.SyntaxProto2)
74 | {
75 | var msg = "'" + Value + "' requires " + FileDescriptorProto.SyntaxProto2 + " syntax";
76 | ctx.Errors.Error(this, msg);
77 | }
78 | }
79 |
80 | internal Error TypeNotFound(string typeName = null) => new Error(this,
81 | $"type not found: '{(string.IsNullOrWhiteSpace(typeName) ? Value : typeName)}'", true);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/IProtoSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | #endif
7 |
8 | namespace ProtoBuf.Serializers
9 | {
10 | interface IProtoSerializer
11 | {
12 | ///
13 | /// The type that this serializer is intended to work for.
14 | ///
15 | Type ExpectedType { get; }
16 |
17 | #if !FEAT_IKVM
18 | ///
19 | /// Perform the steps necessary to serialize this data.
20 | ///
21 | /// The value to be serialized.
22 | /// The writer entity that is accumulating the output data.
23 | void Write(object value, ProtoWriter dest);
24 |
25 | ///
26 | /// Perform the steps necessary to deserialize this data.
27 | ///
28 | /// The current value, if appropriate.
29 | /// The reader providing the input data.
30 | /// The updated / replacement value.
31 | object Read(object value, ProtoReader source);
32 | #endif
33 | ///
34 | /// Indicates whether a Read operation replaces the existing value, or
35 | /// extends the value. If false, the "value" parameter to Read is
36 | /// discarded, and should be passed in as null.
37 | ///
38 | bool RequiresOldValue { get; }
39 | ///
40 | /// Now all Read operations return a value (although most do); if false no
41 | /// value should be expected.
42 | ///
43 | bool ReturnsValue { get; }
44 |
45 | #if FEAT_COMPILER
46 |
47 |
48 |
49 | /// Emit the IL necessary to perform the given actions
50 | /// to serialize this data.
51 | ///
52 | /// Details and utilities for the method being generated.
53 | /// The source of the data to work against;
54 | /// If the value is only needed once, then LoadValue is sufficient. If
55 | /// the value is needed multiple times, then note that a "null"
56 | /// means "the top of the stack", in which case you should create your
57 | /// own copy - GetLocalWithValue.
58 | void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom);
59 |
60 | ///
61 | /// Emit the IL necessary to perform the given actions to deserialize this data.
62 | ///
63 | /// Details and utilities for the method being generated.
64 | /// For nested values, the instance holding the values; note
65 | /// that this is not always provided - a null means not supplied. Since this is always
66 | /// a variable or argument, it is not necessary to consume this value.
67 | void EmitRead(Compiler.CompilerContext ctx, Compiler.Local entity);
68 | #endif
69 | }
70 | }
71 | #endif
--------------------------------------------------------------------------------
/protobuf-net/SerializationContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ProtoBuf
4 | {
5 | ///
6 | /// Additional information about a serialization operation
7 | ///
8 | public sealed class SerializationContext
9 | {
10 | private bool frozen;
11 | internal void Freeze() { frozen = true;}
12 | private void ThrowIfFrozen() { if (frozen) throw new InvalidOperationException("The serialization-context cannot be changed once it is in use"); }
13 | private object context;
14 | ///
15 | /// Gets or sets a user-defined object containing additional information about this serialization/deserialization operation.
16 | ///
17 | public object Context
18 | {
19 | get { return context; }
20 | set { if (context != value) { ThrowIfFrozen(); context = value; } }
21 | }
22 |
23 | private static readonly SerializationContext @default;
24 | static SerializationContext()
25 | {
26 | @default = new SerializationContext();
27 | @default.Freeze();
28 | }
29 | ///
30 | /// A default SerializationContext, with minimal information.
31 | ///
32 | internal static SerializationContext Default { get {return @default;}}
33 | #if PLAT_BINARYFORMATTER || (SILVERLIGHT && NET_4_0)
34 |
35 | #if !(WINRT || PHONE7 || PHONE8 || COREFX)
36 | private System.Runtime.Serialization.StreamingContextStates state = System.Runtime.Serialization.StreamingContextStates.Persistence;
37 | ///
38 | /// Gets or sets the source or destination of the transmitted data.
39 | ///
40 | public System.Runtime.Serialization.StreamingContextStates State
41 | {
42 | get { return state; }
43 | set { if (state != value) { ThrowIfFrozen(); state = value; } }
44 | }
45 | #endif
46 | ///
47 | /// Convert a SerializationContext to a StreamingContext
48 | ///
49 | public static implicit operator System.Runtime.Serialization.StreamingContext(SerializationContext ctx)
50 | {
51 | #if WINRT || PHONE7 || PHONE8 || COREFX
52 | return new System.Runtime.Serialization.StreamingContext();
53 | #else
54 | if (ctx == null) return new System.Runtime.Serialization.StreamingContext(System.Runtime.Serialization.StreamingContextStates.Persistence);
55 | return new System.Runtime.Serialization.StreamingContext(ctx.state, ctx.context);
56 | #endif
57 | }
58 | ///
59 | /// Convert a StreamingContext to a SerializationContext
60 | ///
61 | public static implicit operator SerializationContext (System.Runtime.Serialization.StreamingContext ctx)
62 | {
63 | SerializationContext result = new SerializationContext();
64 |
65 | #if !(WINRT || PHONE7 || PHONE8 || COREFX)
66 | result.Context = ctx.Context;
67 | result.State = ctx.State;
68 | #endif
69 |
70 | return result;
71 | }
72 | #endif
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/protobuf-net/ProtoIncludeAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | using ProtoBuf.Meta;
5 | #if FEAT_IKVM
6 | using Type = IKVM.Reflection.Type;
7 | using IKVM.Reflection;
8 | #else
9 |
10 | #endif
11 | namespace ProtoBuf
12 | {
13 | ///
14 | /// Indicates the known-types to support for an individual
15 | /// message. This serializes each level in the hierarchy as
16 | /// a nested message to retain wire-compatibility with
17 | /// other protocol-buffer implementations.
18 | ///
19 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)]
20 | public sealed class ProtoIncludeAttribute : Attribute
21 | {
22 | ///
23 | /// Creates a new instance of the ProtoIncludeAttribute.
24 | ///
25 | /// The unique index (within the type) that will identify this data.
26 | /// The additional type to serialize/deserialize.
27 | public ProtoIncludeAttribute(int tag, System.Type knownType)
28 | : this(tag, knownType == null ? "" : knownType.AssemblyQualifiedName) { }
29 |
30 | ///
31 | /// Creates a new instance of the ProtoIncludeAttribute.
32 | ///
33 | /// The unique index (within the type) that will identify this data.
34 | /// The additional type to serialize/deserialize.
35 | public ProtoIncludeAttribute(int tag, string knownTypeName)
36 | {
37 | if (tag <= 0) throw new ArgumentOutOfRangeException("tag", "Tags must be positive integers");
38 | if (Helpers.IsNullOrEmpty(knownTypeName)) throw new ArgumentNullException("knownTypeName", "Known type cannot be blank");
39 | this.tag = tag;
40 | this.knownTypeName = knownTypeName;
41 | }
42 |
43 | ///
44 | /// Gets the unique index (within the type) that will identify this data.
45 | ///
46 | public int Tag { get { return tag; } }
47 | private readonly int tag;
48 |
49 | ///
50 | /// Gets the additional type to serialize/deserialize.
51 | ///
52 | public string KnownTypeName { get { return knownTypeName; } }
53 | private readonly string knownTypeName;
54 |
55 | ///
56 | /// Gets the additional type to serialize/deserialize.
57 | ///
58 | public Type KnownType
59 | {
60 | get
61 | {
62 | return TypeModel.ResolveKnownType(KnownTypeName, null, null);
63 | }
64 | }
65 |
66 | ///
67 | /// Specifies whether the inherited sype's sub-message should be
68 | /// written with a length-prefix (default), or with group markers.
69 | ///
70 | [DefaultValue(DataFormat.Default)]
71 | public DataFormat DataFormat
72 | {
73 | get { return dataFormat; }
74 | set { dataFormat = value; }
75 | }
76 | private DataFormat dataFormat = DataFormat.Default;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/CompiledSerializer.cs:
--------------------------------------------------------------------------------
1 | #if FEAT_COMPILER && !(FX11 || FEAT_IKVM)
2 | using System;
3 | using ProtoBuf.Meta;
4 |
5 |
6 |
7 | namespace ProtoBuf.Serializers
8 | {
9 | sealed class CompiledSerializer : IProtoTypeSerializer
10 | {
11 | bool IProtoTypeSerializer.HasCallbacks(TypeModel.CallbackType callbackType)
12 | {
13 | return head.HasCallbacks(callbackType); // these routes only used when bits of the model not compiled
14 | }
15 | bool IProtoTypeSerializer.CanCreateInstance()
16 | {
17 | return head.CanCreateInstance();
18 | }
19 | object IProtoTypeSerializer.CreateInstance(ProtoReader source)
20 | {
21 | return head.CreateInstance(source);
22 | }
23 | public void Callback(object value, TypeModel.CallbackType callbackType, SerializationContext context)
24 | {
25 | head.Callback(value, callbackType, context); // these routes only used when bits of the model not compiled
26 | }
27 | public static CompiledSerializer Wrap(IProtoTypeSerializer head, TypeModel model)
28 | {
29 | CompiledSerializer result = head as CompiledSerializer;
30 | if (result == null)
31 | {
32 | result = new CompiledSerializer(head, model);
33 | Helpers.DebugAssert(((IProtoTypeSerializer)result).ExpectedType == head.ExpectedType);
34 | }
35 | return result;
36 | }
37 | private readonly IProtoTypeSerializer head;
38 | private readonly Compiler.ProtoSerializer serializer;
39 | private readonly Compiler.ProtoDeserializer deserializer;
40 | private CompiledSerializer(IProtoTypeSerializer head, TypeModel model)
41 | {
42 | this.head = head;
43 | serializer = Compiler.CompilerContext.BuildSerializer(head, model);
44 | deserializer = Compiler.CompilerContext.BuildDeserializer(head, model);
45 | }
46 | bool IProtoSerializer.RequiresOldValue { get { return head.RequiresOldValue; } }
47 | bool IProtoSerializer.ReturnsValue { get { return head.ReturnsValue; } }
48 |
49 | Type IProtoSerializer.ExpectedType { get { return head.ExpectedType; } }
50 |
51 | void IProtoSerializer.Write(object value, ProtoWriter dest)
52 | {
53 | serializer(value, dest);
54 | }
55 | object IProtoSerializer.Read(object value, ProtoReader source)
56 | {
57 | return deserializer(value, source);
58 | }
59 |
60 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
61 | {
62 | head.EmitWrite(ctx, valueFrom);
63 | }
64 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
65 | {
66 | head.EmitRead(ctx, valueFrom);
67 | }
68 | void IProtoTypeSerializer.EmitCallback(Compiler.CompilerContext ctx, Compiler.Local valueFrom, TypeModel.CallbackType callbackType)
69 | {
70 | head.EmitCallback(ctx, valueFrom, callbackType);
71 | }
72 | void IProtoTypeSerializer.EmitCreateInstance(Compiler.CompilerContext ctx)
73 | {
74 | head.EmitCreateInstance(ctx);
75 | }
76 | }
77 | }
78 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Meta/SubType.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | using ProtoBuf.Serializers;
4 |
5 | namespace ProtoBuf.Meta
6 | {
7 | ///
8 | /// Represents an inherited type in a type hierarchy.
9 | ///
10 | public sealed class SubType
11 | {
12 | internal sealed class Comparer : System.Collections.IComparer
13 | #if !NO_GENERICS
14 | , System.Collections.Generic.IComparer
15 | #endif
16 | {
17 | public static readonly Comparer Default = new Comparer();
18 | public int Compare(object x, object y)
19 | {
20 | return Compare(x as SubType, y as SubType);
21 | }
22 | public int Compare(SubType x, SubType y)
23 | {
24 | if (ReferenceEquals(x, y)) return 0;
25 | if (x == null) return -1;
26 | if (y == null) return 1;
27 |
28 | return x.FieldNumber.CompareTo(y.FieldNumber);
29 | }
30 | }
31 | private readonly int fieldNumber;
32 | ///
33 | /// The field-number that is used to encapsulate the data (as a nested
34 | /// message) for the derived dype.
35 | ///
36 | public int FieldNumber { get { return fieldNumber; } }
37 | ///
38 | /// The sub-type to be considered.
39 | ///
40 | public MetaType DerivedType { get { return derivedType; } }
41 | private readonly MetaType derivedType;
42 |
43 | ///
44 | /// Creates a new SubType instance.
45 | ///
46 | /// The field-number that is used to encapsulate the data (as a nested
47 | /// message) for the derived dype.
48 | /// The sub-type to be considered.
49 | /// Specific encoding style to use; in particular, Grouped can be used to avoid buffering, but is not the default.
50 | public SubType(int fieldNumber, MetaType derivedType, DataFormat format)
51 | {
52 | if (derivedType == null) throw new ArgumentNullException("derivedType");
53 | if (fieldNumber <= 0) throw new ArgumentOutOfRangeException("fieldNumber");
54 | this.fieldNumber = fieldNumber;
55 | this.derivedType = derivedType;
56 | this.dataFormat = format;
57 | }
58 |
59 | private readonly DataFormat dataFormat;
60 |
61 | private IProtoSerializer serializer;
62 | internal IProtoSerializer Serializer
63 | {
64 | get
65 | {
66 | if (serializer == null) serializer = BuildSerializer();
67 | return serializer;
68 | }
69 | }
70 |
71 | private IProtoSerializer BuildSerializer()
72 | {
73 | // note the caller here is MetaType.BuildSerializer, which already has the sync-lock
74 | WireType wireType = WireType.String;
75 | if(dataFormat == DataFormat.Group) wireType = WireType.StartGroup; // only one exception
76 |
77 | IProtoSerializer ser = new SubItemSerializer(derivedType.Type, derivedType.GetKey(false, false), derivedType, false);
78 | return new TagDecorator(fieldNumber, wireType, false, ser);
79 | }
80 | }
81 | }
82 | #endif
--------------------------------------------------------------------------------
/protobuf-net/BufferPool.cs:
--------------------------------------------------------------------------------
1 |
2 | using System.Threading;
3 | namespace ProtoBuf
4 | {
5 | internal sealed class BufferPool
6 | {
7 | internal static void Flush()
8 | {
9 | #if PLAT_NO_INTERLOCKED
10 | lock(pool)
11 | {
12 | for (int i = 0; i < pool.Length; i++) pool[i] = null;
13 | }
14 | #else
15 | for (int i = 0; i < pool.Length; i++)
16 | {
17 | Interlocked.Exchange(ref pool[i], null); // and drop the old value on the floor
18 | }
19 | #endif
20 | }
21 | private BufferPool() { }
22 | const int PoolSize = 20;
23 | internal const int BufferLength = 1024;
24 | private static readonly object[] pool = new object[PoolSize];
25 |
26 | internal static byte[] GetBuffer()
27 | {
28 | object tmp;
29 | #if PLAT_NO_INTERLOCKED
30 | lock(pool)
31 | {
32 | for (int i = 0; i < pool.Length; i++)
33 | {
34 | if((tmp = pool[i]) != null)
35 | {
36 | pool[i] = null;
37 | return (byte[])tmp;
38 | }
39 | }
40 | }
41 | #else
42 | for (int i = 0; i < pool.Length; i++)
43 | {
44 | if ((tmp = Interlocked.Exchange(ref pool[i], null)) != null) return (byte[])tmp;
45 | }
46 | #endif
47 | return new byte[BufferLength];
48 | }
49 | internal static void ResizeAndFlushLeft(ref byte[] buffer, int toFitAtLeastBytes, int copyFromIndex, int copyBytes)
50 | {
51 | Helpers.DebugAssert(buffer != null);
52 | Helpers.DebugAssert(toFitAtLeastBytes > buffer.Length);
53 | Helpers.DebugAssert(copyFromIndex >= 0);
54 | Helpers.DebugAssert(copyBytes >= 0);
55 |
56 | // try doubling, else match
57 | int newLength = buffer.Length * 2;
58 | if (newLength < toFitAtLeastBytes) newLength = toFitAtLeastBytes;
59 |
60 | byte[] newBuffer = new byte[newLength];
61 | if (copyBytes > 0)
62 | {
63 | Helpers.BlockCopy(buffer, copyFromIndex, newBuffer, 0, copyBytes);
64 | }
65 | if (buffer.Length == BufferPool.BufferLength)
66 | {
67 | BufferPool.ReleaseBufferToPool(ref buffer);
68 | }
69 | buffer = newBuffer;
70 | }
71 | internal static void ReleaseBufferToPool(ref byte[] buffer)
72 | {
73 | if (buffer == null) return;
74 | if (buffer.Length == BufferLength)
75 | {
76 | #if PLAT_NO_INTERLOCKED
77 | lock (pool)
78 | {
79 | for (int i = 0; i < pool.Length; i++)
80 | {
81 | if(pool[i] == null)
82 | {
83 | pool[i] = buffer;
84 | break;
85 | }
86 | }
87 | }
88 | #else
89 | for (int i = 0; i < pool.Length; i++)
90 | {
91 | if (Interlocked.CompareExchange(ref pool[i], buffer, null) == null)
92 | {
93 | break; // found a null; swapped it in
94 | }
95 | }
96 | #endif
97 | }
98 | // if no space, just drop it on the floor
99 | buffer = null;
100 | }
101 |
102 | }
103 | }
--------------------------------------------------------------------------------
/protobuf-net/ServiceModel/ProtoEndpointBehavior.cs:
--------------------------------------------------------------------------------
1 | #if FEAT_SERVICEMODEL && PLAT_XMLSERIALIZER
2 | using System.ServiceModel.Description;
3 |
4 | namespace ProtoBuf.ServiceModel
5 | {
6 | ///
7 | /// Behavior to swap out DatatContractSerilaizer with the XmlProtoSerializer for a given endpoint.
8 | ///
9 | /// Add the following to the server and client app.config in the system.serviceModel section:
10 | ///
11 | ///
12 | ///
13 | ///
14 | ///
15 | ///
16 | ///
17 | ///
18 | ///
19 | ///
20 | ///
21 | ///
22 | ///
23 | /// Configure your endpoints to have a behaviorConfiguration as follows:
24 | ///
25 | ///
26 | ///
28 | ///
29 | ///
30 | ///
33 | ///
34 | ///
35 | ///
36 | public class ProtoEndpointBehavior : IEndpointBehavior
37 | {
38 | #region IEndpointBehavior Members
39 |
40 | void IEndpointBehavior.AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
41 | {
42 | }
43 |
44 | void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
45 | {
46 | ReplaceDataContractSerializerOperationBehavior(endpoint);
47 | }
48 |
49 | void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
50 | {
51 | ReplaceDataContractSerializerOperationBehavior(endpoint);
52 | }
53 |
54 | void IEndpointBehavior.Validate(ServiceEndpoint endpoint)
55 | {
56 | }
57 |
58 | private static void ReplaceDataContractSerializerOperationBehavior(ServiceEndpoint serviceEndpoint)
59 | {
60 | foreach (OperationDescription operationDescription in serviceEndpoint.Contract.Operations)
61 | {
62 | ReplaceDataContractSerializerOperationBehavior(operationDescription);
63 | }
64 | }
65 |
66 |
67 | private static void ReplaceDataContractSerializerOperationBehavior(OperationDescription description)
68 | {
69 | DataContractSerializerOperationBehavior dcsOperationBehavior = description.Behaviors.Find();
70 | if (dcsOperationBehavior != null)
71 | {
72 | description.Behaviors.Remove(dcsOperationBehavior);
73 |
74 | ProtoOperationBehavior newBehavior = new ProtoOperationBehavior(description);
75 | newBehavior.MaxItemsInObjectGraph = dcsOperationBehavior.MaxItemsInObjectGraph;
76 | description.Behaviors.Add(newBehavior);
77 | }
78 | }
79 |
80 |
81 | #endregion
82 | }
83 |
84 | }
85 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/TagDecorator.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | using ProtoBuf.Meta;
5 |
6 | #if FEAT_IKVM
7 | using Type = IKVM.Reflection.Type;
8 | using IKVM.Reflection;
9 | #else
10 |
11 | #endif
12 |
13 |
14 | namespace ProtoBuf.Serializers
15 | {
16 | sealed class TagDecorator : ProtoDecoratorBase, IProtoTypeSerializer
17 | {
18 |
19 | public bool HasCallbacks(TypeModel.CallbackType callbackType)
20 | {
21 | IProtoTypeSerializer pts = Tail as IProtoTypeSerializer;
22 | return pts != null && pts.HasCallbacks(callbackType);
23 | }
24 |
25 | public bool CanCreateInstance()
26 | {
27 | IProtoTypeSerializer pts = Tail as IProtoTypeSerializer;
28 | return pts != null && pts.CanCreateInstance();
29 | }
30 | #if !FEAT_IKVM
31 | public object CreateInstance(ProtoReader source)
32 | {
33 | return ((IProtoTypeSerializer)Tail).CreateInstance(source);
34 | }
35 | public void Callback(object value, TypeModel.CallbackType callbackType, SerializationContext context)
36 | {
37 | IProtoTypeSerializer pts = Tail as IProtoTypeSerializer;
38 | if (pts != null) pts.Callback(value, callbackType, context);
39 | }
40 | #endif
41 | #if FEAT_COMPILER
42 | public void EmitCallback(Compiler.CompilerContext ctx, Compiler.Local valueFrom, TypeModel.CallbackType callbackType)
43 | {
44 | // we only expect this to be invoked if HasCallbacks returned true, so implicitly Tail
45 | // **must** be of the correct type
46 | ((IProtoTypeSerializer)Tail).EmitCallback(ctx, valueFrom, callbackType);
47 | }
48 | public void EmitCreateInstance(Compiler.CompilerContext ctx)
49 | {
50 | ((IProtoTypeSerializer)Tail).EmitCreateInstance(ctx);
51 | }
52 | #endif
53 | public override Type ExpectedType
54 | {
55 | get { return Tail.ExpectedType; }
56 | }
57 | public TagDecorator(int fieldNumber, WireType wireType, bool strict, IProtoSerializer tail)
58 | : base(tail)
59 | {
60 | this.fieldNumber = fieldNumber;
61 | this.wireType = wireType;
62 | this.strict = strict;
63 | }
64 | public override bool RequiresOldValue { get { return Tail.RequiresOldValue; } }
65 | public override bool ReturnsValue { get { return Tail.ReturnsValue; } }
66 | private readonly bool strict;
67 | private readonly int fieldNumber;
68 | private readonly WireType wireType;
69 |
70 | private bool NeedsHint
71 | {
72 | get { return ((int)wireType & ~7) != 0; }
73 | }
74 | #if !FEAT_IKVM
75 | public override object Read(object value, ProtoReader source)
76 | {
77 | Helpers.DebugAssert(fieldNumber == source.FieldNumber);
78 | if (strict) { source.Assert(wireType); }
79 | else if (NeedsHint) { source.Hint(wireType); }
80 | return Tail.Read(value, source);
81 | }
82 | public override void Write(object value, ProtoWriter dest)
83 | {
84 | ProtoWriter.WriteFieldHeader(fieldNumber, wireType, dest);
85 | Tail.Write(value, dest);
86 | }
87 | #endif
88 |
89 | #if FEAT_COMPILER
90 | protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
91 | {
92 | ctx.LoadValue((int)fieldNumber);
93 | ctx.LoadValue((int)wireType);
94 | ctx.LoadReaderWriter();
95 | ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("WriteFieldHeader"));
96 | Tail.EmitWrite(ctx, valueFrom);
97 | }
98 | protected override void EmitRead(ProtoBuf.Compiler.CompilerContext ctx, ProtoBuf.Compiler.Local valueFrom)
99 | {
100 | if (strict || NeedsHint)
101 | {
102 | ctx.LoadReaderWriter();
103 | ctx.LoadValue((int)wireType);
104 | ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod(strict ? "Assert" : "Hint"));
105 | }
106 | Tail.EmitRead(ctx, valueFrom);
107 | }
108 | #endif
109 | }
110 |
111 | }
112 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/FieldDecorator.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | #if FEAT_IKVM
4 | using Type = IKVM.Reflection.Type;
5 | using IKVM.Reflection;
6 | #else
7 | using System.Reflection;
8 | #endif
9 |
10 |
11 |
12 | namespace ProtoBuf.Serializers
13 | {
14 | sealed class FieldDecorator : ProtoDecoratorBase
15 | {
16 |
17 | public override Type ExpectedType { get { return forType; } }
18 | private readonly FieldInfo field;
19 | private readonly Type forType;
20 | public override bool RequiresOldValue { get { return true; } }
21 | public override bool ReturnsValue { get { return false; } }
22 | public FieldDecorator(Type forType, FieldInfo field, IProtoSerializer tail) : base(tail)
23 | {
24 | Helpers.DebugAssert(forType != null);
25 | Helpers.DebugAssert(field != null);
26 | this.forType = forType;
27 | this.field = field;
28 | }
29 | #if !FEAT_IKVM
30 | public override void Write(object value, ProtoWriter dest)
31 | {
32 | Helpers.DebugAssert(value != null);
33 | value = field.GetValue(value);
34 | if(value != null) Tail.Write(value, dest);
35 | }
36 | public override object Read(object value, ProtoReader source)
37 | {
38 | Helpers.DebugAssert(value != null);
39 | object newValue = Tail.Read((Tail.RequiresOldValue ? field.GetValue(value) : null), source);
40 | if(newValue != null) field.SetValue(value,newValue);
41 | return null;
42 | }
43 | #endif
44 |
45 | #if FEAT_COMPILER
46 | protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
47 | {
48 | ctx.LoadAddress(valueFrom, ExpectedType);
49 | ctx.LoadValue(field);
50 | ctx.WriteNullCheckedTail(field.FieldType, Tail, null);
51 | }
52 | protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
53 | {
54 | using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
55 | {
56 | if (Tail.RequiresOldValue)
57 | {
58 | ctx.LoadAddress(loc, ExpectedType);
59 | ctx.LoadValue(field);
60 | }
61 | // value is either now on the stack or not needed
62 | ctx.ReadNullCheckedTail(field.FieldType, Tail, null);
63 |
64 | // the field could be a backing field that needs to be raised back to
65 | // the property if we're doing a full compile
66 | MemberInfo member = field;
67 | ctx.CheckAccessibility(ref member);
68 | bool writeValue = member is FieldInfo;
69 |
70 | if (writeValue)
71 | {
72 | if (Tail.ReturnsValue)
73 | {
74 | using (Compiler.Local newVal = new Compiler.Local(ctx, field.FieldType))
75 | {
76 | ctx.StoreValue(newVal);
77 | if (Helpers.IsValueType(field.FieldType))
78 | {
79 | ctx.LoadAddress(loc, ExpectedType);
80 | ctx.LoadValue(newVal);
81 | ctx.StoreValue(field);
82 | }
83 | else
84 | {
85 | Compiler.CodeLabel allDone = ctx.DefineLabel();
86 | ctx.LoadValue(newVal);
87 | ctx.BranchIfFalse(allDone, true); // interpret null as "don't assign"
88 |
89 | ctx.LoadAddress(loc, ExpectedType);
90 | ctx.LoadValue(newVal);
91 | ctx.StoreValue(field);
92 |
93 | ctx.MarkLabel(allDone);
94 | }
95 | }
96 | }
97 | }
98 | else
99 | {
100 | // can't use result
101 | if (Tail.ReturnsValue)
102 | {
103 | ctx.DiscardValue();
104 | }
105 | }
106 | }
107 | }
108 | #endif
109 | }
110 | }
111 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Meta/CallbackSet.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 | using System.Reflection;
9 | #endif
10 |
11 | namespace ProtoBuf.Meta
12 | {
13 | ///
14 | /// Represents the set of serialization callbacks to be used when serializing/deserializing a type.
15 | ///
16 | public class CallbackSet
17 | {
18 | private readonly MetaType metaType;
19 | internal CallbackSet(MetaType metaType)
20 | {
21 | if (metaType == null) throw new ArgumentNullException("metaType");
22 | this.metaType = metaType;
23 | }
24 | internal MethodInfo this[TypeModel.CallbackType callbackType]
25 | {
26 | get
27 | {
28 | switch (callbackType)
29 | {
30 | case TypeModel.CallbackType.BeforeSerialize: return beforeSerialize;
31 | case TypeModel.CallbackType.AfterSerialize: return afterSerialize;
32 | case TypeModel.CallbackType.BeforeDeserialize: return beforeDeserialize;
33 | case TypeModel.CallbackType.AfterDeserialize: return afterDeserialize;
34 | default: throw new ArgumentException("Callback type not supported: " + callbackType.ToString(), "callbackType");
35 | }
36 | }
37 | }
38 | internal static bool CheckCallbackParameters(TypeModel model, MethodInfo method)
39 | {
40 | ParameterInfo[] args = method.GetParameters();
41 | for (int i = 0; i < args.Length; i++)
42 | {
43 | Type paramType = args[i].ParameterType;
44 | if(paramType == model.MapType(typeof(SerializationContext))) {}
45 | else if(paramType == model.MapType(typeof(System.Type))) {}
46 | #if PLAT_BINARYFORMATTER
47 | else if(paramType == model.MapType(typeof(System.Runtime.Serialization.StreamingContext))) {}
48 | #endif
49 | else return false;
50 | }
51 | return true;
52 | }
53 | private MethodInfo SanityCheckCallback(TypeModel model, MethodInfo callback)
54 | {
55 | metaType.ThrowIfFrozen();
56 | if (callback == null) return callback; // fine
57 | if (callback.IsStatic) throw new ArgumentException("Callbacks cannot be static", "callback");
58 | if (callback.ReturnType != model.MapType(typeof(void))
59 | || !CheckCallbackParameters(model, callback))
60 | {
61 | throw CreateInvalidCallbackSignature(callback);
62 | }
63 | return callback;
64 | }
65 | internal static Exception CreateInvalidCallbackSignature(MethodInfo method)
66 | {
67 | return new NotSupportedException("Invalid callback signature in " + method.DeclaringType.FullName + "." + method.Name);
68 | }
69 | private MethodInfo beforeSerialize, afterSerialize, beforeDeserialize, afterDeserialize;
70 | /// Called before serializing an instance
71 | public MethodInfo BeforeSerialize
72 | {
73 | get { return beforeSerialize; }
74 | set { beforeSerialize = SanityCheckCallback(metaType.Model, value); }
75 | }
76 | /// Called before deserializing an instance
77 | public MethodInfo BeforeDeserialize
78 | {
79 | get { return beforeDeserialize; }
80 | set { beforeDeserialize = SanityCheckCallback(metaType.Model, value); }
81 | }
82 | /// Called after serializing an instance
83 | public MethodInfo AfterSerialize
84 | {
85 | get { return afterSerialize; }
86 | set { afterSerialize = SanityCheckCallback(metaType.Model, value); }
87 | }
88 | /// Called after deserializing an instance
89 | public MethodInfo AfterDeserialize
90 | {
91 | get { return afterDeserialize; }
92 | set { afterDeserialize = SanityCheckCallback(metaType.Model, value); }
93 | }
94 | ///
95 | /// True if any callback is set, else False
96 | ///
97 | public bool NonTrivial
98 | {
99 | get
100 | {
101 | return beforeSerialize != null || beforeDeserialize != null
102 | || afterSerialize != null || afterDeserialize != null;
103 | }
104 | }
105 | }
106 | }
107 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/ParseableSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | using ProtoBuf.Meta;
4 | #if FEAT_IKVM
5 | using Type = IKVM.Reflection.Type;
6 | using IKVM.Reflection;
7 | #else
8 | using System.Reflection;
9 | #endif
10 |
11 | namespace ProtoBuf.Serializers
12 | {
13 | sealed class ParseableSerializer : IProtoSerializer
14 | {
15 | private readonly MethodInfo parse;
16 | public static ParseableSerializer TryCreate(Type type, TypeModel model)
17 | {
18 | if (type == null) throw new ArgumentNullException("type");
19 | #if WINRT || PORTABLE || COREFX
20 | MethodInfo method = null;
21 |
22 | #if WINRT || COREFX
23 | foreach (MethodInfo tmp in type.GetTypeInfo().GetDeclaredMethods("Parse"))
24 | #else
25 | foreach (MethodInfo tmp in type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly))
26 | #endif
27 | {
28 | ParameterInfo[] p;
29 | if (tmp.Name == "Parse" && tmp.IsPublic && tmp.IsStatic && tmp.DeclaringType == type && (p = tmp.GetParameters()) != null && p.Length == 1 && p[0].ParameterType == typeof(string))
30 | {
31 | method = tmp;
32 | break;
33 | }
34 | }
35 | #else
36 | MethodInfo method = type.GetMethod("Parse",
37 | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly,
38 | null, new Type[] { model.MapType(typeof(string)) }, null);
39 | #endif
40 | if (method != null && method.ReturnType == type)
41 | {
42 | if (Helpers.IsValueType(type))
43 | {
44 | MethodInfo toString = GetCustomToString(type);
45 | if (toString == null || toString.ReturnType != model.MapType(typeof(string))) return null; // need custom ToString, fools
46 | }
47 | return new ParseableSerializer(method);
48 | }
49 | return null;
50 | }
51 | private static MethodInfo GetCustomToString(Type type)
52 | {
53 | #if WINRT
54 | foreach (MethodInfo method in type.GetTypeInfo().GetDeclaredMethods("ToString"))
55 | {
56 | if (method.IsPublic && !method.IsStatic && method.GetParameters().Length == 0) return method;
57 | }
58 | return null;
59 | #elif PORTABLE || COREFX
60 | MethodInfo method = Helpers.GetInstanceMethod(type, "ToString", Helpers.EmptyTypes);
61 | if (method == null || !method.IsPublic || method.IsStatic || method.DeclaringType != type) return null;
62 | return method;
63 | #else
64 |
65 | return type.GetMethod("ToString", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
66 | null, Helpers.EmptyTypes, null);
67 | #endif
68 | }
69 | private ParseableSerializer(MethodInfo parse)
70 | {
71 | this.parse = parse;
72 | }
73 | public Type ExpectedType { get { return parse.DeclaringType; } }
74 |
75 | bool IProtoSerializer.RequiresOldValue { get { return false; } }
76 | bool IProtoSerializer.ReturnsValue { get { return true; } }
77 |
78 | #if !FEAT_IKVM
79 | public object Read(object value, ProtoReader source)
80 | {
81 | Helpers.DebugAssert(value == null); // since replaces
82 | return parse.Invoke(null, new object[] { source.ReadString() });
83 | }
84 | public void Write(object value, ProtoWriter dest)
85 | {
86 | ProtoWriter.WriteString(value.ToString(), dest);
87 | }
88 | #endif
89 |
90 | #if FEAT_COMPILER
91 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
92 | {
93 | Type type = ExpectedType;
94 | if (Helpers.IsValueType(type))
95 | { // note that for structs, we've already asserted that a custom ToString
96 | // exists; no need to handle the box/callvirt scenario
97 |
98 | // force it to a variable if needed, so we can take the address
99 | using (Compiler.Local loc = ctx.GetLocalWithValue(type, valueFrom))
100 | {
101 | ctx.LoadAddress(loc, type);
102 | ctx.EmitCall(GetCustomToString(type));
103 | }
104 | }
105 | else {
106 | ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("ToString"));
107 | }
108 | ctx.EmitBasicWrite("WriteString", valueFrom);
109 | }
110 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
111 | {
112 | ctx.EmitBasicRead("ReadString", ctx.MapType(typeof(string)));
113 | ctx.EmitCall(parse);
114 | }
115 | #endif
116 |
117 | }
118 | }
119 | #endif
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/CustomOptions.cs:
--------------------------------------------------------------------------------
1 | // This file was generated by a tool; you should avoid making direct changes.
2 | // Consider using 'partial classes' to extend these types
3 | // Input: protogen.proto
4 |
5 | #pragma warning disable CS1591, CS0612, CS3021
6 |
7 | namespace ProtoBuf.Reflection
8 | {
9 |
10 | [global::ProtoBuf.ProtoContract()]
11 | public partial class ProtogenFileOptions
12 | {
13 | [global::ProtoBuf.ProtoMember(1, Name = @"namespace")]
14 | [global::System.ComponentModel.DefaultValue("")]
15 | public string Namespace { get; set; } = "";
16 |
17 | [global::ProtoBuf.ProtoMember(2, Name = @"access")]
18 | public Access Access { get; set; }
19 |
20 | [global::ProtoBuf.ProtoMember(3, Name = @"extensions")]
21 | [global::System.ComponentModel.DefaultValue("")]
22 | public string ExtensionTypeName { get; set; } = "";
23 |
24 | }
25 |
26 | [global::ProtoBuf.ProtoContract()]
27 | public partial class ProtogenMessageOptions
28 | {
29 | [global::ProtoBuf.ProtoMember(1, Name = @"name")]
30 | [global::System.ComponentModel.DefaultValue("")]
31 | public string Name { get; set; } = "";
32 |
33 | [global::ProtoBuf.ProtoMember(2, Name = @"access")]
34 | public Access Access { get; set; }
35 |
36 | [global::ProtoBuf.ProtoMember(3, Name = @"extensions")]
37 | [global::System.ComponentModel.DefaultValue("")]
38 | public string ExtensionTypeName { get; set; } = "";
39 |
40 | }
41 |
42 | [global::ProtoBuf.ProtoContract()]
43 | public partial class ProtogenFieldOptions
44 | {
45 | [global::ProtoBuf.ProtoMember(1, Name = @"name")]
46 | [global::System.ComponentModel.DefaultValue("")]
47 | public string Name { get; set; } = "";
48 |
49 | [global::ProtoBuf.ProtoMember(2, Name = @"access")]
50 | public Access Access { get; set; }
51 |
52 | [global::ProtoBuf.ProtoMember(3, Name = @"asRef")]
53 | public bool AsReference { get; set; }
54 |
55 | [global::ProtoBuf.ProtoMember(4, Name = @"dynamicType")]
56 | public bool DynamicType { get; set; }
57 |
58 | }
59 |
60 | [global::ProtoBuf.ProtoContract()]
61 | public partial class ProtogenEnumOptions
62 | {
63 | [global::ProtoBuf.ProtoMember(1, Name = @"name")]
64 | [global::System.ComponentModel.DefaultValue("")]
65 | public string Name { get; set; } = "";
66 |
67 | [global::ProtoBuf.ProtoMember(2, Name = @"access")]
68 | public Access Access { get; set; }
69 |
70 | }
71 |
72 | [global::ProtoBuf.ProtoContract()]
73 | public partial class ProtogenEnumValueOptions
74 | {
75 | [global::ProtoBuf.ProtoMember(1, Name = @"name")]
76 | [global::System.ComponentModel.DefaultValue("")]
77 | public string Name { get; set; } = "";
78 |
79 | }
80 |
81 | [global::ProtoBuf.ProtoContract()]
82 | public partial class ProtogenServiceOptions
83 | {
84 | [global::ProtoBuf.ProtoMember(1, Name = @"name")]
85 | [global::System.ComponentModel.DefaultValue("")]
86 | public string Name { get; set; } = "";
87 |
88 | [global::ProtoBuf.ProtoMember(2, Name = @"access")]
89 | public Access Access { get; set; }
90 |
91 | }
92 |
93 | [global::ProtoBuf.ProtoContract()]
94 | public partial class ProtogenMethodOptions
95 | {
96 | [global::ProtoBuf.ProtoMember(1, Name = @"name")]
97 | [global::System.ComponentModel.DefaultValue("")]
98 | public string Name { get; set; } = "";
99 |
100 | }
101 |
102 | [global::ProtoBuf.ProtoContract()]
103 | public enum Access
104 | {
105 | [global::ProtoBuf.ProtoEnum(Name = @"INHERIT")]
106 | Inherit = 0,
107 | [global::ProtoBuf.ProtoEnum(Name = @"PUBLIC")]
108 | Public = 1,
109 | [global::ProtoBuf.ProtoEnum(Name = @"PRIVATE")]
110 | Private = 2,
111 | [global::ProtoBuf.ProtoEnum(Name = @"INTERNAL")]
112 | Internal = 3,
113 | }
114 |
115 | public static class Extensions
116 | {
117 | public static ProtogenFileOptions GetOptions(this global::Google.Protobuf.Reflection.FileOptions obj)
118 | => obj == null ? default(ProtogenFileOptions) : global::ProtoBuf.Extensible.GetValue(obj, 1037);
119 |
120 | public static ProtogenMessageOptions GetOptions(this global::Google.Protobuf.Reflection.MessageOptions obj)
121 | => obj == null ? default(ProtogenMessageOptions) : global::ProtoBuf.Extensible.GetValue(obj, 1037);
122 |
123 | public static ProtogenFieldOptions GetOptions(this global::Google.Protobuf.Reflection.FieldOptions obj)
124 | => obj == null ? default(ProtogenFieldOptions) : global::ProtoBuf.Extensible.GetValue(obj, 1037);
125 |
126 | public static ProtogenEnumOptions GetOptions(this global::Google.Protobuf.Reflection.EnumOptions obj)
127 | => obj == null ? default(ProtogenEnumOptions) : global::ProtoBuf.Extensible.GetValue(obj, 1037);
128 |
129 | public static ProtogenEnumValueOptions GetOptions(this global::Google.Protobuf.Reflection.EnumValueOptions obj)
130 | => obj == null ? default(ProtogenEnumValueOptions) : global::ProtoBuf.Extensible.GetValue(obj, 1037);
131 |
132 | public static ProtogenServiceOptions GetOptions(this global::Google.Protobuf.Reflection.ServiceOptions obj)
133 | => obj == null ? default(ProtogenServiceOptions) : global::ProtoBuf.Extensible.GetValue(obj, 1037);
134 |
135 | public static ProtogenMethodOptions GetOptions(this global::Google.Protobuf.Reflection.MethodOptions obj)
136 | => obj == null ? default(ProtogenMethodOptions) : global::ProtoBuf.Extensible.GetValue(obj, 1037);
137 |
138 | }
139 | }
140 |
141 | #pragma warning restore CS1591, CS0612, CS3021
142 |
--------------------------------------------------------------------------------
/protobuf-net/ExtensibleUtil.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | #if !NO_GENERICS
4 | using System.Collections.Generic;
5 | #endif
6 | using System.IO;
7 | using ProtoBuf.Meta;
8 |
9 | namespace ProtoBuf
10 | {
11 | ///
12 | /// This class acts as an internal wrapper allowing us to do a dynamic
13 | /// methodinfo invoke; an't put into Serializer as don't want on public
14 | /// API; can't put into Serializer<T> since we need to invoke
15 | /// accross classes, which isn't allowed in Silverlight)
16 | ///
17 | internal
18 | #if FX11
19 | sealed
20 | #else
21 | static
22 | #endif
23 | class ExtensibleUtil
24 | {
25 | #if FX11
26 | private ExtensibleUtil() { } // not a static class for C# 1.2 reasons
27 | #endif
28 |
29 | #if !NO_RUNTIME && !NO_GENERICS
30 | ///
31 | /// All this does is call GetExtendedValuesTyped with the correct type for "instance";
32 | /// this ensures that we don't get issues with subclasses declaring conflicting types -
33 | /// the caller must respect the fields defined for the type they pass in.
34 | ///
35 | internal static IEnumerable GetExtendedValues(IExtensible instance, int tag, DataFormat format, bool singleton, bool allowDefinedTag)
36 | {
37 | foreach (TValue value in GetExtendedValues(RuntimeTypeModel.Default, typeof(TValue), instance, tag, format, singleton, allowDefinedTag))
38 | {
39 | yield return value;
40 | }
41 | }
42 | #endif
43 | ///
44 | /// All this does is call GetExtendedValuesTyped with the correct type for "instance";
45 | /// this ensures that we don't get issues with subclasses declaring conflicting types -
46 | /// the caller must respect the fields defined for the type they pass in.
47 | ///
48 | internal static IEnumerable GetExtendedValues(TypeModel model, Type type, IExtensible instance, int tag, DataFormat format, bool singleton, bool allowDefinedTag)
49 | {
50 | #if FEAT_IKVM
51 | throw new NotSupportedException();
52 | #else
53 |
54 | if (instance == null) throw new ArgumentNullException("instance");
55 | if (tag <= 0) throw new ArgumentOutOfRangeException("tag");
56 | IExtension extn = instance.GetExtensionObject(false);
57 |
58 | if (extn == null)
59 | {
60 | #if FX11
61 | return new object[0];
62 | #else
63 | yield break;
64 | #endif
65 | }
66 |
67 | #if FX11
68 | BasicList result = new BasicList();
69 | #endif
70 | Stream stream = extn.BeginQuery();
71 | object value = null;
72 | ProtoReader reader = null;
73 | try {
74 | SerializationContext ctx = new SerializationContext();
75 | reader = ProtoReader.Create(stream, model, ctx, ProtoReader.TO_EOF);
76 | while (model.TryDeserializeAuxiliaryType(reader, format, tag, type, ref value, true, false, false, false, null) && value != null)
77 | {
78 | if (!singleton)
79 | {
80 | #if FX11
81 | result.Add(value);
82 | #else
83 | yield return value;
84 | #endif
85 | value = null; // fresh item each time
86 | }
87 | }
88 | if (singleton && value != null)
89 | {
90 | #if FX11
91 | result.Add(value);
92 | #else
93 | yield return value;
94 | #endif
95 | }
96 | #if FX11
97 | object[] resultArr = new object[result.Count];
98 | result.CopyTo(resultArr, 0);
99 | return resultArr;
100 | #endif
101 | } finally {
102 | ProtoReader.Recycle(reader);
103 | extn.EndQuery(stream);
104 | }
105 | #endif
106 | }
107 |
108 | internal static void AppendExtendValue(TypeModel model, IExtensible instance, int tag, DataFormat format, object value)
109 | {
110 | #if FEAT_IKVM
111 | throw new NotSupportedException();
112 | #else
113 | if(instance == null) throw new ArgumentNullException("instance");
114 | if(value == null) throw new ArgumentNullException("value");
115 |
116 | // TODO
117 | //model.CheckTagNotInUse(tag);
118 |
119 | // obtain the extension object and prepare to write
120 | IExtension extn = instance.GetExtensionObject(true);
121 | if (extn == null) throw new InvalidOperationException("No extension object available; appended data would be lost.");
122 | bool commit = false;
123 | Stream stream = extn.BeginAppend();
124 | try {
125 | using(ProtoWriter writer = new ProtoWriter(stream, model, null)) {
126 | model.TrySerializeAuxiliaryType(writer, null, format, tag, value, false, null);
127 | writer.Close();
128 | }
129 | commit = true;
130 | }
131 | finally {
132 | extn.EndAppend(stream, commit);
133 | }
134 | #endif
135 | }
136 | //#if !NO_GENERICS
137 | // ///
138 | // /// Stores the given value into the instance's stream; the serializer
139 | // /// is inferred from TValue and format.
140 | // ///
141 | // /// Needs to be public to be callable thru reflection in Silverlight
142 | // public static void AppendExtendValueTyped(
143 | // TypeModel model, TSource instance, int tag, DataFormat format, TValue value)
144 | // where TSource : class, IExtensible
145 | // {
146 | // AppendExtendValue(model, instance, tag, format, value);
147 | // }
148 | //#endif
149 | }
150 |
151 | }
--------------------------------------------------------------------------------
/protobuf-net/Serializers/SubItemSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | using ProtoBuf.Meta;
4 |
5 | #if FEAT_COMPILER
6 | #if FEAT_IKVM
7 | using IKVM.Reflection.Emit;
8 | using Type = IKVM.Reflection.Type;
9 | #else
10 | using System.Reflection.Emit;
11 | #endif
12 | #endif
13 |
14 | namespace ProtoBuf.Serializers
15 | {
16 | sealed class SubItemSerializer : IProtoTypeSerializer
17 | {
18 | bool IProtoTypeSerializer.HasCallbacks(TypeModel.CallbackType callbackType)
19 | {
20 | return ((IProtoTypeSerializer)proxy.Serializer).HasCallbacks(callbackType);
21 | }
22 | bool IProtoTypeSerializer.CanCreateInstance()
23 | {
24 | return ((IProtoTypeSerializer)proxy.Serializer).CanCreateInstance();
25 | }
26 | #if FEAT_COMPILER
27 | void IProtoTypeSerializer.EmitCallback(Compiler.CompilerContext ctx, Compiler.Local valueFrom, TypeModel.CallbackType callbackType)
28 | {
29 | ((IProtoTypeSerializer)proxy.Serializer).EmitCallback(ctx, valueFrom, callbackType);
30 | }
31 | void IProtoTypeSerializer.EmitCreateInstance(Compiler.CompilerContext ctx)
32 | {
33 | ((IProtoTypeSerializer)proxy.Serializer).EmitCreateInstance(ctx);
34 | }
35 | #endif
36 | #if !FEAT_IKVM
37 | void IProtoTypeSerializer.Callback(object value, TypeModel.CallbackType callbackType, SerializationContext context)
38 | {
39 | ((IProtoTypeSerializer)proxy.Serializer).Callback(value, callbackType, context);
40 | }
41 | object IProtoTypeSerializer.CreateInstance(ProtoReader source)
42 | {
43 | return ((IProtoTypeSerializer)proxy.Serializer).CreateInstance(source);
44 | }
45 | #endif
46 |
47 | private readonly int key;
48 | private readonly Type type;
49 | private readonly ISerializerProxy proxy;
50 | private readonly bool recursionCheck;
51 | public SubItemSerializer(Type type, int key, ISerializerProxy proxy, bool recursionCheck)
52 | {
53 | if (type == null) throw new ArgumentNullException("type");
54 | if (proxy == null) throw new ArgumentNullException("proxy");
55 | this.type = type;
56 | this.proxy= proxy;
57 | this.key = key;
58 | this.recursionCheck = recursionCheck;
59 | }
60 | Type IProtoSerializer.ExpectedType
61 | {
62 | get { return type; }
63 | }
64 | bool IProtoSerializer.RequiresOldValue { get { return true; } }
65 | bool IProtoSerializer.ReturnsValue { get { return true; } }
66 |
67 | #if !FEAT_IKVM
68 | void IProtoSerializer.Write(object value, ProtoWriter dest)
69 | {
70 | if (recursionCheck)
71 | {
72 | ProtoWriter.WriteObject(value, key, dest);
73 | }
74 | else
75 | {
76 | ProtoWriter.WriteRecursionSafeObject(value, key, dest);
77 | }
78 | }
79 | object IProtoSerializer.Read(object value, ProtoReader source)
80 | {
81 | return ProtoReader.ReadObject(value, key, source);
82 | }
83 | #endif
84 |
85 | #if FEAT_COMPILER
86 | bool EmitDedicatedMethod(Compiler.CompilerContext ctx, Compiler.Local valueFrom, bool read)
87 | {
88 | #if SILVERLIGHT
89 | return false;
90 | #else
91 | MethodBuilder method = ctx.GetDedicatedMethod(key, read);
92 | if (method == null) return false;
93 |
94 | using (Compiler.Local token = new ProtoBuf.Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
95 | {
96 | Type rwType = ctx.MapType(read ? typeof(ProtoReader) : typeof(ProtoWriter));
97 | ctx.LoadValue(valueFrom);
98 | if (!read) // write requires the object for StartSubItem; read doesn't
99 | { // (if recursion-check is disabled [subtypes] then null is fine too)
100 | if (Helpers.IsValueType(type) || !recursionCheck) { ctx.LoadNullRef(); }
101 | else { ctx.CopyValue(); }
102 | }
103 | ctx.LoadReaderWriter();
104 | ctx.EmitCall(Helpers.GetStaticMethod(rwType, "StartSubItem",
105 | read ? new Type[] { rwType } : new Type[] { ctx.MapType(typeof(object)), rwType }));
106 | ctx.StoreValue(token);
107 |
108 | // note: value already on the stack
109 | ctx.LoadReaderWriter();
110 | ctx.EmitCall(method);
111 | // handle inheritance (we will be calling the *base* version of things,
112 | // but we expect Read to return the "type" type)
113 | if (read && type != method.ReturnType) ctx.Cast(this.type);
114 | ctx.LoadValue(token);
115 | ctx.LoadReaderWriter();
116 | ctx.EmitCall(Helpers.GetStaticMethod(rwType, "EndSubItem", new Type[] { ctx.MapType(typeof(SubItemToken)), rwType }));
117 | }
118 | return true;
119 | #endif
120 | }
121 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
122 | {
123 | if (!EmitDedicatedMethod(ctx, valueFrom, false))
124 | {
125 | ctx.LoadValue(valueFrom);
126 | if (Helpers.IsValueType(type)) ctx.CastToObject(type);
127 | ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key)); // re-map for formality, but would expect identical, else dedicated method
128 | ctx.LoadReaderWriter();
129 | ctx.EmitCall(Helpers.GetStaticMethod(ctx.MapType(typeof(ProtoWriter)), recursionCheck ? "WriteObject" : "WriteRecursionSafeObject", new Type[] { ctx.MapType(typeof(object)), ctx.MapType(typeof(int)), ctx.MapType(typeof(ProtoWriter)) }));
130 | }
131 | }
132 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
133 | {
134 | if (!EmitDedicatedMethod(ctx, valueFrom, true))
135 | {
136 | ctx.LoadValue(valueFrom);
137 | if (Helpers.IsValueType(type)) ctx.CastToObject(type);
138 | ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key)); // re-map for formality, but would expect identical, else dedicated method
139 | ctx.LoadReaderWriter();
140 | ctx.EmitCall(Helpers.GetStaticMethod(ctx.MapType(typeof(ProtoReader)), "ReadObject"));
141 | ctx.CastFromObject(type);
142 | }
143 | }
144 | #endif
145 | }
146 | }
147 | #endif
--------------------------------------------------------------------------------
/Editor/protobuf-net.Reflection/CodeGenerator.OneOfStub.cs:
--------------------------------------------------------------------------------
1 | using Google.Protobuf.Reflection;
2 |
3 | namespace ProtoBuf.Reflection
4 | {
5 | partial class CommonCodeGenerator
6 | {
7 | ///
8 | /// Represents the union summary of a one-of declaration
9 | ///
10 | protected class OneOfStub
11 | {
12 | ///
13 | /// The underlying descriptor
14 | ///
15 | public OneofDescriptorProto OneOf { get; }
16 |
17 | internal OneOfStub(OneofDescriptorProto decl)
18 | {
19 | OneOf = decl;
20 | }
21 | internal int Count32 { get; private set; }
22 | internal int Count64 { get; private set; }
23 | internal int Count128 { get; private set; }
24 | internal int CountRef { get; private set; }
25 | internal int CountTotal => CountRef + Count32 + Count64;
26 |
27 | private void AccountFor(FieldDescriptorProto.Type type, string typeName)
28 | {
29 | switch (type)
30 | {
31 | case FieldDescriptorProto.Type.TypeBool:
32 | case FieldDescriptorProto.Type.TypeEnum:
33 | case FieldDescriptorProto.Type.TypeFixed32:
34 | case FieldDescriptorProto.Type.TypeFloat:
35 | case FieldDescriptorProto.Type.TypeInt32:
36 | case FieldDescriptorProto.Type.TypeSfixed32:
37 | case FieldDescriptorProto.Type.TypeSint32:
38 | case FieldDescriptorProto.Type.TypeUint32:
39 | Count32++;
40 | break;
41 | case FieldDescriptorProto.Type.TypeDouble:
42 | case FieldDescriptorProto.Type.TypeFixed64:
43 | case FieldDescriptorProto.Type.TypeInt64:
44 | case FieldDescriptorProto.Type.TypeSfixed64:
45 | case FieldDescriptorProto.Type.TypeSint64:
46 | case FieldDescriptorProto.Type.TypeUint64:
47 | Count32++;
48 | Count64++;
49 | break;
50 | case FieldDescriptorProto.Type.TypeMessage:
51 | switch(typeName)
52 | {
53 | case ".google.protobuf.Timestamp":
54 | case ".google.protobuf.Duration":
55 | Count64++;
56 | break;
57 | case ".bcl.Guid":
58 | Count128++;
59 | break;
60 | default:
61 | CountRef++;
62 | break;
63 | }
64 | break;
65 | default:
66 | CountRef++;
67 | break;
68 | }
69 | }
70 | internal string GetStorage(FieldDescriptorProto.Type type, string typeName)
71 | {
72 | switch (type)
73 | {
74 | case FieldDescriptorProto.Type.TypeBool:
75 | return "Boolean";
76 | case FieldDescriptorProto.Type.TypeInt32:
77 | case FieldDescriptorProto.Type.TypeSfixed32:
78 | case FieldDescriptorProto.Type.TypeSint32:
79 | case FieldDescriptorProto.Type.TypeFixed32:
80 | case FieldDescriptorProto.Type.TypeEnum:
81 | return "Int32";
82 | case FieldDescriptorProto.Type.TypeFloat:
83 | return "Single";
84 | case FieldDescriptorProto.Type.TypeUint32:
85 | return "UInt32";
86 | case FieldDescriptorProto.Type.TypeDouble:
87 | return "Double";
88 | case FieldDescriptorProto.Type.TypeFixed64:
89 | case FieldDescriptorProto.Type.TypeInt64:
90 | case FieldDescriptorProto.Type.TypeSfixed64:
91 | case FieldDescriptorProto.Type.TypeSint64:
92 | return "Int64";
93 | case FieldDescriptorProto.Type.TypeUint64:
94 | return "UInt64";
95 | case FieldDescriptorProto.Type.TypeMessage:
96 | switch (typeName)
97 | {
98 | case ".google.protobuf.Timestamp":
99 | return "DateTime";
100 | case ".google.protobuf.Duration":
101 | return "TimeSpan";
102 | case ".bcl.Guid":
103 | return "Guid";
104 | default:
105 | return "Object";
106 | }
107 | default:
108 | return "Object";
109 | }
110 | }
111 | internal static OneOfStub[] Build(GeneratorContext context, DescriptorProto message)
112 | {
113 | if (message.OneofDecls.Count == 0) return null;
114 | var stubs = new OneOfStub[message.OneofDecls.Count];
115 | int index = 0;
116 | foreach (var decl in message.OneofDecls)
117 | {
118 | stubs[index++] = new OneOfStub(decl);
119 | }
120 | foreach (var field in message.Fields)
121 | {
122 | if (field.ShouldSerializeOneofIndex())
123 | {
124 | stubs[field.OneofIndex].AccountFor(field.type, field.TypeName);
125 | }
126 | }
127 | return stubs;
128 | }
129 | private bool isFirst = true;
130 | internal bool IsFirst()
131 | {
132 | if (isFirst)
133 | {
134 | isFirst = false;
135 | return true;
136 | }
137 | return false;
138 | }
139 |
140 | internal string GetUnionType()
141 | {
142 | if (Count128 != 0)
143 | {
144 | return CountRef == 0 ? "DiscriminatedUnion128" : "DiscriminatedUnion128Object";
145 | }
146 | if (Count64 != 0)
147 | {
148 | return CountRef == 0 ? "DiscriminatedUnion64" : "DiscriminatedUnion64Object";
149 | }
150 | if (Count32 != 0)
151 | {
152 | return CountRef == 0 ? "DiscriminatedUnion32" : "DiscriminatedUnion32Object";
153 | }
154 | return "DiscriminatedUnionObject";
155 | }
156 | }
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/protobuf-net/Serializers/NullDecorator.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 |
4 | using ProtoBuf.Meta;
5 |
6 | #if FEAT_IKVM
7 | using Type = IKVM.Reflection.Type;
8 | using IKVM.Reflection;
9 | #else
10 |
11 | #endif
12 |
13 | namespace ProtoBuf.Serializers
14 | {
15 | sealed class NullDecorator : ProtoDecoratorBase
16 | {
17 | private readonly Type expectedType;
18 | public const int Tag = 1;
19 | public NullDecorator(TypeModel model, IProtoSerializer tail) : base(tail)
20 | {
21 | if (!tail.ReturnsValue)
22 | throw new NotSupportedException("NullDecorator only supports implementations that return values");
23 |
24 | Type tailType = tail.ExpectedType;
25 | if (Helpers.IsValueType(tailType))
26 | {
27 | #if NO_GENERICS
28 | throw new NotSupportedException("NullDecorator cannot be used with a struct without generics support");
29 | #else
30 | expectedType = model.MapType(typeof(Nullable<>)).MakeGenericType(tailType);
31 | #endif
32 | }
33 | else
34 | {
35 | expectedType = tailType;
36 | }
37 |
38 | }
39 |
40 | public override Type ExpectedType
41 | {
42 | get { return expectedType; }
43 | }
44 | public override bool ReturnsValue
45 | {
46 | get { return true; }
47 | }
48 | public override bool RequiresOldValue
49 | {
50 | get { return true; }
51 | }
52 | #if FEAT_COMPILER
53 | protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
54 | {
55 | using (Compiler.Local oldValue = ctx.GetLocalWithValue(expectedType, valueFrom))
56 | using (Compiler.Local token = new Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
57 | using (Compiler.Local field = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
58 | {
59 | ctx.LoadReaderWriter();
60 | ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("StartSubItem"));
61 | ctx.StoreValue(token);
62 |
63 | Compiler.CodeLabel next = ctx.DefineLabel(), processField = ctx.DefineLabel(), end = ctx.DefineLabel();
64 |
65 | ctx.MarkLabel(next);
66 |
67 | ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
68 | ctx.CopyValue();
69 | ctx.StoreValue(field);
70 | ctx.LoadValue(Tag); // = 1 - process
71 | ctx.BranchIfEqual(processField, true);
72 | ctx.LoadValue(field);
73 | ctx.LoadValue(1); // < 1 - exit
74 | ctx.BranchIfLess(end, false);
75 |
76 | // default: skip
77 | ctx.LoadReaderWriter();
78 | ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
79 | ctx.Branch(next, true);
80 |
81 | // process
82 | ctx.MarkLabel(processField);
83 | if (Tail.RequiresOldValue)
84 | {
85 | if (Helpers.IsValueType(expectedType))
86 | {
87 | ctx.LoadAddress(oldValue, expectedType);
88 | ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
89 | }
90 | else
91 | {
92 | ctx.LoadValue(oldValue);
93 | }
94 | }
95 | Tail.EmitRead(ctx, null);
96 | // note we demanded always returns a value
97 | if (Helpers.IsValueType(expectedType))
98 | {
99 | ctx.EmitCtor(expectedType, Tail.ExpectedType); // re-nullable it
100 | }
101 | ctx.StoreValue(oldValue);
102 | ctx.Branch(next, false);
103 |
104 | // outro
105 | ctx.MarkLabel(end);
106 |
107 | ctx.LoadValue(token);
108 | ctx.LoadReaderWriter();
109 | ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("EndSubItem"));
110 | ctx.LoadValue(oldValue); // load the old value
111 | }
112 | }
113 | protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
114 | {
115 | using(Compiler.Local valOrNull = ctx.GetLocalWithValue(expectedType, valueFrom))
116 | using(Compiler.Local token = new Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
117 | {
118 | ctx.LoadNullRef();
119 | ctx.LoadReaderWriter();
120 | ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("StartSubItem"));
121 | ctx.StoreValue(token);
122 |
123 | if (Helpers.IsValueType(expectedType))
124 | {
125 | ctx.LoadAddress(valOrNull, expectedType);
126 | ctx.LoadValue(expectedType.GetProperty("HasValue"));
127 | }
128 | else
129 | {
130 | ctx.LoadValue(valOrNull);
131 | }
132 | Compiler.CodeLabel @end = ctx.DefineLabel();
133 | ctx.BranchIfFalse(@end, false);
134 | if (Helpers.IsValueType(expectedType))
135 | {
136 | ctx.LoadAddress(valOrNull, expectedType);
137 | ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
138 | }
139 | else
140 | {
141 | ctx.LoadValue(valOrNull);
142 | }
143 | Tail.EmitWrite(ctx, null);
144 |
145 | ctx.MarkLabel(@end);
146 |
147 | ctx.LoadValue(token);
148 | ctx.LoadReaderWriter();
149 | ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("EndSubItem"));
150 | }
151 | }
152 | #endif
153 |
154 | #if !FEAT_IKVM
155 | public override object Read(object value, ProtoReader source)
156 | {
157 | SubItemToken tok = ProtoReader.StartSubItem(source);
158 | int field;
159 | while((field = source.ReadFieldHeader()) > 0)
160 | {
161 | if(field == Tag) {
162 | value = Tail.Read(value, source);
163 | } else {
164 | source.SkipField();
165 | }
166 | }
167 | ProtoReader.EndSubItem(tok, source);
168 | return value;
169 | }
170 | public override void Write(object value, ProtoWriter dest)
171 | {
172 | SubItemToken token = ProtoWriter.StartSubItem(null, dest);
173 | if(value != null)
174 | {
175 | Tail.Write(value, dest);
176 | }
177 | ProtoWriter.EndSubItem(token, dest);
178 | }
179 | #endif
180 | }
181 | }
182 | #endif
--------------------------------------------------------------------------------
/protobuf-net/Serializers/SurrogateSerializer.cs:
--------------------------------------------------------------------------------
1 | #if !NO_RUNTIME
2 | using System;
3 | using ProtoBuf.Meta;
4 |
5 | #if FEAT_IKVM
6 | using Type = IKVM.Reflection.Type;
7 | using IKVM.Reflection;
8 | #else
9 | using System.Reflection;
10 | #endif
11 |
12 | namespace ProtoBuf.Serializers
13 | {
14 | sealed class SurrogateSerializer : IProtoTypeSerializer
15 | {
16 | bool IProtoTypeSerializer.HasCallbacks(ProtoBuf.Meta.TypeModel.CallbackType callbackType) { return false; }
17 | #if FEAT_COMPILER
18 | void IProtoTypeSerializer.EmitCallback(Compiler.CompilerContext ctx, Compiler.Local valueFrom, ProtoBuf.Meta.TypeModel.CallbackType callbackType) { }
19 | void IProtoTypeSerializer.EmitCreateInstance(Compiler.CompilerContext ctx) { throw new NotSupportedException(); }
20 | #endif
21 | bool IProtoTypeSerializer.CanCreateInstance() { return false; }
22 | #if !FEAT_IKVM
23 | object IProtoTypeSerializer.CreateInstance(ProtoReader source) { throw new NotSupportedException(); }
24 | void IProtoTypeSerializer.Callback(object value, ProtoBuf.Meta.TypeModel.CallbackType callbackType, SerializationContext context) { }
25 | #endif
26 |
27 | public bool ReturnsValue { get { return false; } }
28 | public bool RequiresOldValue { get { return true; } }
29 | public Type ExpectedType { get { return forType; } }
30 | private readonly Type forType, declaredType;
31 | private readonly MethodInfo toTail, fromTail;
32 | IProtoTypeSerializer rootTail;
33 |
34 | public SurrogateSerializer(TypeModel model, Type forType, Type declaredType, IProtoTypeSerializer rootTail)
35 | {
36 | Helpers.DebugAssert(forType != null, "forType");
37 | Helpers.DebugAssert(declaredType != null, "declaredType");
38 | Helpers.DebugAssert(rootTail != null, "rootTail");
39 | Helpers.DebugAssert(rootTail.RequiresOldValue, "RequiresOldValue");
40 | Helpers.DebugAssert(!rootTail.ReturnsValue, "ReturnsValue");
41 | Helpers.DebugAssert(declaredType == rootTail.ExpectedType || Helpers.IsSubclassOf(declaredType, rootTail.ExpectedType));
42 | this.forType = forType;
43 | this.declaredType = declaredType;
44 | this.rootTail = rootTail;
45 | toTail = GetConversion(model, true);
46 | fromTail = GetConversion(model, false);
47 | }
48 | private static bool HasCast(TypeModel model, Type type, Type from, Type to, out MethodInfo op)
49 | {
50 | #if WINRT
51 | System.Collections.Generic.List list = new System.Collections.Generic.List();
52 | foreach (var item in type.GetRuntimeMethods())
53 | {
54 | if (item.IsStatic) list.Add(item);
55 | }
56 | MethodInfo[] found = list.ToArray();
57 | #else
58 | const BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
59 | MethodInfo[] found = type.GetMethods(flags);
60 | #endif
61 | ParameterInfo[] paramTypes;
62 | Type convertAttributeType = null;
63 | for (int i = 0; i < found.Length; i++)
64 | {
65 | MethodInfo m = found[i];
66 | if (m.ReturnType != to) continue;
67 | paramTypes = m.GetParameters();
68 | if(paramTypes.Length == 1 && paramTypes[0].ParameterType == from)
69 | {
70 | if (convertAttributeType == null)
71 | {
72 | convertAttributeType = model.MapType(typeof(ProtoConverterAttribute), false);
73 | if (convertAttributeType == null)
74 | { // attribute isn't defined in the source assembly: stop looking
75 | break;
76 | }
77 | }
78 | if (m.IsDefined(convertAttributeType, true))
79 | {
80 | op = m;
81 | return true;
82 | }
83 | }
84 | }
85 |
86 | for(int i = 0 ; i < found.Length ; i++)
87 | {
88 | MethodInfo m = found[i];
89 | if ((m.Name != "op_Implicit" && m.Name != "op_Explicit") || m.ReturnType != to)
90 | {
91 | continue;
92 | }
93 | paramTypes = m.GetParameters();
94 | if(paramTypes.Length == 1 && paramTypes[0].ParameterType == from)
95 | {
96 | op = m;
97 | return true;
98 | }
99 | }
100 | op = null;
101 | return false;
102 | }
103 |
104 | public MethodInfo GetConversion(TypeModel model, bool toTail)
105 | {
106 | Type to = toTail ? declaredType : forType;
107 | Type from = toTail ? forType : declaredType;
108 | MethodInfo op;
109 | if (HasCast(model, declaredType, from, to, out op) || HasCast(model, forType, from, to, out op))
110 | {
111 | return op;
112 | }
113 | throw new InvalidOperationException("No suitable conversion operator found for surrogate: " +
114 | forType.FullName + " / " + declaredType.FullName);
115 | }
116 |
117 | #if !FEAT_IKVM
118 | public void Write(object value, ProtoWriter writer)
119 | {
120 | rootTail.Write(toTail.Invoke(null, new object[] { value }), writer);
121 | }
122 | public object Read(object value, ProtoReader source)
123 | {
124 | // convert the incoming value
125 | object[] args = { value };
126 | value = toTail.Invoke(null, args);
127 |
128 | // invoke the tail and convert the outgoing value
129 | args[0] = rootTail.Read(value, source);
130 | return fromTail.Invoke(null, args);
131 | }
132 | #endif
133 |
134 | #if FEAT_COMPILER
135 | void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
136 | {
137 | Helpers.DebugAssert(valueFrom != null); // don't support stack-head for this
138 | using (Compiler.Local converted = new Compiler.Local(ctx, declaredType)) // declare/re-use local
139 | {
140 | ctx.LoadValue(valueFrom); // load primary onto stack
141 | ctx.EmitCall(toTail); // static convert op, primary-to-surrogate
142 | ctx.StoreValue(converted); // store into surrogate local
143 |
144 | rootTail.EmitRead(ctx, converted); // downstream processing against surrogate local
145 |
146 | ctx.LoadValue(converted); // load from surrogate local
147 | ctx.EmitCall(fromTail); // static convert op, surrogate-to-primary
148 | ctx.StoreValue(valueFrom); // store back into primary
149 | }
150 | }
151 |
152 | void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
153 | {
154 | ctx.LoadValue(valueFrom);
155 | ctx.EmitCall(toTail);
156 | rootTail.EmitWrite(ctx, null);
157 | }
158 | #endif
159 | }
160 | }
161 | #endif
--------------------------------------------------------------------------------