Protocol Buffers

common.h

#include <google/protobuf/stubs/common.h>
namespace google::protobuf

Contains basic types and utilities used by the rest of the library.

Classes in this file

Create a LogSilencer if you want to temporarily suppress all log messages.
Abstract interface for a callback.

File Members

These definitions are not part of any class.
enum
LogLevel
typedef
unsigned int uint
typedef
int8_t int8
typedef
int16_t int16
typedef
int32_t int32
typedef
int64_t int64
typedef
uint8_t uint8
typedef
uint16_t uint16
typedef
uint32_t uint32
typedef
uint64_t uint64
typedef
void LogHandler(LogLevel level, const char *filename, int line, const std::string &message)
const int32
kint32max = 0x7FFFFFFF
const int32
kint32min = -kint32max - 1
const int64
kint64max = 0x7FFFFFFFFFFFFFFFLL
const int64
kint64min = -kint64max - 1
const uint32
kuint32max = 0xFFFFFFFFu
const uint64
kuint64max = 0xFFFFFFFFFFFFFFFFULL
LogHandler *
SetLogHandler(LogHandler * new_func)
The protobuf library sometimes writes warning and error messages to stderr. more...
Closure *
NewCallback(void(*)() function)
See Closure.
Closure *
NewPermanentCallback(void(*)() function)
See Closure.
template Closure *
NewCallback(Class * object, void(Class::*)() method)
See Closure.
template Closure *
NewPermanentCallback(Class * object, void(Class::*)() method)
See Closure.
template Closure *
NewCallback(void(*)(Arg1) function, Arg1 arg1)
See Closure.
template Closure *
NewPermanentCallback(void(*)(Arg1) function, Arg1 arg1)
See Closure.
template Closure *
NewCallback(Class * object, void(Class::*)(Arg1) method, Arg1 arg1)
See Closure.
template Closure *
NewPermanentCallback(Class * object, void(Class::*)(Arg1) method, Arg1 arg1)
See Closure.
template Closure *
NewCallback(void(*)(Arg1, Arg2) function, Arg1 arg1, Arg2 arg2)
See Closure.
template Closure *
NewPermanentCallback(void(*)(Arg1, Arg2) function, Arg1 arg1, Arg2 arg2)
See Closure.
template Closure *
NewCallback(Class * object, void(Class::*)(Arg1, Arg2) method, Arg1 arg1, Arg2 arg2)
See Closure.
template Closure *
NewPermanentCallback(Class * object, void(Class::*)(Arg1, Arg2) method, Arg1 arg1, Arg2 arg2)
See Closure.
void
DoNothing()
A function which does nothing. more...
uint32
ghtonl(uint32 x)
=================================================================== from google3/util/endian/endian.h
void
ShutdownProtobufLibrary()
Shut down the entire protocol buffers library, deleting all static-duration objects allocated by the library or by generated .pb.cc files. more...

enum protobuf::LogLevel {
  LOGLEVEL_INFO,
  LOGLEVEL_WARNING,
  LOGLEVEL_ERROR,
  LOGLEVEL_FATAL,
  LOGLEVEL_DFATAL = LOGLEVEL_FATAL
}

LOGLEVEL_INFO

Informational.

This is never actually used by libprotobuf.

LOGLEVEL_WARNING

Warns about issues that, although not technically a problem now, could cause problems in the future.

For example, a // warning will be printed when parsing a message that is near the message size limit.

LOGLEVEL_ERRORAn error occurred which should never happen during normal use.
LOGLEVEL_FATAL

An error occurred from which the library cannot recover.

This usually indicates a programming error in the code which calls the library, especially when compiled in debug mode.

LOGLEVEL_DFATAL

LogHandler * protobuf::SetLogHandler(
        LogHandler * new_func)

The protobuf library sometimes writes warning and error messages to stderr.

These messages are primarily useful for developers, but may also help end users figure out a problem. If you would prefer that these messages be sent somewhere other than stderr, call SetLogHandler() to set your own handler. This returns the old handler. Set the handler to NULL to ignore log messages (but see also LogSilencer, below).

Obviously, SetLogHandler is not thread-safe. You should only call it at initialization time, and probably not from library code. If you simply want to suppress log messages temporarily (e.g. because you have some code that tends to trigger them frequently and you know the warnings are not important to you), use the LogSilencer class below.


void protobuf::DoNothing()

A function which does nothing.

Useful for creating no-op callbacks, e.g.:

Closure* nothing = NewCallback(&DoNothing);

void protobuf::ShutdownProtobufLibrary()

Shut down the entire protocol buffers library, deleting all static-duration objects allocated by the library or by generated .pb.cc files.

There are two reasons you might want to call this:

  • You use a draconian definition of "memory leak" in which you expect every single malloc() to have a corresponding free(), even for objects which live until program exit.
  • You are writing a dynamically-loaded library which needs to clean up after itself when the library is unloaded.

It is safe to call this multiple times. However, it is not safe to use any other part of the protocol buffers library after ShutdownProtobufLibrary() has been called.

class LogSilencer

#include <google/protobuf/stubs/common.h>
namespace google::protobuf

Create a LogSilencer if you want to temporarily suppress all log messages.

As long as any LogSilencer objects exist, non-fatal log messages will be discarded (the current LogHandler will *not* be called). Constructing a LogSilencer is thread-safe. You may accidentally suppress log messages occurring in another thread, but since messages are generally for debugging purposes only, this isn't a big deal. If you want to intercept log messages, use SetLogHandler().

Members

LogSilencer()
~LogSilencer()

class Closure

#include <google/protobuf/stubs/common.h>
namespace google::protobuf

Abstract interface for a callback.

When calling an RPC, you must provide a Closure to call when the procedure completes. See the Service interface in service.h.

To automatically construct a Closure which calls a particular function or method with a particular set of parameters, use the NewCallback() function. Example:

void FooDone(const FooResponse* response) {
  ...
}

void CallFoo() {
  ...
 When done, call FooDone() and pass it a pointer to the response.
  Closure* callback = NewCallback(&FooDone, response);
 Make the call.
  service->Foo(controller, request, response, callback);
}

Example that calls a method:

class Handler {
 public:
  ...

  void FooDone(const FooResponse* response) {
    ...
  }

  void CallFoo() {
    ...
 When done, call FooDone() and pass it a pointer to the response.
    Closure* callback = NewCallback(this, &Handler::FooDone, response);
 Make the call.
    service->Foo(controller, request, response, callback);
  }
};

Currently NewCallback() supports binding zero, one, or two arguments.

Callbacks created with NewCallback() automatically delete themselves when executed. They should be used when a callback is to be called exactly once (usually the case with RPC callbacks). If a callback may be called a different number of times (including zero), create it with NewPermanentCallback() instead. You are then responsible for deleting the callback (using the "delete" keyword as normal).

Note that NewCallback() is a bit touchy regarding argument types. Generally, the values you provide for the parameter bindings must exactly match the types accepted by the callback function. For example:

void Foo(string s);
NewCallback(&Foo, "foo");          // WON'T WORK:  const char* != string
NewCallback(&Foo, string("foo"));  // WORKS

Also note that the arguments cannot be references:

void Foo(const string& s);
string my_str;
NewCallback(&Foo, my_str);  // WON'T WORK:  Can't use referecnes.

However, correctly-typed pointers will work just fine.

Members

Closure()
virtual
~Closure()
virtual void
Run() = 0

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.