aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/ProtocolBuffers/GeneratedBuilder.cs
blob: a98dbccc91ec72c13c5d97bac2257209149d878c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Collections.Generic;
using System.Text;
using Google.ProtocolBuffers.Collections;
using Google.ProtocolBuffers.Descriptors;

namespace Google.ProtocolBuffers {
  /// <summary>
  /// All generated protocol message builder classes extend this class. It implements
  /// most of the IBuilder interface using reflection. Users can ignore this class
  /// as an implementation detail.
  /// </summary>
  public abstract class GeneratedBuilder<TMessage, TBuilder> : AbstractBuilder, IBuilder<TMessage>
      where TMessage : GeneratedMessage <TMessage, TBuilder>
      where TBuilder : GeneratedBuilder<TMessage, TBuilder>, IBuilder<TMessage> {

    /// <summary>
    /// Returns the message being built at the moment.
    /// </summary>
    protected abstract GeneratedMessage<TMessage,TBuilder> MessageBeingBuilt { get; }

    public override bool Initialized {
      get { return MessageBeingBuilt.IsInitialized; }
    }

    public override IDictionary<FieldDescriptor, object> AllFields {
      get { return MessageBeingBuilt.AllFields; }
    }

    public override object this[FieldDescriptor field] {
      get {
        // For repeated fields, the underlying list object is still modifiable at this point.
        // Make sure not to expose the modifiable list to the caller.
        return field.IsRepeated
          ? MessageBeingBuilt.InternalFieldAccessors[field].GetRepeatedWrapper(this)
          : MessageBeingBuilt[field];
      }
      set {
        MessageBeingBuilt.InternalFieldAccessors[field].SetValue(this, value);
      }
    }

    public override MessageDescriptor DescriptorForType {
      get { return MessageBeingBuilt.DescriptorForType; }
    }

    public override int GetRepeatedFieldCount(FieldDescriptor field) {
      return MessageBeingBuilt.GetRepeatedFieldCount(field);
    }

    public override object this[FieldDescriptor field, int index] {
      get { return MessageBeingBuilt[field, index]; }
      set { MessageBeingBuilt.InternalFieldAccessors[field].SetRepeated(this, index, value); }
    }

    public override bool HasField(FieldDescriptor field) {
      return MessageBeingBuilt.HasField(field);
    }

    protected override IMessage BuildImpl() {
      return Build();
    }

    protected override IMessage BuildPartialImpl() {
      return BuildPartial();
    }

    protected override IBuilder CloneImpl() {
      return Clone();
    }

    protected override IMessage DefaultInstanceForTypeImpl {
      get { return DefaultInstanceForType; }
    }

    protected override IBuilder CreateBuilderForFieldImpl(FieldDescriptor field) {
      return CreateBuilderForField(field);
    }

    protected override IBuilder ClearFieldImpl(FieldDescriptor field) {
      return ClearField(field);
    }

    protected override IBuilder AddRepeatedFieldImpl(FieldDescriptor field, object value) {
      return AddRepeatedField(field, value);
    }

    public new abstract IBuilder<TMessage> Clear();

    public IBuilder<TMessage> MergeFrom(IMessage<TMessage> other) {
      throw new NotImplementedException();
    }

    public abstract TMessage Build();

    public abstract TMessage BuildPartial();

    public abstract IBuilder<TMessage> Clone();

    IBuilder<TMessage> IBuilder<TMessage>.MergeFrom(CodedInputStream input) {
      throw new NotImplementedException();
    }

    IBuilder<TMessage> IBuilder<TMessage>.MergeFrom(CodedInputStream input, ExtensionRegistry extensionRegistry) {
      throw new NotImplementedException();
    }

    public TMessage DefaultInstanceForType {
      get { throw new NotImplementedException(); }
    }

    public IBuilder CreateBuilderForField(FieldDescriptor field) {
      throw new NotImplementedException();
    }

    public IBuilder<TMessage> ClearField(FieldDescriptor field) {
      MessageBeingBuilt.InternalFieldAccessors[field].Clear(this);
      return this;
    }

    public IBuilder<TMessage> AddRepeatedField(FieldDescriptor field, object value) {
      return this;
    }

    public new IBuilder<TMessage> MergeUnknownFields(UnknownFieldSet unknownFields) {
      throw new NotImplementedException();
    }

    IBuilder<TMessage> IBuilder<TMessage>.MergeFrom(ByteString data) {
      throw new NotImplementedException();
    }

    IBuilder<TMessage> IBuilder<TMessage>.MergeFrom(ByteString data, ExtensionRegistry extensionRegistry) {
      throw new NotImplementedException();
    }

    IBuilder<TMessage> IBuilder<TMessage>.MergeFrom(byte[] data) {
      throw new NotImplementedException();
    }

    IBuilder<TMessage> IBuilder<TMessage>.MergeFrom(byte[] data, ExtensionRegistry extensionRegistry) {
      throw new NotImplementedException();
    }

    IBuilder<TMessage> IBuilder<TMessage>.MergeFrom(System.IO.Stream input) {
      throw new NotImplementedException();
    }

    IBuilder<TMessage> IBuilder<TMessage>.MergeFrom(System.IO.Stream input, ExtensionRegistry extensionRegistry) {
      throw new NotImplementedException();
    }
  }
}