Protocol Buffers C++ API

来源:互联网 发布:淘宝发票管家在哪里 编辑:程序博客网 时间:2024/06/06 06:32

source : https://developers.google.com/protocol-buffers/docs/reference/cpp/index

C++ API

Packages

google::protobuf
Core components of the Protocol Buffers runtime library.
google::protobuf::io
Auxiliary classes used for I/O.
google::protobuf::compiler
repeated_field.h

google::protobuf

Core components of the Protocol Buffers runtime library.

The files in this package represent the core of the Protocol Buffer system. All of them are part of the libprotobuf library.

A note on thread-safety:

Thread-safety in the Protocol Buffer library follows a simple rule: unless explicitly noted otherwise, it is always safe to use an object from multiple threads simultaneously as long as the object is declared const in all threads (or, it is only used in ways that would be allowed if it were declared const). However, if an object is accessed in one thread in a way that would not be allowed if it were const, then it is not safe to access that object in any other thread simultaneously.

Put simply, read-only access to an object can happen in multiple threads simultaneously, but write access can only happen in a single thread at a time.

The implementation does contain some "const" methods which actually modify the object behind the scenes -- e.g., to cache results -- but in these cases mutex locking is used to make the access thread-safe.

Files

google/protobuf/descriptor.h
This file contains classes which describe a type of protocol message.
google/protobuf/descriptor.pb.h
Protocol buffer representations of descriptors.
google/protobuf/descriptor_database.h
Interface for manipulating databases of descriptors.
google/protobuf/dynamic_message.h
Defines an implementation ofMessage which can emulate types which are not known at compile-time.
google/protobuf/message.h
Defines Message, the abstract interface implemented by non-lite protocol message objects.
google/protobuf/message_lite.h
Defines MessageLite, the abstract interface implemented by all (lite and non-lite) protocol message objects.
google/protobuf/repeated_field.h
RepeatedField andRepeatedPtrField are used by generated protocol message classes to manipulate repeated fields.
google/protobuf/service.h
DEPRECATED: This module declares the abstract interfaces underlying proto2 RPC services.
google/protobuf/text_format.h
Utilities for printing and parsing protocol messages in a human-readable, text-based format.
google/protobuf/unknown_field_set.h
Contains classes used to keep track of unrecognized fields seen while parsing a protocol message.
google/protobuf/stubs/common.h
Contains basic types and utilities used by the rest of the library.

google::protobuf::io

Auxiliary classes used for I/O.

The Protocol Buffer library uses the classes in this package to deal with I/O and encoding/decoding raw bytes. Most users will not need to deal with this package. However, users who want to adapt the system to work with their own I/O abstractions -- e.g., to allow Protocol Buffers to be read from a different kind of input stream without the need for a temporary buffer -- should take a closer look.

Files

google/protobuf/io/coded_stream.h
This file contains theCodedInputStream and CodedOutputStream classes, which wrap a ZeroCopyInputStream or ZeroCopyOutputStream, respectively, and allow you to read or write individual pieces of data in various formats.
google/protobuf/io/gzip_stream.h
This file contains the definition for classesGzipInputStream and GzipOutputStream.
google/protobuf/io/printer.h
Utility class for writing text to aZeroCopyOutputStream.
google/protobuf/io/tokenizer.h
Class for parsing tokenized text from aZeroCopyInputStream.
google/protobuf/io/zero_copy_stream.h
This file contains theZeroCopyInputStream and ZeroCopyOutputStream interfaces, which represent abstract I/O streams to and from which protocol buffers can be read and written.
google/protobuf/io/zero_copy_stream_impl.h
This file contains common implementations of the interfaces defined inzero_copy_stream.h which are only included in the full (non-lite) protobuf library.
google/protobuf/io/zero_copy_stream_impl_lite.h
This file contains common implementations of the interfaces defined inzero_copy_stream.h which are included in the "lite" protobuf library.

google::protobuf::compiler

repeated_field.h

Implementation of the Protocol Buffer compiler.

This package contains code for parsing .proto files and generating code based on them. There are two reasons you might be interested in this package:

  • You want to parse .proto files at runtime. In this case, you should look at importer.h. Since this functionality is widely useful, it is included in the libprotobuf base library; you do not have to link against libprotoc.
  • You want to write a custom protocol compiler which generates different kinds of code, e.g. code in a different language which is not supported by the official compiler. For this purpose,command_line_interface.h provides you with a complete compiler front-end, so all you need to do is write a custom implementation ofCodeGenerator and a trivial main() function. You can even make your compiler support the official languages in addition to your own. Since this functionality is only useful to those writing custom compilers, it is in a separate library called "libprotoc" which you will have to link against.

Files

google/protobuf/compiler/code_generator.h
Defines the abstract interface implemented by each of the language-specific code generators.
google/protobuf/compiler/command_line_interface.h
Implements the Protocol Compiler front-end such that it may be reused by custom compilers written to support other languages.
google/protobuf/compiler/importer.h
This file is the public interface to the .proto file parser.
google/protobuf/compiler/parser.h
Implements parsing of .proto files to FileDescriptorProtos.
google/protobuf/compiler/plugin.h
Front-end for protoc code generator plugins written in C++.
google/protobuf/compiler/plugin.pb.h
API for protoc plugins.
google/protobuf/compiler/cpp/cpp_generator.h
Generates C++ code for a given .proto file.
google/protobuf/compiler/java/java_generator.h
Generates Java code for a given .proto file.
google/protobuf/compiler/python/python_generator.h
Generates Python code for a given .proto file. 

原创粉丝点击