xref: /aosp_15_r20/external/protobuf/csharp/src/Google.Protobuf/WriteContext.cs (revision 1b3f573f81763fcece89efc2b6a5209149e44ab8)
1*1b3f573fSAndroid Build Coastguard Worker #region Copyright notice and license
2*1b3f573fSAndroid Build Coastguard Worker // Protocol Buffers - Google's data interchange format
3*1b3f573fSAndroid Build Coastguard Worker // Copyright 2008 Google Inc.  All rights reserved.
4*1b3f573fSAndroid Build Coastguard Worker // https://developers.google.com/protocol-buffers/
5*1b3f573fSAndroid Build Coastguard Worker //
6*1b3f573fSAndroid Build Coastguard Worker // Redistribution and use in source and binary forms, with or without
7*1b3f573fSAndroid Build Coastguard Worker // modification, are permitted provided that the following conditions are
8*1b3f573fSAndroid Build Coastguard Worker // met:
9*1b3f573fSAndroid Build Coastguard Worker //
10*1b3f573fSAndroid Build Coastguard Worker //     * Redistributions of source code must retain the above copyright
11*1b3f573fSAndroid Build Coastguard Worker // notice, this list of conditions and the following disclaimer.
12*1b3f573fSAndroid Build Coastguard Worker //     * Redistributions in binary form must reproduce the above
13*1b3f573fSAndroid Build Coastguard Worker // copyright notice, this list of conditions and the following disclaimer
14*1b3f573fSAndroid Build Coastguard Worker // in the documentation and/or other materials provided with the
15*1b3f573fSAndroid Build Coastguard Worker // distribution.
16*1b3f573fSAndroid Build Coastguard Worker //     * Neither the name of Google Inc. nor the names of its
17*1b3f573fSAndroid Build Coastguard Worker // contributors may be used to endorse or promote products derived from
18*1b3f573fSAndroid Build Coastguard Worker // this software without specific prior written permission.
19*1b3f573fSAndroid Build Coastguard Worker //
20*1b3f573fSAndroid Build Coastguard Worker // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21*1b3f573fSAndroid Build Coastguard Worker // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*1b3f573fSAndroid Build Coastguard Worker // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23*1b3f573fSAndroid Build Coastguard Worker // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24*1b3f573fSAndroid Build Coastguard Worker // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25*1b3f573fSAndroid Build Coastguard Worker // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26*1b3f573fSAndroid Build Coastguard Worker // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27*1b3f573fSAndroid Build Coastguard Worker // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28*1b3f573fSAndroid Build Coastguard Worker // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29*1b3f573fSAndroid Build Coastguard Worker // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30*1b3f573fSAndroid Build Coastguard Worker // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*1b3f573fSAndroid Build Coastguard Worker #endregion
32*1b3f573fSAndroid Build Coastguard Worker 
33*1b3f573fSAndroid Build Coastguard Worker using System;
34*1b3f573fSAndroid Build Coastguard Worker using System.Buffers;
35*1b3f573fSAndroid Build Coastguard Worker using System.Buffers.Binary;
36*1b3f573fSAndroid Build Coastguard Worker using System.Collections.Generic;
37*1b3f573fSAndroid Build Coastguard Worker using System.IO;
38*1b3f573fSAndroid Build Coastguard Worker using System.Runtime.CompilerServices;
39*1b3f573fSAndroid Build Coastguard Worker using System.Runtime.InteropServices;
40*1b3f573fSAndroid Build Coastguard Worker using System.Security;
41*1b3f573fSAndroid Build Coastguard Worker using System.Text;
42*1b3f573fSAndroid Build Coastguard Worker using Google.Protobuf.Collections;
43*1b3f573fSAndroid Build Coastguard Worker 
44*1b3f573fSAndroid Build Coastguard Worker namespace Google.Protobuf
45*1b3f573fSAndroid Build Coastguard Worker {
46*1b3f573fSAndroid Build Coastguard Worker     /// <summary>
47*1b3f573fSAndroid Build Coastguard Worker     /// An opaque struct that represents the current serialization state and is passed along
48*1b3f573fSAndroid Build Coastguard Worker     /// as the serialization proceeds.
49*1b3f573fSAndroid Build Coastguard Worker     /// All the public methods are intended to be invoked only by the generated code,
50*1b3f573fSAndroid Build Coastguard Worker     /// users should never invoke them directly.
51*1b3f573fSAndroid Build Coastguard Worker     /// </summary>
52*1b3f573fSAndroid Build Coastguard Worker     [SecuritySafeCritical]
53*1b3f573fSAndroid Build Coastguard Worker     public ref struct WriteContext
54*1b3f573fSAndroid Build Coastguard Worker     {
55*1b3f573fSAndroid Build Coastguard Worker         internal Span<byte> buffer;
56*1b3f573fSAndroid Build Coastguard Worker         internal WriterInternalState state;
57*1b3f573fSAndroid Build Coastguard Worker 
58*1b3f573fSAndroid Build Coastguard Worker         [MethodImpl(MethodImplOptions.AggressiveInlining)]
InitializeGoogle.Protobuf.WriteContext59*1b3f573fSAndroid Build Coastguard Worker         internal static void Initialize(ref Span<byte> buffer, ref WriterInternalState state, out WriteContext ctx)
60*1b3f573fSAndroid Build Coastguard Worker         {
61*1b3f573fSAndroid Build Coastguard Worker             ctx.buffer = buffer;
62*1b3f573fSAndroid Build Coastguard Worker             ctx.state = state;
63*1b3f573fSAndroid Build Coastguard Worker         }
64*1b3f573fSAndroid Build Coastguard Worker 
65*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
66*1b3f573fSAndroid Build Coastguard Worker         /// Creates a WriteContext instance from CodedOutputStream.
67*1b3f573fSAndroid Build Coastguard Worker         /// WARNING: internally this copies the CodedOutputStream's state, so after done with the WriteContext,
68*1b3f573fSAndroid Build Coastguard Worker         /// the CodedOutputStream's state needs to be updated.
69*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
70*1b3f573fSAndroid Build Coastguard Worker         [MethodImpl(MethodImplOptions.AggressiveInlining)]
InitializeGoogle.Protobuf.WriteContext71*1b3f573fSAndroid Build Coastguard Worker         internal static void Initialize(CodedOutputStream output, out WriteContext ctx)
72*1b3f573fSAndroid Build Coastguard Worker         {
73*1b3f573fSAndroid Build Coastguard Worker             ctx.buffer = new Span<byte>(output.InternalBuffer);
74*1b3f573fSAndroid Build Coastguard Worker             // ideally we would use a reference to the original state, but that doesn't seem possible
75*1b3f573fSAndroid Build Coastguard Worker             // so we just copy the struct that holds the state. We will need to later store the state back
76*1b3f573fSAndroid Build Coastguard Worker             // into CodedOutputStream if we want to keep it usable.
77*1b3f573fSAndroid Build Coastguard Worker             ctx.state = output.InternalState;
78*1b3f573fSAndroid Build Coastguard Worker         }
79*1b3f573fSAndroid Build Coastguard Worker 
80*1b3f573fSAndroid Build Coastguard Worker         [MethodImpl(MethodImplOptions.AggressiveInlining)]
InitializeGoogle.Protobuf.WriteContext81*1b3f573fSAndroid Build Coastguard Worker         internal static void Initialize(IBufferWriter<byte> output, out WriteContext ctx)
82*1b3f573fSAndroid Build Coastguard Worker         {
83*1b3f573fSAndroid Build Coastguard Worker             ctx.buffer = default;
84*1b3f573fSAndroid Build Coastguard Worker             ctx.state = default;
85*1b3f573fSAndroid Build Coastguard Worker             WriteBufferHelper.Initialize(output, out ctx.state.writeBufferHelper, out ctx.buffer);
86*1b3f573fSAndroid Build Coastguard Worker             ctx.state.limit = ctx.buffer.Length;
87*1b3f573fSAndroid Build Coastguard Worker             ctx.state.position = 0;
88*1b3f573fSAndroid Build Coastguard Worker         }
89*1b3f573fSAndroid Build Coastguard Worker 
90*1b3f573fSAndroid Build Coastguard Worker         [MethodImpl(MethodImplOptions.AggressiveInlining)]
InitializeGoogle.Protobuf.WriteContext91*1b3f573fSAndroid Build Coastguard Worker         internal static void Initialize(ref Span<byte> buffer, out WriteContext ctx)
92*1b3f573fSAndroid Build Coastguard Worker         {
93*1b3f573fSAndroid Build Coastguard Worker             ctx.buffer = buffer;
94*1b3f573fSAndroid Build Coastguard Worker             ctx.state = default;
95*1b3f573fSAndroid Build Coastguard Worker             ctx.state.limit = ctx.buffer.Length;
96*1b3f573fSAndroid Build Coastguard Worker             ctx.state.position = 0;
97*1b3f573fSAndroid Build Coastguard Worker             WriteBufferHelper.InitializeNonRefreshable(out ctx.state.writeBufferHelper);
98*1b3f573fSAndroid Build Coastguard Worker         }
99*1b3f573fSAndroid Build Coastguard Worker 
100*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
101*1b3f573fSAndroid Build Coastguard Worker         /// Writes a double field value, without a tag.
102*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
103*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteDoubleGoogle.Protobuf.WriteContext104*1b3f573fSAndroid Build Coastguard Worker         public void WriteDouble(double value)
105*1b3f573fSAndroid Build Coastguard Worker         {
106*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteDouble(ref buffer, ref state, value);
107*1b3f573fSAndroid Build Coastguard Worker         }
108*1b3f573fSAndroid Build Coastguard Worker 
109*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
110*1b3f573fSAndroid Build Coastguard Worker         /// Writes a float field value, without a tag.
111*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
112*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteFloatGoogle.Protobuf.WriteContext113*1b3f573fSAndroid Build Coastguard Worker         public void WriteFloat(float value)
114*1b3f573fSAndroid Build Coastguard Worker         {
115*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteFloat(ref buffer, ref state, value);
116*1b3f573fSAndroid Build Coastguard Worker         }
117*1b3f573fSAndroid Build Coastguard Worker 
118*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
119*1b3f573fSAndroid Build Coastguard Worker         /// Writes a uint64 field value, without a tag.
120*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
121*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteUInt64Google.Protobuf.WriteContext122*1b3f573fSAndroid Build Coastguard Worker         public void WriteUInt64(ulong value)
123*1b3f573fSAndroid Build Coastguard Worker         {
124*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteUInt64(ref buffer, ref state, value);
125*1b3f573fSAndroid Build Coastguard Worker         }
126*1b3f573fSAndroid Build Coastguard Worker 
127*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
128*1b3f573fSAndroid Build Coastguard Worker         /// Writes an int64 field value, without a tag.
129*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
130*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteInt64Google.Protobuf.WriteContext131*1b3f573fSAndroid Build Coastguard Worker         public void WriteInt64(long value)
132*1b3f573fSAndroid Build Coastguard Worker         {
133*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteInt64(ref buffer, ref state, value);
134*1b3f573fSAndroid Build Coastguard Worker         }
135*1b3f573fSAndroid Build Coastguard Worker 
136*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
137*1b3f573fSAndroid Build Coastguard Worker         /// Writes an int32 field value, without a tag.
138*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
139*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteInt32Google.Protobuf.WriteContext140*1b3f573fSAndroid Build Coastguard Worker         public void WriteInt32(int value)
141*1b3f573fSAndroid Build Coastguard Worker         {
142*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteInt32(ref buffer, ref state, value);
143*1b3f573fSAndroid Build Coastguard Worker         }
144*1b3f573fSAndroid Build Coastguard Worker 
145*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
146*1b3f573fSAndroid Build Coastguard Worker         /// Writes a fixed64 field value, without a tag.
147*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
148*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteFixed64Google.Protobuf.WriteContext149*1b3f573fSAndroid Build Coastguard Worker         public void WriteFixed64(ulong value)
150*1b3f573fSAndroid Build Coastguard Worker         {
151*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteFixed64(ref buffer, ref state, value);
152*1b3f573fSAndroid Build Coastguard Worker         }
153*1b3f573fSAndroid Build Coastguard Worker 
154*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
155*1b3f573fSAndroid Build Coastguard Worker         /// Writes a fixed32 field value, without a tag.
156*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
157*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteFixed32Google.Protobuf.WriteContext158*1b3f573fSAndroid Build Coastguard Worker         public void WriteFixed32(uint value)
159*1b3f573fSAndroid Build Coastguard Worker         {
160*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteFixed32(ref buffer, ref state, value);
161*1b3f573fSAndroid Build Coastguard Worker         }
162*1b3f573fSAndroid Build Coastguard Worker 
163*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
164*1b3f573fSAndroid Build Coastguard Worker         /// Writes a bool field value, without a tag.
165*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
166*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteBoolGoogle.Protobuf.WriteContext167*1b3f573fSAndroid Build Coastguard Worker         public void WriteBool(bool value)
168*1b3f573fSAndroid Build Coastguard Worker         {
169*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteBool(ref buffer, ref state, value);
170*1b3f573fSAndroid Build Coastguard Worker         }
171*1b3f573fSAndroid Build Coastguard Worker 
172*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
173*1b3f573fSAndroid Build Coastguard Worker         /// Writes a string field value, without a tag.
174*1b3f573fSAndroid Build Coastguard Worker         /// The data is length-prefixed.
175*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
176*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteStringGoogle.Protobuf.WriteContext177*1b3f573fSAndroid Build Coastguard Worker         public void WriteString(string value)
178*1b3f573fSAndroid Build Coastguard Worker         {
179*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteString(ref buffer, ref state, value);
180*1b3f573fSAndroid Build Coastguard Worker         }
181*1b3f573fSAndroid Build Coastguard Worker 
182*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
183*1b3f573fSAndroid Build Coastguard Worker         /// Writes a message, without a tag.
184*1b3f573fSAndroid Build Coastguard Worker         /// The data is length-prefixed.
185*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
186*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteMessageGoogle.Protobuf.WriteContext187*1b3f573fSAndroid Build Coastguard Worker         public void WriteMessage(IMessage value)
188*1b3f573fSAndroid Build Coastguard Worker         {
189*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitivesMessages.WriteMessage(ref this, value);
190*1b3f573fSAndroid Build Coastguard Worker         }
191*1b3f573fSAndroid Build Coastguard Worker 
192*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
193*1b3f573fSAndroid Build Coastguard Worker         /// Writes a group, without a tag, to the stream.
194*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
195*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteGroupGoogle.Protobuf.WriteContext196*1b3f573fSAndroid Build Coastguard Worker         public void WriteGroup(IMessage value)
197*1b3f573fSAndroid Build Coastguard Worker         {
198*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitivesMessages.WriteGroup(ref this, value);
199*1b3f573fSAndroid Build Coastguard Worker         }
200*1b3f573fSAndroid Build Coastguard Worker 
201*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
202*1b3f573fSAndroid Build Coastguard Worker         /// Write a byte string, without a tag, to the stream.
203*1b3f573fSAndroid Build Coastguard Worker         /// The data is length-prefixed.
204*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
205*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteBytesGoogle.Protobuf.WriteContext206*1b3f573fSAndroid Build Coastguard Worker         public void WriteBytes(ByteString value)
207*1b3f573fSAndroid Build Coastguard Worker         {
208*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteBytes(ref buffer, ref state, value);
209*1b3f573fSAndroid Build Coastguard Worker         }
210*1b3f573fSAndroid Build Coastguard Worker 
211*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
212*1b3f573fSAndroid Build Coastguard Worker         /// Writes a uint32 value, without a tag.
213*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
214*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteUInt32Google.Protobuf.WriteContext215*1b3f573fSAndroid Build Coastguard Worker         public void WriteUInt32(uint value)
216*1b3f573fSAndroid Build Coastguard Worker         {
217*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteUInt32(ref buffer, ref state, value);
218*1b3f573fSAndroid Build Coastguard Worker         }
219*1b3f573fSAndroid Build Coastguard Worker 
220*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
221*1b3f573fSAndroid Build Coastguard Worker         /// Writes an enum value, without a tag.
222*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
223*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteEnumGoogle.Protobuf.WriteContext224*1b3f573fSAndroid Build Coastguard Worker         public void WriteEnum(int value)
225*1b3f573fSAndroid Build Coastguard Worker         {
226*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteEnum(ref buffer, ref state, value);
227*1b3f573fSAndroid Build Coastguard Worker         }
228*1b3f573fSAndroid Build Coastguard Worker 
229*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
230*1b3f573fSAndroid Build Coastguard Worker         /// Writes an sfixed32 value, without a tag.
231*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
232*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write.</param>
WriteSFixed32Google.Protobuf.WriteContext233*1b3f573fSAndroid Build Coastguard Worker         public void WriteSFixed32(int value)
234*1b3f573fSAndroid Build Coastguard Worker         {
235*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteSFixed32(ref buffer, ref state, value);
236*1b3f573fSAndroid Build Coastguard Worker         }
237*1b3f573fSAndroid Build Coastguard Worker 
238*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
239*1b3f573fSAndroid Build Coastguard Worker         /// Writes an sfixed64 value, without a tag.
240*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
241*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteSFixed64Google.Protobuf.WriteContext242*1b3f573fSAndroid Build Coastguard Worker         public void WriteSFixed64(long value)
243*1b3f573fSAndroid Build Coastguard Worker         {
244*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteSFixed64(ref buffer, ref state, value);
245*1b3f573fSAndroid Build Coastguard Worker         }
246*1b3f573fSAndroid Build Coastguard Worker 
247*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
248*1b3f573fSAndroid Build Coastguard Worker         /// Writes an sint32 value, without a tag.
249*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
250*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteSInt32Google.Protobuf.WriteContext251*1b3f573fSAndroid Build Coastguard Worker         public void WriteSInt32(int value)
252*1b3f573fSAndroid Build Coastguard Worker         {
253*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteSInt32(ref buffer, ref state, value);
254*1b3f573fSAndroid Build Coastguard Worker         }
255*1b3f573fSAndroid Build Coastguard Worker 
256*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
257*1b3f573fSAndroid Build Coastguard Worker         /// Writes an sint64 value, without a tag.
258*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
259*1b3f573fSAndroid Build Coastguard Worker         /// <param name="value">The value to write</param>
WriteSInt64Google.Protobuf.WriteContext260*1b3f573fSAndroid Build Coastguard Worker         public void WriteSInt64(long value)
261*1b3f573fSAndroid Build Coastguard Worker         {
262*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteSInt64(ref buffer, ref state, value);
263*1b3f573fSAndroid Build Coastguard Worker         }
264*1b3f573fSAndroid Build Coastguard Worker 
265*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
266*1b3f573fSAndroid Build Coastguard Worker         /// Writes a length (in bytes) for length-delimited data.
267*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
268*1b3f573fSAndroid Build Coastguard Worker         /// <remarks>
269*1b3f573fSAndroid Build Coastguard Worker         /// This method simply writes a rawint, but exists for clarity in calling code.
270*1b3f573fSAndroid Build Coastguard Worker         /// </remarks>
271*1b3f573fSAndroid Build Coastguard Worker         /// <param name="length">Length value, in bytes.</param>
WriteLengthGoogle.Protobuf.WriteContext272*1b3f573fSAndroid Build Coastguard Worker         public void WriteLength(int length)
273*1b3f573fSAndroid Build Coastguard Worker         {
274*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteLength(ref buffer, ref state, length);
275*1b3f573fSAndroid Build Coastguard Worker         }
276*1b3f573fSAndroid Build Coastguard Worker 
277*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
278*1b3f573fSAndroid Build Coastguard Worker         /// Encodes and writes a tag.
279*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
280*1b3f573fSAndroid Build Coastguard Worker         /// <param name="fieldNumber">The number of the field to write the tag for</param>
281*1b3f573fSAndroid Build Coastguard Worker         /// <param name="type">The wire format type of the tag to write</param>
WriteTagGoogle.Protobuf.WriteContext282*1b3f573fSAndroid Build Coastguard Worker         public void WriteTag(int fieldNumber, WireFormat.WireType type)
283*1b3f573fSAndroid Build Coastguard Worker         {
284*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteTag(ref buffer, ref state, fieldNumber, type);
285*1b3f573fSAndroid Build Coastguard Worker         }
286*1b3f573fSAndroid Build Coastguard Worker 
287*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
288*1b3f573fSAndroid Build Coastguard Worker         /// Writes an already-encoded tag.
289*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
290*1b3f573fSAndroid Build Coastguard Worker         /// <param name="tag">The encoded tag</param>
WriteTagGoogle.Protobuf.WriteContext291*1b3f573fSAndroid Build Coastguard Worker         public void WriteTag(uint tag)
292*1b3f573fSAndroid Build Coastguard Worker         {
293*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteTag(ref buffer, ref state, tag);
294*1b3f573fSAndroid Build Coastguard Worker         }
295*1b3f573fSAndroid Build Coastguard Worker 
296*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
297*1b3f573fSAndroid Build Coastguard Worker         /// Writes the given single-byte tag.
298*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
299*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b1">The encoded tag</param>
WriteRawTagGoogle.Protobuf.WriteContext300*1b3f573fSAndroid Build Coastguard Worker         public void WriteRawTag(byte b1)
301*1b3f573fSAndroid Build Coastguard Worker         {
302*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteRawTag(ref buffer, ref state, b1);
303*1b3f573fSAndroid Build Coastguard Worker         }
304*1b3f573fSAndroid Build Coastguard Worker 
305*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
306*1b3f573fSAndroid Build Coastguard Worker         /// Writes the given two-byte tag.
307*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
308*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b1">The first byte of the encoded tag</param>
309*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b2">The second byte of the encoded tag</param>
WriteRawTagGoogle.Protobuf.WriteContext310*1b3f573fSAndroid Build Coastguard Worker         public void WriteRawTag(byte b1, byte b2)
311*1b3f573fSAndroid Build Coastguard Worker         {
312*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2);
313*1b3f573fSAndroid Build Coastguard Worker         }
314*1b3f573fSAndroid Build Coastguard Worker 
315*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
316*1b3f573fSAndroid Build Coastguard Worker         /// Writes the given three-byte tag.
317*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
318*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b1">The first byte of the encoded tag</param>
319*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b2">The second byte of the encoded tag</param>
320*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b3">The third byte of the encoded tag</param>
WriteRawTagGoogle.Protobuf.WriteContext321*1b3f573fSAndroid Build Coastguard Worker         public void WriteRawTag(byte b1, byte b2, byte b3)
322*1b3f573fSAndroid Build Coastguard Worker         {
323*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3);
324*1b3f573fSAndroid Build Coastguard Worker         }
325*1b3f573fSAndroid Build Coastguard Worker 
326*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
327*1b3f573fSAndroid Build Coastguard Worker         /// Writes the given four-byte tag.
328*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
329*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b1">The first byte of the encoded tag</param>
330*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b2">The second byte of the encoded tag</param>
331*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b3">The third byte of the encoded tag</param>
332*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b4">The fourth byte of the encoded tag</param>
WriteRawTagGoogle.Protobuf.WriteContext333*1b3f573fSAndroid Build Coastguard Worker         public void WriteRawTag(byte b1, byte b2, byte b3, byte b4)
334*1b3f573fSAndroid Build Coastguard Worker         {
335*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3, b4);
336*1b3f573fSAndroid Build Coastguard Worker         }
337*1b3f573fSAndroid Build Coastguard Worker 
338*1b3f573fSAndroid Build Coastguard Worker         /// <summary>
339*1b3f573fSAndroid Build Coastguard Worker         /// Writes the given five-byte tag.
340*1b3f573fSAndroid Build Coastguard Worker         /// </summary>
341*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b1">The first byte of the encoded tag</param>
342*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b2">The second byte of the encoded tag</param>
343*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b3">The third byte of the encoded tag</param>
344*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b4">The fourth byte of the encoded tag</param>
345*1b3f573fSAndroid Build Coastguard Worker         /// <param name="b5">The fifth byte of the encoded tag</param>
WriteRawTagGoogle.Protobuf.WriteContext346*1b3f573fSAndroid Build Coastguard Worker         public void WriteRawTag(byte b1, byte b2, byte b3, byte b4, byte b5)
347*1b3f573fSAndroid Build Coastguard Worker         {
348*1b3f573fSAndroid Build Coastguard Worker             WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3, b4, b5);
349*1b3f573fSAndroid Build Coastguard Worker         }
350*1b3f573fSAndroid Build Coastguard Worker 
FlushGoogle.Protobuf.WriteContext351*1b3f573fSAndroid Build Coastguard Worker         internal void Flush()
352*1b3f573fSAndroid Build Coastguard Worker         {
353*1b3f573fSAndroid Build Coastguard Worker             WriteBufferHelper.Flush(ref buffer, ref state);
354*1b3f573fSAndroid Build Coastguard Worker         }
355*1b3f573fSAndroid Build Coastguard Worker 
CheckNoSpaceLeftGoogle.Protobuf.WriteContext356*1b3f573fSAndroid Build Coastguard Worker         internal void CheckNoSpaceLeft()
357*1b3f573fSAndroid Build Coastguard Worker         {
358*1b3f573fSAndroid Build Coastguard Worker             WriteBufferHelper.CheckNoSpaceLeft(ref state);
359*1b3f573fSAndroid Build Coastguard Worker         }
360*1b3f573fSAndroid Build Coastguard Worker 
CopyStateToGoogle.Protobuf.WriteContext361*1b3f573fSAndroid Build Coastguard Worker         internal void CopyStateTo(CodedOutputStream output)
362*1b3f573fSAndroid Build Coastguard Worker         {
363*1b3f573fSAndroid Build Coastguard Worker             output.InternalState = state;
364*1b3f573fSAndroid Build Coastguard Worker         }
365*1b3f573fSAndroid Build Coastguard Worker 
LoadStateFromGoogle.Protobuf.WriteContext366*1b3f573fSAndroid Build Coastguard Worker         internal void LoadStateFrom(CodedOutputStream output)
367*1b3f573fSAndroid Build Coastguard Worker         {
368*1b3f573fSAndroid Build Coastguard Worker             state = output.InternalState;
369*1b3f573fSAndroid Build Coastguard Worker         }
370*1b3f573fSAndroid Build Coastguard Worker     }
371*1b3f573fSAndroid Build Coastguard Worker }