aboutsummaryrefslogtreecommitdiff
path: root/src/ProtoGen/FieldGeneratorBase.cs
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2009-02-18 16:06:22 +0000
committerJon Skeet <skeet@pobox.com>2009-02-18 16:06:22 +0000
commit25a28580a6f307cb8eb040367f5671e678e9896b (patch)
tree6ce918e09f644733ad514eac706208be2d5f7883 /src/ProtoGen/FieldGeneratorBase.cs
parent0ca3fecfafe6b2f7b6de4a5e1b978353fcaae83b (diff)
downloadprotobuf-25a28580a6f307cb8eb040367f5671e678e9896b.tar.gz
protobuf-25a28580a6f307cb8eb040367f5671e678e9896b.tar.bz2
protobuf-25a28580a6f307cb8eb040367f5671e678e9896b.zip
Support packed primitive types
Diffstat (limited to 'src/ProtoGen/FieldGeneratorBase.cs')
-rw-r--r--src/ProtoGen/FieldGeneratorBase.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/ProtoGen/FieldGeneratorBase.cs b/src/ProtoGen/FieldGeneratorBase.cs
index 207f3fdc..357614d1 100644
--- a/src/ProtoGen/FieldGeneratorBase.cs
+++ b/src/ProtoGen/FieldGeneratorBase.cs
@@ -97,6 +97,45 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
+ /// <summary>
+ /// For encodings with fixed sizes, returns that size in bytes. Otherwise
+ /// returns -1. TODO(jonskeet): Make this less ugly.
+ /// </summary>
+ protected int FixedSize {
+ get {
+ switch (Descriptor.FieldType) {
+ case FieldType.UInt32:
+ case FieldType.UInt64:
+ case FieldType.Int32:
+ case FieldType.Int64:
+ case FieldType.SInt32:
+ case FieldType.SInt64:
+ case FieldType.Enum:
+ case FieldType.Bytes:
+ case FieldType.String:
+ case FieldType.Message:
+ case FieldType.Group:
+ return -1;
+ case FieldType.Float:
+ return WireFormat.FloatSize;
+ case FieldType.SFixed32:
+ return WireFormat.SFixed32Size;
+ case FieldType.Fixed32:
+ return WireFormat.Fixed32Size;
+ case FieldType.Double:
+ return WireFormat.DoubleSize;
+ case FieldType.SFixed64:
+ return WireFormat.SFixed64Size;
+ case FieldType.Fixed64:
+ return WireFormat.Fixed64Size;
+ case FieldType.Bool:
+ return WireFormat.BoolSize;
+ default:
+ throw new InvalidOperationException("Invalid field descriptor type");
+ }
+ }
+ }
+
protected bool IsNullableType {
get {
switch (Descriptor.FieldType) {