1e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// Protocol Buffers - Google's data interchange format
2e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// Copyright 2008 Google Inc.  All rights reserved.
3e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// http://code.google.com/p/protobuf/
4e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville//
5e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// Redistribution and use in source and binary forms, with or without
6e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// modification, are permitted provided that the following conditions are
7e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// met:
8e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville//
9e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville//     * Redistributions of source code must retain the above copyright
10e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// notice, this list of conditions and the following disclaimer.
11e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville//     * Redistributions in binary form must reproduce the above
12e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// copyright notice, this list of conditions and the following disclaimer
13e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// in the documentation and/or other materials provided with the
14e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// distribution.
15e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville//     * Neither the name of Google Inc. nor the names of its
16e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// contributors may be used to endorse or promote products derived from
17e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// this software without specific prior written permission.
18e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville//
19e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
31e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville// Author: kenton@google.com (Kenton Varda)
32e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville//  Based on original Protocol Buffers design by
33e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville//  Sanjay Ghemawat, Jeff Dean, and others.
34e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
35e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__
36e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__
37e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
38e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville#include <string>
39e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville#include <google/protobuf/stubs/common.h>
40e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville#include <google/protobuf/compiler/javamicro/javamicro_params.h>
41e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville#include <google/protobuf/compiler/javamicro/javamicro_field.h>
42e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
43e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Savillenamespace google {
44e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Savillenamespace protobuf {
45e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  namespace io {
46e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville    class Printer;             // printer.h
47e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  }
48e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville}
49e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
50e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Savillenamespace protobuf {
51e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Savillenamespace compiler {
52e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Savillenamespace javamicro {
53e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
54e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Savilleclass MessageGenerator {
55e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville public:
56e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  explicit MessageGenerator(const Descriptor* descriptor, const Params& params);
57e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  ~MessageGenerator();
58e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
59e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  // All static variables have to be declared at the top-level of the file
60e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  // so that we can control initialization order, which is important for
61e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  // DescriptorProto bootstrapping to work.
62e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  void GenerateStaticVariables(io::Printer* printer);
63e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
64e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  // Output code which initializes the static variables generated by
65e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  // GenerateStaticVariables().
66e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  void GenerateStaticVariableInitializers(io::Printer* printer);
67e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
68e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  // Generate the class itself.
69e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  void Generate(io::Printer* printer);
70e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
71e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville private:
72e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  void GenerateMessageSerializationMethods(io::Printer* printer);
73e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  void GenerateMergeFromMethods(io::Printer* printer);
74e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  void GenerateParseFromMethods(io::Printer* printer);
75e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  void GenerateSerializeOneField(io::Printer* printer,
76e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville                                 const FieldDescriptor* field);
77e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
78e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  void GenerateClear(io::Printer* printer);
79e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  void GenerateIsInitialized(io::Printer* printer);
80e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
81e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  const Params& params_;
82e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  const Descriptor* descriptor_;
83e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  FieldGeneratorMap field_generators_;
84e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
85e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville  GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator);
86e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville};
87e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
88e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville}  // namespace javamicro
89e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville}  // namespace compiler
90e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville}  // namespace protobuf
91e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville
92e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville}  // namespace google
93e2d542951c059563a3b7f74c257dac4f222d9dc5Wink Saville#endif  // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__
94