1
1
// Protocol Buffers - Google's data interchange format
2
// Copyright 2008 Google Inc.
2
// Copyright 2008 Google Inc. All rights reserved.
3
3
// http://code.google.com/p/protobuf/
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
9
// http://www.apache.org/licenses/LICENSE-2.0
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
9
// * Redistributions of source code must retain the above copyright
10
// notice, this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above
12
// copyright notice, this list of conditions and the following disclaimer
13
// in the documentation and/or other materials provided with the
15
// * Neither the name of Google Inc. nor the names of its
16
// contributors may be used to endorse or promote products derived from
17
// this software without specific prior written permission.
19
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
31
// Author: kenton@google.com (Kenton Varda)
18
32
// atenasio@google.com (Chris Atenasio) (ZigZag transform)
56
70
// These procedures can be used to implement the methods of Message which
57
71
// handle parsing and serialization of the protocol buffer wire format
58
// using only the Message::Reflection interface. When you ask the protocol
72
// using only the Reflection interface. When you ask the protocol
59
73
// compiler to optimize for code size rather than speed, it will implement
60
74
// those methods in terms of these procedures. Of course, these are much
61
75
// slower than the specialized implementations which the protocol compiler
70
84
// Required fields are NOT checked by this method. You must call
71
85
// IsInitialized() on the resulting message yourself.
72
static bool ParseAndMergePartial(const Descriptor* descriptor,
73
io::CodedInputStream* input,
74
Message::Reflection* message_reflection);
86
static bool ParseAndMergePartial(io::CodedInputStream* input,
76
89
// Serialize a message in protocol buffer wire format.
82
95
// These return false iff the underlying stream returns a write error.
83
96
static bool SerializeWithCachedSizes(
84
const Descriptor* descriptor,
85
const Message::Reflection* message_reflection,
97
const Message& message,
86
98
int size, io::CodedOutputStream* output);
88
100
// Implements Message::ByteSize() via reflection. WARNING: The result
90
102
// will have their ByteSize() methods called, so their sizes will be cached.
91
103
// Therefore, calling this method is sufficient to allow you to call
92
104
// WireFormat::SerializeWithCachedSizes() on the same object.
93
static int ByteSize(const Descriptor* descriptor,
94
const Message::Reflection* message_reflection);
105
static int ByteSize(const Message& message);
96
107
// -----------------------------------------------------------------
97
108
// Helpers for dealing with unknown fields
188
199
static bool ParseAndMergeField(
190
201
const FieldDescriptor* field, // May be NULL for unknown
191
Message::Reflection* message_reflection,
192
203
io::CodedInputStream* input);
194
205
// Serialize a single field.
195
206
static bool SerializeFieldWithCachedSizes(
196
207
const FieldDescriptor* field, // Cannot be NULL
197
const Message::Reflection* message_reflection,
208
const Message& message,
198
209
io::CodedOutputStream* output);
200
211
// Compute size of a single field. If the field is a message type, this
335
346
// opion message_set_wire_format = true.
336
347
static bool ParseAndMergeMessageSetItem(
337
348
io::CodedInputStream* input,
338
Message::Reflection* message_reflection);
339
350
static bool SerializeMessageSetItemWithCachedSizes(
340
351
const FieldDescriptor* field,
341
const Message::Reflection* message_reflection,
352
const Message& message,
342
353
io::CodedOutputStream* output);
343
354
static int MessageSetItemByteSize(
344
355
const FieldDescriptor* field,
345
const Message::Reflection* message_reflection);
356
const Message& message);
347
358
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WireFormat);