aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers/GeneratedExtensionLite.cs
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2010-11-07 10:49:33 -0600
committercsharptest <roger@csharptest.net>2010-11-07 10:49:33 -0600
commit804b6d842e9202cd79039cd8e7aa899426d37f78 (patch)
treee0fe5bb1fcca18f49ae4909081a6cfd3291d947c /src/ProtocolBuffers/GeneratedExtensionLite.cs
parent64bfac2825d69c0359e40c876ec4130e23f53fb7 (diff)
downloadprotobuf-804b6d842e9202cd79039cd8e7aa899426d37f78.tar.gz
protobuf-804b6d842e9202cd79039cd8e7aa899426d37f78.tar.bz2
protobuf-804b6d842e9202cd79039cd8e7aa899426d37f78.zip
Implementation work for Lite runtime and generator
Diffstat (limited to 'src/ProtocolBuffers/GeneratedExtensionLite.cs')
-rw-r--r--src/ProtocolBuffers/GeneratedExtensionLite.cs108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/ProtocolBuffers/GeneratedExtensionLite.cs b/src/ProtocolBuffers/GeneratedExtensionLite.cs
index 9b3cf504..da07fb8c 100644
--- a/src/ProtocolBuffers/GeneratedExtensionLite.cs
+++ b/src/ProtocolBuffers/GeneratedExtensionLite.cs
@@ -1,4 +1,5 @@
using System;
+using Google.ProtocolBuffers.Descriptors;
namespace Google.ProtocolBuffers {
@@ -7,4 +8,111 @@ namespace Google.ProtocolBuffers {
object ContainingType { get; }
IMessageLite MessageDefaultInstance { get; }
}
+
+ public class ExtensionDescriptorLite {
+ private readonly EnumLiteMap enumTypeMap;
+ private readonly int number;
+ private readonly FieldType type;
+ private readonly bool isRepeated;
+ private readonly bool isPacked;
+
+ public ExtensionDescriptorLite(EnumLiteMap enumTypeMap, int number, FieldType type, bool isRepeated, bool isPacked) {
+ this.enumTypeMap = enumTypeMap;
+ this.number = number;
+ this.type = type;
+ this.isRepeated = isRepeated;
+ this.isPacked = isPacked;
+ }
+
+ public int Number {
+ get { return number; }
+ }
+ }
+
+ public class EnumLiteMap { }
+
+ public class GeneratedExtensionLite<TContainingType, TExtensionType> : IGeneratedExtensionLite
+ where TContainingType : IMessageLite {
+
+ private readonly TContainingType containingTypeDefaultInstance;
+ private readonly TExtensionType defaultValue;
+ private readonly IMessageLite messageDefaultInstance;
+ private readonly ExtensionDescriptorLite descriptor;
+
+ // We can't always initialize a GeneratedExtension when we first construct
+ // it due to initialization order difficulties (namely, the default
+ // instances may not have been constructed yet). So, we construct an
+ // uninitialized GeneratedExtension once, then call internalInit() on it
+ // later. Generated code will always call internalInit() on all extensions
+ // as part of the static initialization code, and internalInit() throws an
+ // exception if called more than once, so this method is useless to users.
+ protected GeneratedExtensionLite(
+ TContainingType containingTypeDefaultInstance,
+ TExtensionType defaultValue,
+ IMessageLite messageDefaultInstance,
+ ExtensionDescriptorLite descriptor) {
+ this.containingTypeDefaultInstance = containingTypeDefaultInstance;
+ this.messageDefaultInstance = messageDefaultInstance;
+ this.defaultValue = defaultValue;
+ this.descriptor = descriptor;
+ }
+
+ /** For use by generated code only. */
+ public GeneratedExtensionLite(
+ TContainingType containingTypeDefaultInstance,
+ TExtensionType defaultValue,
+ IMessageLite messageDefaultInstance,
+ EnumLiteMap enumTypeMap,
+ int number,
+ FieldType type)
+ : this(containingTypeDefaultInstance, defaultValue, messageDefaultInstance,
+ new ExtensionDescriptorLite(enumTypeMap, number, type,
+ false /* isRepeated */, false /* isPacked */)) {
+ }
+
+ /** For use by generated code only. */
+ public GeneratedExtensionLite(
+ TContainingType containingTypeDefaultInstance,
+ TExtensionType defaultValue,
+ IMessageLite messageDefaultInstance,
+ EnumLiteMap enumTypeMap,
+ int number,
+ FieldType type,
+ bool isPacked)
+ : this(containingTypeDefaultInstance, defaultValue, messageDefaultInstance,
+ new ExtensionDescriptorLite(enumTypeMap, number, type,
+ true /* isRepeated */, isPacked)) {
+ }
+
+ /// <summary>
+ /// used for the extension registry
+ /// </summary>
+ object IGeneratedExtensionLite.ContainingType {
+ get { return ContainingTypeDefaultInstance; }
+ }
+ /**
+ * Default instance of the type being extended, used to identify that type.
+ */
+ public TContainingType ContainingTypeDefaultInstance {
+ get {
+ return containingTypeDefaultInstance;
+ }
+ }
+
+ /** Get the field number. */
+ public int Number {
+ get {
+ return descriptor.Number;
+ }
+ }
+ /**
+ * If the extension is an embedded message, this is the default instance of
+ * that type.
+ */
+ public IMessageLite MessageDefaultInstance {
+ get {
+ return messageDefaultInstance;
+ }
+ }
+ }
} \ No newline at end of file