aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers/GeneratedExtensionLite.cs
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2010-11-07 16:30:39 -0600
committercsharptest <roger@csharptest.net>2010-11-07 16:30:39 -0600
commit980ba8dcd470ddb964a84da1317028dd81c1d60a (patch)
tree0a442251e67543740202bb6c8d5f373bb960b2c0 /src/ProtocolBuffers/GeneratedExtensionLite.cs
parent804b6d842e9202cd79039cd8e7aa899426d37f78 (diff)
downloadprotobuf-980ba8dcd470ddb964a84da1317028dd81c1d60a.tar.gz
protobuf-980ba8dcd470ddb964a84da1317028dd81c1d60a.tar.bz2
protobuf-980ba8dcd470ddb964a84da1317028dd81c1d60a.zip
Full rutime working, Lite generator and runtime building but untested
Diffstat (limited to 'src/ProtocolBuffers/GeneratedExtensionLite.cs')
-rw-r--r--src/ProtocolBuffers/GeneratedExtensionLite.cs137
1 files changed, 125 insertions, 12 deletions
diff --git a/src/ProtocolBuffers/GeneratedExtensionLite.cs b/src/ProtocolBuffers/GeneratedExtensionLite.cs
index da07fb8c..e27dff72 100644
--- a/src/ProtocolBuffers/GeneratedExtensionLite.cs
+++ b/src/ProtocolBuffers/GeneratedExtensionLite.cs
@@ -1,4 +1,40 @@
-using System;
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://github.com/jskeet/dotnet-protobufs/
+// Original C++/Java/Python code:
+// http://code.google.com/p/protobuf/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using Google.ProtocolBuffers.Collections;
using Google.ProtocolBuffers.Descriptors;
namespace Google.ProtocolBuffers {
@@ -9,28 +45,87 @@ namespace Google.ProtocolBuffers {
IMessageLite MessageDefaultInstance { get; }
}
- public class ExtensionDescriptorLite {
- private readonly EnumLiteMap enumTypeMap;
+ public class ExtensionDescriptorLite : IFieldDescriptorLite {
+ /// <summary>
+ /// Immutable mapping from field type to mapped type. Built using the attributes on
+ /// FieldType values.
+ /// </summary>
+ public static readonly IDictionary<FieldType, MappedType> FieldTypeToMappedTypeMap = MapFieldTypes();
+
+ private static IDictionary<FieldType, MappedType> MapFieldTypes() {
+ var map = new Dictionary<FieldType, MappedType>();
+ foreach (System.Reflection.FieldInfo field in typeof(FieldType).GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public)) {
+ FieldType fieldType = (FieldType)field.GetValue(null);
+ FieldMappingAttribute mapping = (FieldMappingAttribute)field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0];
+ map[fieldType] = mapping.MappedType;
+ }
+ return Dictionaries.AsReadOnly(map);
+ }
+
+ private readonly IEnumLiteMap enumTypeMap;
private readonly int number;
private readonly FieldType type;
private readonly bool isRepeated;
private readonly bool isPacked;
+ private readonly MappedType mapType;
+ private readonly object defaultValue;
- public ExtensionDescriptorLite(EnumLiteMap enumTypeMap, int number, FieldType type, bool isRepeated, bool isPacked) {
+ public ExtensionDescriptorLite(IEnumLiteMap enumTypeMap, int number, FieldType type, object defaultValue, bool isRepeated, bool isPacked) {
this.enumTypeMap = enumTypeMap;
this.number = number;
this.type = type;
+ this.mapType = FieldTypeToMappedTypeMap[type];
this.isRepeated = isRepeated;
this.isPacked = isPacked;
+ this.defaultValue = defaultValue;
}
- public int Number {
+ public bool IsRepeated {
+ get { return isRepeated; }
+ }
+
+ public bool IsRequired {
+ get { return false; }
+ }
+
+ public bool IsPacked {
+ get { return isPacked; }
+ }
+
+ public bool IsExtension {
+ get { return true; }
+ }
+
+#warning ToDo - Discover the meaning and purpose of this durring serialization and return the correct value
+ public bool MessageSetWireFormat {
+ get { return true; }
+ }
+
+ public int FieldNumber {
get { return number; }
}
+
+ public IEnumLiteMap EnumType {
+ get { return enumTypeMap; }
+ }
+
+ public FieldType FieldType {
+ get { return type; }
+ }
+
+ public MappedType MappedType {
+ get { return mapType; }
+ }
+
+ public object DefaultValue {
+ get { return defaultValue; }
+ }
+
+ public int CompareTo(IFieldDescriptorLite other) {
+ return FieldNumber.CompareTo(other.FieldNumber);
+ }
}
- public class EnumLiteMap { }
-
public class GeneratedExtensionLite<TContainingType, TExtensionType> : IGeneratedExtensionLite
where TContainingType : IMessageLite {
@@ -62,11 +157,11 @@ namespace Google.ProtocolBuffers {
TContainingType containingTypeDefaultInstance,
TExtensionType defaultValue,
IMessageLite messageDefaultInstance,
- EnumLiteMap enumTypeMap,
+ IEnumLiteMap enumTypeMap,
int number,
FieldType type)
: this(containingTypeDefaultInstance, defaultValue, messageDefaultInstance,
- new ExtensionDescriptorLite(enumTypeMap, number, type,
+ new ExtensionDescriptorLite(enumTypeMap, number, type, defaultValue,
false /* isRepeated */, false /* isPacked */)) {
}
@@ -75,16 +170,30 @@ namespace Google.ProtocolBuffers {
TContainingType containingTypeDefaultInstance,
TExtensionType defaultValue,
IMessageLite messageDefaultInstance,
- EnumLiteMap enumTypeMap,
+ IEnumLiteMap enumTypeMap,
int number,
FieldType type,
bool isPacked)
: this(containingTypeDefaultInstance, defaultValue, messageDefaultInstance,
- new ExtensionDescriptorLite(enumTypeMap, number, type,
+ new ExtensionDescriptorLite(enumTypeMap, number, type, defaultValue,
true /* isRepeated */, isPacked)) {
}
/// <summary>
+ /// Returns information about this extension
+ /// </summary>
+ public IFieldDescriptorLite Descriptor {
+ get { return descriptor; }
+ }
+
+ /// <summary>
+ /// Returns the default value for this extension
+ /// </summary>
+ public TExtensionType DefaultValue {
+ get { return defaultValue; }
+ }
+
+ /// <summary>
/// used for the extension registry
/// </summary>
object IGeneratedExtensionLite.ContainingType {
@@ -102,7 +211,7 @@ namespace Google.ProtocolBuffers {
/** Get the field number. */
public int Number {
get {
- return descriptor.Number;
+ return descriptor.FieldNumber;
}
}
/**
@@ -114,5 +223,9 @@ namespace Google.ProtocolBuffers {
return messageDefaultInstance;
}
}
+
+ public object SingularFromReflectionType(object value) {
+ return value;
+ }
}
} \ No newline at end of file