commit
eebb129fd3
339 changed files with 24629 additions and 13855 deletions
@ -1,49 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/ext/client_config/subchannel_factory.h" |
||||
|
||||
void grpc_subchannel_factory_ref(grpc_subchannel_factory* factory) { |
||||
factory->vtable->ref(factory); |
||||
} |
||||
|
||||
void grpc_subchannel_factory_unref(grpc_exec_ctx* exec_ctx, |
||||
grpc_subchannel_factory* factory) { |
||||
factory->vtable->unref(exec_ctx, factory); |
||||
} |
||||
|
||||
grpc_subchannel* grpc_subchannel_factory_create_subchannel( |
||||
grpc_exec_ctx* exec_ctx, grpc_subchannel_factory* factory, |
||||
grpc_subchannel_args* args) { |
||||
return factory->vtable->create_subchannel(exec_ctx, factory, args); |
||||
} |
@ -1,66 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_FACTORY_H |
||||
#define GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_FACTORY_H |
||||
|
||||
#include "src/core/ext/client_config/subchannel.h" |
||||
#include "src/core/lib/channel/channel_stack.h" |
||||
|
||||
typedef struct grpc_subchannel_factory grpc_subchannel_factory; |
||||
typedef struct grpc_subchannel_factory_vtable grpc_subchannel_factory_vtable; |
||||
|
||||
/** Constructor for new configured channels.
|
||||
Creating decorators around this type is encouraged to adapt behavior. */ |
||||
struct grpc_subchannel_factory { |
||||
const grpc_subchannel_factory_vtable *vtable; |
||||
}; |
||||
|
||||
struct grpc_subchannel_factory_vtable { |
||||
void (*ref)(grpc_subchannel_factory *factory); |
||||
void (*unref)(grpc_exec_ctx *exec_ctx, grpc_subchannel_factory *factory); |
||||
grpc_subchannel *(*create_subchannel)(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_factory *factory, |
||||
grpc_subchannel_args *args); |
||||
}; |
||||
|
||||
void grpc_subchannel_factory_ref(grpc_subchannel_factory *factory); |
||||
void grpc_subchannel_factory_unref(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_factory *factory); |
||||
|
||||
/** Create a new grpc_subchannel */ |
||||
grpc_subchannel *grpc_subchannel_factory_create_subchannel( |
||||
grpc_exec_ctx *exec_ctx, grpc_subchannel_factory *factory, |
||||
grpc_subchannel_args *args); |
||||
|
||||
#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_FACTORY_H */ |
@ -0,0 +1,302 @@ |
||||
//
|
||||
// Copyright 2016, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#include "src/core/lib/channel/deadline_filter.h" |
||||
|
||||
#include <stdbool.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/sync.h> |
||||
#include <grpc/support/time.h> |
||||
|
||||
#include "src/core/lib/iomgr/exec_ctx.h" |
||||
#include "src/core/lib/iomgr/timer.h" |
||||
|
||||
//
|
||||
// grpc_deadline_state
|
||||
//
|
||||
|
||||
// Timer callback.
|
||||
static void timer_callback(grpc_exec_ctx* exec_ctx, void* arg, |
||||
grpc_error* error) { |
||||
grpc_call_element* elem = arg; |
||||
grpc_deadline_state* deadline_state = elem->call_data; |
||||
gpr_mu_lock(&deadline_state->timer_mu); |
||||
deadline_state->timer_pending = false; |
||||
gpr_mu_unlock(&deadline_state->timer_mu); |
||||
if (error != GRPC_ERROR_CANCELLED) { |
||||
gpr_slice msg = gpr_slice_from_static_string("Deadline Exceeded"); |
||||
grpc_call_element_send_cancel_with_message( |
||||
exec_ctx, elem, GRPC_STATUS_DEADLINE_EXCEEDED, &msg); |
||||
gpr_slice_unref(msg); |
||||
} |
||||
GRPC_CALL_STACK_UNREF(exec_ctx, deadline_state->call_stack, "deadline_timer"); |
||||
} |
||||
|
||||
// Starts the deadline timer.
|
||||
static void start_timer_if_needed(grpc_exec_ctx* exec_ctx, |
||||
grpc_call_element* elem, |
||||
gpr_timespec deadline) { |
||||
grpc_deadline_state* deadline_state = elem->call_data; |
||||
deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC); |
||||
if (gpr_time_cmp(deadline, gpr_inf_future(GPR_CLOCK_MONOTONIC)) != 0) { |
||||
// Take a reference to the call stack, to be owned by the timer.
|
||||
GRPC_CALL_STACK_REF(deadline_state->call_stack, "deadline_timer"); |
||||
gpr_mu_lock(&deadline_state->timer_mu); |
||||
deadline_state->timer_pending = true; |
||||
grpc_timer_init(exec_ctx, &deadline_state->timer, deadline, timer_callback, |
||||
elem, gpr_now(GPR_CLOCK_MONOTONIC)); |
||||
gpr_mu_unlock(&deadline_state->timer_mu); |
||||
} |
||||
} |
||||
|
||||
// Cancels the deadline timer.
|
||||
static void cancel_timer_if_needed(grpc_exec_ctx* exec_ctx, |
||||
grpc_deadline_state* deadline_state) { |
||||
gpr_mu_lock(&deadline_state->timer_mu); |
||||
if (deadline_state->timer_pending) { |
||||
grpc_timer_cancel(exec_ctx, &deadline_state->timer); |
||||
deadline_state->timer_pending = false; |
||||
} |
||||
gpr_mu_unlock(&deadline_state->timer_mu); |
||||
} |
||||
|
||||
// Callback run when the call is complete.
|
||||
static void on_complete(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { |
||||
grpc_deadline_state* deadline_state = arg; |
||||
cancel_timer_if_needed(exec_ctx, deadline_state); |
||||
// Invoke the next callback.
|
||||
deadline_state->next_on_complete->cb( |
||||
exec_ctx, deadline_state->next_on_complete->cb_arg, error); |
||||
} |
||||
|
||||
// Inject our own on_complete callback into op.
|
||||
static void inject_on_complete_cb(grpc_deadline_state* deadline_state, |
||||
grpc_transport_stream_op* op) { |
||||
deadline_state->next_on_complete = op->on_complete; |
||||
grpc_closure_init(&deadline_state->on_complete, on_complete, deadline_state); |
||||
op->on_complete = &deadline_state->on_complete; |
||||
} |
||||
|
||||
// Callback and associated state for starting the timer after call stack
|
||||
// initialization has been completed.
|
||||
struct start_timer_after_init_state { |
||||
grpc_call_element* elem; |
||||
gpr_timespec deadline; |
||||
grpc_closure closure; |
||||
}; |
||||
static void start_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg, |
||||
grpc_error* error) { |
||||
struct start_timer_after_init_state* state = arg; |
||||
start_timer_if_needed(exec_ctx, state->elem, state->deadline); |
||||
gpr_free(state); |
||||
} |
||||
|
||||
void grpc_deadline_state_init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, |
||||
grpc_call_element_args* args) { |
||||
grpc_deadline_state* deadline_state = elem->call_data; |
||||
memset(deadline_state, 0, sizeof(*deadline_state)); |
||||
deadline_state->call_stack = args->call_stack; |
||||
gpr_mu_init(&deadline_state->timer_mu); |
||||
// Deadline will always be infinite on servers, so the timer will only be
|
||||
// set on clients with a finite deadline.
|
||||
const gpr_timespec deadline = |
||||
gpr_convert_clock_type(args->deadline, GPR_CLOCK_MONOTONIC); |
||||
if (gpr_time_cmp(deadline, gpr_inf_future(GPR_CLOCK_MONOTONIC)) != 0) { |
||||
// When the deadline passes, we indicate the failure by sending down
|
||||
// an op with cancel_error set. However, we can't send down any ops
|
||||
// until after the call stack is fully initialized. If we start the
|
||||
// timer here, we have no guarantee that the timer won't pop before
|
||||
// call stack initialization is finished. To avoid that problem, we
|
||||
// create a closure to start the timer, and we schedule that closure
|
||||
// to be run after call stack initialization is done.
|
||||
struct start_timer_after_init_state* state = gpr_malloc(sizeof(*state)); |
||||
state->elem = elem; |
||||
state->deadline = deadline; |
||||
grpc_closure_init(&state->closure, start_timer_after_init, state); |
||||
grpc_exec_ctx_sched(exec_ctx, &state->closure, GRPC_ERROR_NONE, NULL); |
||||
} |
||||
} |
||||
|
||||
void grpc_deadline_state_destroy(grpc_exec_ctx* exec_ctx, |
||||
grpc_call_element* elem) { |
||||
grpc_deadline_state* deadline_state = elem->call_data; |
||||
cancel_timer_if_needed(exec_ctx, deadline_state); |
||||
gpr_mu_destroy(&deadline_state->timer_mu); |
||||
} |
||||
|
||||
void grpc_deadline_state_client_start_transport_stream_op( |
||||
grpc_exec_ctx* exec_ctx, grpc_call_element* elem, |
||||
grpc_transport_stream_op* op) { |
||||
grpc_deadline_state* deadline_state = elem->call_data; |
||||
if (op->cancel_error != GRPC_ERROR_NONE || |
||||
op->close_error != GRPC_ERROR_NONE) { |
||||
cancel_timer_if_needed(exec_ctx, deadline_state); |
||||
} else { |
||||
// Make sure we know when the call is complete, so that we can cancel
|
||||
// the timer.
|
||||
if (op->recv_trailing_metadata != NULL) { |
||||
inject_on_complete_cb(deadline_state, op); |
||||
} |
||||
} |
||||
} |
||||
|
||||
//
|
||||
// filter code
|
||||
//
|
||||
|
||||
// Constructor for channel_data. Used for both client and server filters.
|
||||
static void init_channel_elem(grpc_exec_ctx* exec_ctx, |
||||
grpc_channel_element* elem, |
||||
grpc_channel_element_args* args) { |
||||
GPR_ASSERT(!args->is_last); |
||||
} |
||||
|
||||
// Destructor for channel_data. Used for both client and server filters.
|
||||
static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, |
||||
grpc_channel_element* elem) {} |
||||
|
||||
// Call data used for both client and server filter.
|
||||
typedef struct base_call_data { |
||||
grpc_deadline_state deadline_state; |
||||
} base_call_data; |
||||
|
||||
// Additional call data used only for the server filter.
|
||||
typedef struct server_call_data { |
||||
base_call_data base; // Must be first.
|
||||
// The closure for receiving initial metadata.
|
||||
grpc_closure recv_initial_metadata_ready; |
||||
// Received initial metadata batch.
|
||||
grpc_metadata_batch* recv_initial_metadata; |
||||
// The original recv_initial_metadata_ready closure, which we chain to
|
||||
// after our own closure is invoked.
|
||||
grpc_closure* next_recv_initial_metadata_ready; |
||||
} server_call_data; |
||||
|
||||
// Constructor for call_data. Used for both client and server filters.
|
||||
static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, |
||||
grpc_call_element* elem, |
||||
grpc_call_element_args* args) { |
||||
// Note: size of call data is different between client and server.
|
||||
memset(elem->call_data, 0, elem->filter->sizeof_call_data); |
||||
grpc_deadline_state_init(exec_ctx, elem, args); |
||||
return GRPC_ERROR_NONE; |
||||
} |
||||
|
||||
// Destructor for call_data. Used for both client and server filters.
|
||||
static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, |
||||
const grpc_call_final_info* final_info, |
||||
void* and_free_memory) { |
||||
grpc_deadline_state_destroy(exec_ctx, elem); |
||||
} |
||||
|
||||
// Method for starting a call op for client filter.
|
||||
static void client_start_transport_stream_op(grpc_exec_ctx* exec_ctx, |
||||
grpc_call_element* elem, |
||||
grpc_transport_stream_op* op) { |
||||
grpc_deadline_state_client_start_transport_stream_op(exec_ctx, elem, op); |
||||
// Chain to next filter.
|
||||
grpc_call_next_op(exec_ctx, elem, op); |
||||
} |
||||
|
||||
// Callback for receiving initial metadata on the server.
|
||||
static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, void* arg, |
||||
grpc_error* error) { |
||||
grpc_call_element* elem = arg; |
||||
server_call_data* calld = elem->call_data; |
||||
// Get deadline from metadata and start the timer if needed.
|
||||
start_timer_if_needed(exec_ctx, elem, calld->recv_initial_metadata->deadline); |
||||
// Invoke the next callback.
|
||||
calld->next_recv_initial_metadata_ready->cb( |
||||
exec_ctx, calld->next_recv_initial_metadata_ready->cb_arg, error); |
||||
} |
||||
|
||||
// Method for starting a call op for server filter.
|
||||
static void server_start_transport_stream_op(grpc_exec_ctx* exec_ctx, |
||||
grpc_call_element* elem, |
||||
grpc_transport_stream_op* op) { |
||||
server_call_data* calld = elem->call_data; |
||||
if (op->cancel_error != GRPC_ERROR_NONE || |
||||
op->close_error != GRPC_ERROR_NONE) { |
||||
cancel_timer_if_needed(exec_ctx, &calld->base.deadline_state); |
||||
} else { |
||||
// If we're receiving initial metadata, we need to get the deadline
|
||||
// from the recv_initial_metadata_ready callback. So we inject our
|
||||
// own callback into that hook.
|
||||
if (op->recv_initial_metadata_ready != NULL) { |
||||
calld->next_recv_initial_metadata_ready = op->recv_initial_metadata_ready; |
||||
calld->recv_initial_metadata = op->recv_initial_metadata; |
||||
grpc_closure_init(&calld->recv_initial_metadata_ready, |
||||
recv_initial_metadata_ready, elem); |
||||
op->recv_initial_metadata_ready = &calld->recv_initial_metadata_ready; |
||||
} |
||||
// Make sure we know when the call is complete, so that we can cancel
|
||||
// the timer.
|
||||
// Note that we trigger this on recv_trailing_metadata, even though
|
||||
// the client never sends trailing metadata, because this is the
|
||||
// hook that tells us when the call is complete on the server side.
|
||||
if (op->recv_trailing_metadata != NULL) { |
||||
inject_on_complete_cb(&calld->base.deadline_state, op); |
||||
} |
||||
} |
||||
// Chain to next filter.
|
||||
grpc_call_next_op(exec_ctx, elem, op); |
||||
} |
||||
|
||||
const grpc_channel_filter grpc_client_deadline_filter = { |
||||
client_start_transport_stream_op, |
||||
grpc_channel_next_op, |
||||
sizeof(base_call_data), |
||||
init_call_elem, |
||||
grpc_call_stack_ignore_set_pollset_or_pollset_set, |
||||
destroy_call_elem, |
||||
0, // sizeof(channel_data)
|
||||
init_channel_elem, |
||||
destroy_channel_elem, |
||||
grpc_call_next_get_peer, |
||||
"deadline", |
||||
}; |
||||
|
||||
const grpc_channel_filter grpc_server_deadline_filter = { |
||||
server_start_transport_stream_op, |
||||
grpc_channel_next_op, |
||||
sizeof(server_call_data), |
||||
init_call_elem, |
||||
grpc_call_stack_ignore_set_pollset_or_pollset_set, |
||||
destroy_call_elem, |
||||
0, // sizeof(channel_data)
|
||||
init_channel_elem, |
||||
destroy_channel_elem, |
||||
grpc_call_next_get_peer, |
||||
"deadline", |
||||
}; |
@ -0,0 +1,79 @@ |
||||
//
|
||||
// Copyright 2016, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef GRPC_CORE_LIB_CHANNEL_DEADLINE_FILTER_H |
||||
#define GRPC_CORE_LIB_CHANNEL_DEADLINE_FILTER_H |
||||
|
||||
#include "src/core/lib/channel/channel_stack.h" |
||||
#include "src/core/lib/iomgr/timer.h" |
||||
|
||||
// State used for filters that enforce call deadlines.
|
||||
// Must be the first field in the filter's call_data.
|
||||
typedef struct grpc_deadline_state { |
||||
// We take a reference to the call stack for the timer callback.
|
||||
grpc_call_stack* call_stack; |
||||
// Guards access to timer_pending and timer.
|
||||
gpr_mu timer_mu; |
||||
// True if the timer callback is currently pending.
|
||||
bool timer_pending; |
||||
// The deadline timer.
|
||||
grpc_timer timer; |
||||
// Closure to invoke when the call is complete.
|
||||
// We use this to cancel the timer.
|
||||
grpc_closure on_complete; |
||||
// The original on_complete closure, which we chain to after our own
|
||||
// closure is invoked.
|
||||
grpc_closure* next_on_complete; |
||||
} grpc_deadline_state; |
||||
|
||||
// To be used in a filter's init_call_elem(), destroy_call_elem(), and
|
||||
// start_transport_stream_op() methods to enforce call deadlines.
|
||||
//
|
||||
// REQUIRES: The first field in elem->call_data is a grpc_deadline_state.
|
||||
//
|
||||
// For grpc_deadline_state_client_start_transport_stream_op(), it is the
|
||||
// caller's responsibility to chain to the next filter if necessary
|
||||
// after the function returns.
|
||||
void grpc_deadline_state_init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, |
||||
grpc_call_element_args* args); |
||||
void grpc_deadline_state_destroy(grpc_exec_ctx* exec_ctx, |
||||
grpc_call_element* elem); |
||||
void grpc_deadline_state_client_start_transport_stream_op( |
||||
grpc_exec_ctx* exec_ctx, grpc_call_element* elem, |
||||
grpc_transport_stream_op* op); |
||||
|
||||
// Deadline filters for direct client channels and server channels.
|
||||
// Note: Deadlines for non-direct client channels are handled by the
|
||||
// client_channel filter.
|
||||
extern const grpc_channel_filter grpc_client_deadline_filter; |
||||
extern const grpc_channel_filter grpc_server_deadline_filter; |
||||
|
||||
#endif /* GRPC_CORE_LIB_CHANNEL_DEADLINE_FILTER_H */ |
@ -0,0 +1,28 @@ |
||||
*.gcda |
||||
*.gcno |
||||
*.gcov |
||||
*.o |
||||
*.pb.c |
||||
*.pb.h |
||||
*.pb |
||||
*.pyc |
||||
*_pb2.py |
||||
*~ |
||||
*.tar.gz |
||||
.sconsign.dblite |
||||
config.log |
||||
.sconf_temp |
||||
tests/build |
||||
julkaisu.txt |
||||
dist |
||||
docs/*.html |
||||
docs/generator_flow.png |
||||
examples/simple/simple |
||||
examples/network_server/client |
||||
examples/network_server/server |
||||
examples/using_double_on_avr/decode_double |
||||
examples/using_double_on_avr/encode_double |
||||
examples/using_double_on_avr/test_conversions |
||||
examples/using_union_messages/decode |
||||
examples/using_union_messages/encode |
||||
generator/nanopb_pb2.pyc |
@ -0,0 +1,54 @@ |
||||
# Travis CI has no ability to handle 3 langauges (c, c++, python) |
||||
# and it overrides $CC/$CXX if language is set to c/c++ (only one, not both). |
||||
# |
||||
# Set language to python since at least the result of that is something useful. |
||||
language: python |
||||
|
||||
python: |
||||
- "2.7" |
||||
- "3.4" |
||||
|
||||
# Manage the C/C++ compiler manually |
||||
env: |
||||
- CC=gcc CXX=g++ |
||||
- CC=gcc-4.8 CXX=g++-4.8 |
||||
- CC=gcc-4.9 CXX=g++-4.9 |
||||
- CC=gcc-5 CXX=g++-5 |
||||
- CC=clang CXX=clang++ |
||||
|
||||
addons: |
||||
apt: |
||||
sources: |
||||
- ubuntu-toolchain-r-test |
||||
packages: |
||||
- gcc-4.8 |
||||
- g++-4.8 |
||||
- gcc-4.9 |
||||
- g++-4.9 |
||||
- gcc-5 |
||||
- g++-5 |
||||
|
||||
|
||||
before_install: |
||||
- export PATH=$HOME/.local/bin:$HOME/protobuf/bin:$PATH |
||||
- export MAKEFLAGS=-j$(grep processor /proc/cpuinfo | wc -l) |
||||
- $CC --version |
||||
- $CXX --version |
||||
- python --version |
||||
- lsb_release -a |
||||
|
||||
# Seems to be issues with concurrent builds |
||||
#cache: |
||||
# directories: |
||||
# - $HOME/protobuf |
||||
|
||||
install: |
||||
- curl -L https://github.com/google/protobuf/releases/download/v3.0.0-beta-1/protobuf-python-3.0.0-alpha-4.tar.gz | tar xzf - |
||||
&& pushd protobuf-3.0.0-alpha-4 |
||||
&& ./configure --prefix=$HOME/protobuf && make && make install |
||||
&& pushd python && python setup.py build && python setup.py install && popd |
||||
&& popd |
||||
|
||||
script: |
||||
- pushd generator/proto && make && popd |
||||
- pushd tests && python2 $(which scons) CC=$CC CXX=$CXX && popd |
@ -0,0 +1,24 @@ |
||||
Petteri Aimonen <jpa@npb.mail.kapsi.fi> |
||||
Michael Poole <mdpoole@troilus.org> |
||||
Daniel Kan <extremeblue99@gmail.com> |
||||
Stan Hu <stanhu@aclimalabs.com> |
||||
dch <david.hotham@blueyonder.co.uk> |
||||
Steffen Siering <steffen siering gmail com> |
||||
Jens Steinhauser <jens.steinhauser@gmail.com> |
||||
Pavel Ilin <ilin.pa@gmail.com> |
||||
Kent Ryhorchuk <kryhorchuk@xeralux.com> |
||||
Martin Donath <scifish@gmail.com> |
||||
Oliver Lee <oliverzlee@gmail.com> |
||||
Michael Haberler <git@mah.priv.at> |
||||
Nicolas Colomer <ncolomer@viadeoteam.com> |
||||
Ivan Kravets <me@ikravets.com> |
||||
Kyle Manna <kyle@kylemanna.com> |
||||
Benjamin Kamath <ben.kamath@synapse.com> |
||||
Andrew Ruder <andrew.ruder@elecsyscorp.com> |
||||
Kenshi Kawaguchi <kenshi@recurse.ca> |
||||
isotes <isotes@gmail.com> |
||||
Maxim Khitrov <max@mxcrypt.com> |
||||
Yaniv Mordekhay <yanivmo@users.noreply.github.com> |
||||
Ming Zhao <mzhao@luminatewireless.com> |
||||
Google, Inc. |
||||
Tom Roeder <tmroeder@google.com> |
@ -0,0 +1,18 @@ |
||||
licenses(["notice"]) |
||||
package(default_visibility = ["//visibility:public"]) |
||||
|
||||
cc_library( |
||||
name = "nanopb", |
||||
visibility = ["//visibility:public"], |
||||
hdrs = [ |
||||
"pb.h", |
||||
"pb_common.h", |
||||
"pb_decode.h", |
||||
"pb_encode.h", |
||||
], |
||||
srcs = [ |
||||
"pb_common.c", |
||||
"pb_decode.c", |
||||
"pb_encode.c", |
||||
], |
||||
) |
@ -0,0 +1,241 @@ |
||||
nanopb-0.3.6 (2016-06-19) |
||||
Protect against corrupted _count fields in pb_release (#205) |
||||
Fix error in STATIC_ASSERT with multiple files (#203) |
||||
Add -D option to specify output directory (#193) |
||||
Generate MIN/MAX/ARRAYSIZE defines for enums (#194) |
||||
Generate comments about uncalculable message sizes (#195) |
||||
Documentation updates (#196, #201) |
||||
Improvements to test cases. |
||||
|
||||
nanopb-0.3.5 (2016-02-13) |
||||
NOTE: If you are using pb_syshdr.h, you will need to add uint_least8_t |
||||
definition. See docs/migration.rst for details. |
||||
|
||||
Fix generator crash with Enum inside Oneof (#188) |
||||
Fix some generator regressions related to .options file path (#172) |
||||
Add support for platforms without uint8_t (#191) |
||||
Allow const parameter to pb_istream_from_buffer (#152) |
||||
Ignore null pointers in pb_release() (#183) |
||||
Add support for anonymous unions (#184) |
||||
Add Python3 support to the generator (#169) |
||||
Add code generator insertion points to generated files (#178) |
||||
Improvements to CMake script (#181) |
||||
Improvements to test cases. |
||||
|
||||
nanopb-0.3.4 (2015-09-26) |
||||
Fix handling of unsigned 8- and 16-bit enums (issue 164) |
||||
Fix generator on systems where python = python3. (issue 155) |
||||
Fix compiler warning on GCC 5.x (issue 171) |
||||
Make the generator better handle imported .protos (issue 165) |
||||
Add packed_enum option to generator. |
||||
Add syntax= line to .proto files (issue 167) |
||||
Add PlatformIO registry manifest file. (pr 156) |
||||
|
||||
nanopb-0.3.3 (2015-04-10) |
||||
Fix missing files in Linux binary package (issue 146) |
||||
Fix generator bug when oneof is first field in a message. (issue 142) |
||||
Fix generator error when long_names:false is combined with Oneofs. (issue 147) |
||||
Fix oneof submessage initialization bug. (issue 149) |
||||
Fix problem with plugin options on Python 2.7.2 and older. (issue 153) |
||||
Fix crash when callback is inside oneof field. (issue 148) |
||||
Switch to .tar.gz format for Mac OS X packages. (issue 154) |
||||
Always define enum long names so that cross-file references work. (issue 118) |
||||
Add msgid generator option. (issue 151) |
||||
Improve comment support in .options files. (issue 145) |
||||
Updates for the CMake rule file, add cmake example. |
||||
Better error messages for syntax errors in .options file |
||||
|
||||
nanopb-0.3.2 (2015-01-24) |
||||
Fix memory leaks with PB_ENABLE_MALLOC with some submessage hierarchies (issue 138) |
||||
Implement support for oneofs (C unions). (issues 131, 141) |
||||
Add int_size option for generator (issue 139) |
||||
Add compilation option to disable struct packing. (issue 136) |
||||
Change PB_RETURN_ERROR() macro to avoid compiler warnings (issue 140) |
||||
Fix build problems with protoc 3.0.0 |
||||
Add support for POINTER type in extensions |
||||
Initialize also extension fields to defaults in pb_decode(). |
||||
Detect too large varint values when decoding. |
||||
|
||||
nanopb-0.3.1 (2014-09-11) |
||||
Fix security issue due to size_t overflows. (issue 132) |
||||
Fix memory leak with duplicated fields and PB_ENABLE_MALLOC |
||||
Fix crash if pb_release() is called twice. |
||||
Fix cyclic message support (issue 130) |
||||
Fix error in generated initializers for repeated pointer fields. |
||||
Improve tests (issues 113, 126) |
||||
|
||||
nanopb-0.3.0 (2014-08-26) |
||||
NOTE: See docs/migration.html or online at |
||||
http://koti.kapsi.fi/~jpa/nanopb/docs/migration.html |
||||
for changes in this version. Most importantly, you need to add |
||||
pb_common.c to the list of files to compile. |
||||
|
||||
Separated field iterator logic to pb_common.c (issue 128) |
||||
Change the _count fields to use pb_size_t datatype (issue 82) |
||||
Added PB_ prefix to macro names (issue 106) |
||||
Added #if version guard to generated files (issue 129) |
||||
Added migration document |
||||
|
||||
nanopb-0.2.9 (2014-08-09) |
||||
NOTE: If you are using the -e option with the generator, you have |
||||
to prepend . to the argument to get the same behaviour as before. |
||||
|
||||
Do not automatically add a dot with generator -e option. (issue 122) |
||||
Fix problem with .options file and extension fields. (issue 125) |
||||
Don't use SIZE_MAX macro, as it is not in C89. (issue 120) |
||||
Generate #defines for initializing message structures. (issue 79) |
||||
Add skip_message option to generator. (issue 121) |
||||
Add PB_PACKED_STRUCT support for Keil MDK-ARM toolchain (issue 119) |
||||
Give better messages about the .options file path. (issue 124) |
||||
Improved tests |
||||
|
||||
nanopb-0.2.8 (2014-05-20) |
||||
Fix security issue with PB_ENABLE_MALLOC. (issue 117) |
||||
Add option to not add timestamps to .pb.h and .pb.c preambles. (issue 115) |
||||
Documentation updates |
||||
Improved tests |
||||
|
||||
nanopb-0.2.7 (2014-04-07) |
||||
Fix bug with default values for extension fields (issue 111) |
||||
Fix some MISRA-C warnings (issue 91) |
||||
Implemented optional malloc() support (issue 80) |
||||
Changed pointer-type bytes field datatype |
||||
Add a "found" field to pb_extension_t (issue 112) |
||||
Add convenience function pb_get_encoded_size() (issue 16) |
||||
|
||||
nanopb-0.2.6 (2014-02-15) |
||||
Fix generator error with bytes callback fields (issue 99) |
||||
Fix warnings about large integer constants (issue 102) |
||||
Add comments to where STATIC_ASSERT is used (issue 96) |
||||
Add warning about unknown field names on .options (issue 105) |
||||
Move descriptor.proto to google/protobuf subdirectory (issue 104) |
||||
Improved tests |
||||
|
||||
nanopb-0.2.5 (2014-01-01) |
||||
Fix a bug with encoding negative values in int32 fields (issue 97) |
||||
Create binary packages of the generator + dependencies (issue 47) |
||||
Add support for pointer-type fields to the encoder (part of issue 80) |
||||
Fixed path in FindNanopb.cmake (issue 94) |
||||
Improved tests |
||||
|
||||
nanopb-0.2.4 (2013-11-07) |
||||
Remove the deprecated NANOPB_INTERNALS functions from public API. |
||||
Document the security model. |
||||
Check array and bytes max sizes when encoding (issue 90) |
||||
Add #defines for maximum encoded message size (issue 89) |
||||
Add #define tags for extension fields (issue 93) |
||||
Fix MISRA C violations (issue 91) |
||||
Clean up pb_field_t definition with typedefs. |
||||
|
||||
nanopb-0.2.3 (2013-09-18) |
||||
Improve compatibility by removing ternary operator from initializations (issue 88) |
||||
Fix build error on Visual C++ (issue 84, patch by Markus Schwarzenberg) |
||||
Don't stop on unsupported extension fields (issue 83) |
||||
Add an example pb_syshdr.h file for non-C99 compilers |
||||
Reorganize tests and examples into subfolders (issue 63) |
||||
Switch from Makefiles to scons for building the tests |
||||
Make the tests buildable on Windows |
||||
|
||||
nanopb-0.2.2 (2013-08-18) |
||||
Add support for extension fields (issue 17) |
||||
Fix unknown fields in empty message (issue 78) |
||||
Include the field tags in the generated .pb.h file. |
||||
Add pb_decode_delimited and pb_encode_delimited wrapper functions (issue 74) |
||||
Add a section in top of pb.h for changing compilation settings (issue 76) |
||||
Documentation improvements (issues 12, 77 and others) |
||||
Improved tests |
||||
|
||||
nanopb-0.2.1 (2013-04-14) |
||||
NOTE: The default callback function signature has changed. |
||||
If you don't want to update your code, define PB_OLD_CALLBACK_STYLE. |
||||
|
||||
Change the callback function to use void** (issue 69) |
||||
Add support for defining the nanopb options in a separate file (issue 12) |
||||
Add support for packed structs in IAR and MSVC (in addition to GCC) (issue 66) |
||||
Implement error message support for the encoder side (issue 7) |
||||
Handle unterminated strings when encoding (issue 68) |
||||
Fix bug with empty strings in repeated string callbacks (issue 73) |
||||
Fix regression in 0.2.0 with optional callback fields (issue 70) |
||||
Fix bugs with empty message types (issues 64, 65) |
||||
Fix some compiler warnings on clang (issue 67) |
||||
Some portability improvements (issues 60, 62) |
||||
Various new generator options |
||||
Improved tests |
||||
|
||||
nanopb-0.2.0 (2013-03-02) |
||||
NOTE: This release requires you to regenerate all .pb.c |
||||
files. Files generated by older versions will not |
||||
compile anymore. |
||||
|
||||
Reformat generated .pb.c files using macros (issue 58) |
||||
Rename PB_HTYPE_ARRAY -> PB_HTYPE_REPEATED |
||||
Separate PB_HTYPE to PB_ATYPE and PB_HTYPE |
||||
Move STATIC_ASSERTs to .pb.c file |
||||
Added CMake file (by Pavel Ilin) |
||||
Add option to give file extension to generator (by Michael Haberler) |
||||
Documentation updates |
||||
|
||||
nanopb-0.1.9 (2013-02-13) |
||||
Fixed error message bugs (issues 52, 56) |
||||
Sanitize #ifndef filename (issue 50) |
||||
Performance improvements |
||||
Add compile-time option PB_BUFFER_ONLY |
||||
Add Java package name to nanopb.proto |
||||
Check for sizeof(double) == 8 (issue 54) |
||||
Added generator option to ignore some fields. (issue 51) |
||||
Added generator option to make message structs packed. (issue 49) |
||||
Add more test cases. |
||||
|
||||
nanopb-0.1.8 (2012-12-13) |
||||
Fix bugs in the enum short names introduced in 0.1.7 (issues 42, 43) |
||||
Fix STATIC_ASSERT macro when using multiple .proto files. (issue 41) |
||||
Fix missing initialization of istream.errmsg |
||||
Make tests/Makefile work for non-gcc compilers (issue 40) |
||||
|
||||
nanopb-0.1.7 (2012-11-11) |
||||
Remove "skip" mode from pb_istream_t callbacks. Example implementation had a bug. (issue 37) |
||||
Add option to use shorter names for enum values (issue 38) |
||||
Improve options support in generator (issues 12, 30) |
||||
Add nanopb version number to generated files (issue 36) |
||||
Add extern "C" to generated headers (issue 35) |
||||
Add names for structs to allow forward declaration (issue 39) |
||||
Add buffer size check in example (issue 34) |
||||
Fix build warnings on MS compilers (issue 33) |
||||
|
||||
nanopb-0.1.6 (2012-09-02) |
||||
Reorganize the field decoder interface (issue 2) |
||||
Improve performance in submessage decoding (issue 28) |
||||
Implement error messages in the decoder side (issue 7) |
||||
Extended testcases (alltypes test is now complete). |
||||
Fix some compiler warnings (issues 25, 26, 27, 32). |
||||
|
||||
nanopb-0.1.5 (2012-08-04) |
||||
Fix bug in decoder with packed arrays (issue 23). |
||||
Extended testcases. |
||||
Fix some compiler warnings. |
||||
|
||||
nanopb-0.1.4 (2012-07-05) |
||||
Add compile-time options for easy-to-use >255 field support. |
||||
Improve the detection of missing required fields. |
||||
Added example on how to handle union messages. |
||||
Fix generator error with .proto without messages. |
||||
Fix problems that stopped the code from compiling with some compilers. |
||||
Fix some compiler warnings. |
||||
|
||||
nanopb-0.1.3 (2012-06-12) |
||||
Refactor the field encoder interface. |
||||
Improve generator error messages (issue 5) |
||||
Add descriptor.proto into the #include exclusion list |
||||
Fix some compiler warnings. |
||||
|
||||
nanopb-0.1.2 (2012-02-15) |
||||
Make the generator to generate include for other .proto files (issue 4). |
||||
Fixed generator not working on Windows (issue 3) |
||||
|
||||
nanopb-0.1.1 (2012-01-14) |
||||
Fixed bug in encoder with 'bytes' fields (issue 1). |
||||
Fixed a bug in the generator that caused a compiler error on sfixed32 and sfixed64 fields. |
||||
Extended testcases. |
||||
|
||||
nanopb-0.1.0 (2012-01-06) |
||||
First stable release. |
@ -0,0 +1,32 @@ |
||||
Contributing to Nanopb development |
||||
================================== |
||||
|
||||
Reporting issues and requesting features |
||||
---------------------------------------- |
||||
|
||||
Feel free to report any issues you see or features you would like |
||||
to see in the future to the Github issue tracker. Using the templates |
||||
below is preferred: |
||||
|
||||
* [Report a bug](https://github.com/nanopb/nanopb/issues/new?body=**Steps%20to%20reproduce%20the%20issue**%0a%0a1.%0a2.%0a3.%0a%0a**What%20happens?**%0A%0A**What%20should%20happen?**&labels=Type-Defect) |
||||
* [Request a feature](https://github.com/nanopb/nanopb/issues/new?body=**What%20should%20the%20feature%20do?**%0A%0A**In%20what%20situation%20would%20the%20feature%20be%20useful?**&labels=Type-Enhancement) |
||||
|
||||
Requesting help |
||||
--------------- |
||||
|
||||
If there is something strange going on, but you do not know if |
||||
it is actually a bug in nanopb, try asking first on the |
||||
[discussion forum](https://groups.google.com/forum/#!forum/nanopb). |
||||
|
||||
Pull requests |
||||
------------- |
||||
|
||||
Pull requests are welcome! |
||||
|
||||
If it is not obvious from the commit message, please indicate the |
||||
same information as you would for an issue report: |
||||
|
||||
* What functionality it fixes/adds. |
||||
* How can the problem be reproduced / when would the feature be useful. |
||||
|
||||
|
@ -0,0 +1,20 @@ |
||||
Copyright (c) 2011 Petteri Aimonen <jpa at nanopb.mail.kapsi.fi> |
||||
|
||||
This software is provided 'as-is', without any express or |
||||
implied warranty. In no event will the authors be held liable |
||||
for any damages arising from the use of this software. |
||||
|
||||
Permission is granted to anyone to use this software for any |
||||
purpose, including commercial applications, and to alter it and |
||||
redistribute it freely, subject to the following restrictions: |
||||
|
||||
1. The origin of this software must not be misrepresented; you |
||||
must not claim that you wrote the original software. If you use |
||||
this software in a product, an acknowledgment in the product |
||||
documentation would be appreciated but is not required. |
||||
|
||||
2. Altered source versions must be plainly marked as such, and |
||||
must not be misrepresented as being the original software. |
||||
|
||||
3. This notice may not be removed or altered from any source |
||||
distribution. |
@ -0,0 +1,71 @@ |
||||
Nanopb - Protocol Buffers for Embedded Systems |
||||
============================================== |
||||
|
||||
[](https://travis-ci.org/nanopb/nanopb) |
||||
|
||||
Nanopb is a small code-size Protocol Buffers implementation in ansi C. It is |
||||
especially suitable for use in microcontrollers, but fits any memory |
||||
restricted system. |
||||
|
||||
* **Homepage:** http://kapsi.fi/~jpa/nanopb/ |
||||
* **Documentation:** http://kapsi.fi/~jpa/nanopb/docs/ |
||||
* **Downloads:** http://kapsi.fi/~jpa/nanopb/download/ |
||||
* **Forum:** https://groups.google.com/forum/#!forum/nanopb |
||||
|
||||
|
||||
|
||||
Using the nanopb library |
||||
------------------------ |
||||
To use the nanopb library, you need to do two things: |
||||
|
||||
1. Compile your .proto files for nanopb, using protoc. |
||||
2. Include pb_encode.c and pb_decode.c in your project. |
||||
|
||||
The easiest way to get started is to study the project in "examples/simple". |
||||
It contains a Makefile, which should work directly under most Linux systems. |
||||
However, for any other kind of build system, see the manual steps in |
||||
README.txt in that folder. |
||||
|
||||
|
||||
|
||||
Using the Protocol Buffers compiler (protoc) |
||||
-------------------------------------------- |
||||
The nanopb generator is implemented as a plugin for the Google's own protoc |
||||
compiler. This has the advantage that there is no need to reimplement the |
||||
basic parsing of .proto files. However, it does mean that you need the |
||||
Google's protobuf library in order to run the generator. |
||||
|
||||
If you have downloaded a binary package for nanopb (either Windows, Linux or |
||||
Mac OS X version), the 'protoc' binary is included in the 'generator-bin' |
||||
folder. In this case, you are ready to go. Simply run this command: |
||||
|
||||
generator-bin/protoc --nanopb_out=. myprotocol.proto |
||||
|
||||
However, if you are using a git checkout or a plain source distribution, you |
||||
need to provide your own version of protoc and the Google's protobuf library. |
||||
On Linux, the necessary packages are protobuf-compiler and python-protobuf. |
||||
On Windows, you can either build Google's protobuf library from source or use |
||||
one of the binary distributions of it. In either case, if you use a separate |
||||
protoc, you need to manually give the path to nanopb generator: |
||||
|
||||
protoc --plugin=protoc-gen-nanopb=nanopb/generator/protoc-gen-nanopb ... |
||||
|
||||
|
||||
|
||||
Running the tests |
||||
----------------- |
||||
If you want to perform further development of the nanopb core, or to verify |
||||
its functionality using your compiler and platform, you'll want to run the |
||||
test suite. The build rules for the test suite are implemented using Scons, |
||||
so you need to have that installed. To run the tests: |
||||
|
||||
cd tests |
||||
scons |
||||
|
||||
This will show the progress of various test cases. If the output does not |
||||
end in an error, the test cases were successful. |
||||
|
||||
Note: Mac OS X by default aliases 'clang' as 'gcc', while not actually |
||||
supporting the same command line options as gcc does. To run tests on |
||||
Mac OS X, use: "scons CC=clang CXX=clang". Same way can be used to run |
||||
tests with different compilers on any platform. |
@ -0,0 +1,9 @@ |
||||
all: index.html concepts.html reference.html security.html migration.html \
|
||||
generator_flow.png
|
||||
|
||||
%.png: %.svg |
||||
rsvg $< $@
|
||||
|
||||
%.html: %.rst |
||||
rst2html --stylesheet=lsr.css --link-stylesheet $< $@
|
||||
sed -i 's!</head>!<link href="favicon.ico" type="image/x-icon" rel="shortcut icon" />\n</head>!' $@
|
@ -0,0 +1,392 @@ |
||||
====================== |
||||
Nanopb: Basic concepts |
||||
====================== |
||||
|
||||
.. include :: menu.rst |
||||
|
||||
The things outlined here are the underlying concepts of the nanopb design. |
||||
|
||||
.. contents:: |
||||
|
||||
Proto files |
||||
=========== |
||||
All Protocol Buffers implementations use .proto files to describe the message |
||||
format. The point of these files is to be a portable interface description |
||||
language. |
||||
|
||||
Compiling .proto files for nanopb |
||||
--------------------------------- |
||||
Nanopb uses the Google's protoc compiler to parse the .proto file, and then a |
||||
python script to generate the C header and source code from it:: |
||||
|
||||
user@host:~$ protoc -omessage.pb message.proto |
||||
user@host:~$ python ../generator/nanopb_generator.py message.pb |
||||
Writing to message.h and message.c |
||||
user@host:~$ |
||||
|
||||
Modifying generator behaviour |
||||
----------------------------- |
||||
Using generator options, you can set maximum sizes for fields in order to |
||||
allocate them statically. The preferred way to do this is to create an .options |
||||
file with the same name as your .proto file:: |
||||
|
||||
# Foo.proto |
||||
message Foo { |
||||
required string name = 1; |
||||
} |
||||
|
||||
:: |
||||
|
||||
# Foo.options |
||||
Foo.name max_size:16 |
||||
|
||||
For more information on this, see the `Proto file options`_ section in the |
||||
reference manual. |
||||
|
||||
.. _`Proto file options`: reference.html#proto-file-options |
||||
|
||||
Streams |
||||
======= |
||||
|
||||
Nanopb uses streams for accessing the data in encoded format. |
||||
The stream abstraction is very lightweight, and consists of a structure (*pb_ostream_t* or *pb_istream_t*) which contains a pointer to a callback function. |
||||
|
||||
There are a few generic rules for callback functions: |
||||
|
||||
#) Return false on IO errors. The encoding or decoding process will abort immediately. |
||||
#) Use state to store your own data, such as a file descriptor. |
||||
#) *bytes_written* and *bytes_left* are updated by pb_write and pb_read. |
||||
#) Your callback may be used with substreams. In this case *bytes_left*, *bytes_written* and *max_size* have smaller values than the original stream. Don't use these values to calculate pointers. |
||||
#) Always read or write the full requested length of data. For example, POSIX *recv()* needs the *MSG_WAITALL* parameter to accomplish this. |
||||
|
||||
Output streams |
||||
-------------- |
||||
|
||||
:: |
||||
|
||||
struct _pb_ostream_t |
||||
{ |
||||
bool (*callback)(pb_ostream_t *stream, const uint8_t *buf, size_t count); |
||||
void *state; |
||||
size_t max_size; |
||||
size_t bytes_written; |
||||
}; |
||||
|
||||
The *callback* for output stream may be NULL, in which case the stream simply counts the number of bytes written. In this case, *max_size* is ignored. |
||||
|
||||
Otherwise, if *bytes_written* + bytes_to_be_written is larger than *max_size*, pb_write returns false before doing anything else. If you don't want to limit the size of the stream, pass SIZE_MAX. |
||||
|
||||
**Example 1:** |
||||
|
||||
This is the way to get the size of the message without storing it anywhere:: |
||||
|
||||
Person myperson = ...; |
||||
pb_ostream_t sizestream = {0}; |
||||
pb_encode(&sizestream, Person_fields, &myperson); |
||||
printf("Encoded size is %d\n", sizestream.bytes_written); |
||||
|
||||
**Example 2:** |
||||
|
||||
Writing to stdout:: |
||||
|
||||
bool callback(pb_ostream_t *stream, const uint8_t *buf, size_t count) |
||||
{ |
||||
FILE *file = (FILE*) stream->state; |
||||
return fwrite(buf, 1, count, file) == count; |
||||
} |
||||
|
||||
pb_ostream_t stdoutstream = {&callback, stdout, SIZE_MAX, 0}; |
||||
|
||||
Input streams |
||||
------------- |
||||
For input streams, there is one extra rule: |
||||
|
||||
#) You don't need to know the length of the message in advance. After getting EOF error when reading, set bytes_left to 0 and return false. Pb_decode will detect this and if the EOF was in a proper position, it will return true. |
||||
|
||||
Here is the structure:: |
||||
|
||||
struct _pb_istream_t |
||||
{ |
||||
bool (*callback)(pb_istream_t *stream, uint8_t *buf, size_t count); |
||||
void *state; |
||||
size_t bytes_left; |
||||
}; |
||||
|
||||
The *callback* must always be a function pointer. *Bytes_left* is an upper limit on the number of bytes that will be read. You can use SIZE_MAX if your callback handles EOF as described above. |
||||
|
||||
**Example:** |
||||
|
||||
This function binds an input stream to stdin: |
||||
|
||||
:: |
||||
|
||||
bool callback(pb_istream_t *stream, uint8_t *buf, size_t count) |
||||
{ |
||||
FILE *file = (FILE*)stream->state; |
||||
bool status; |
||||
|
||||
if (buf == NULL) |
||||
{ |
||||
while (count-- && fgetc(file) != EOF); |
||||
return count == 0; |
||||
} |
||||
|
||||
status = (fread(buf, 1, count, file) == count); |
||||
|
||||
if (feof(file)) |
||||
stream->bytes_left = 0; |
||||
|
||||
return status; |
||||
} |
||||
|
||||
pb_istream_t stdinstream = {&callback, stdin, SIZE_MAX}; |
||||
|
||||
Data types |
||||
========== |
||||
|
||||
Most Protocol Buffers datatypes have directly corresponding C datatypes, such as int32 is int32_t, float is float and bool is bool. However, the variable-length datatypes are more complex: |
||||
|
||||
1) Strings, bytes and repeated fields of any type map to callback functions by default. |
||||
2) If there is a special option *(nanopb).max_size* specified in the .proto file, string maps to null-terminated char array and bytes map to a structure containing a char array and a size field. |
||||
3) If *(nanopb).type* is set to *FT_INLINE* and *(nanopb).max_size* is also set, then bytes map to an inline byte array of fixed size. |
||||
3) If there is a special option *(nanopb).max_count* specified on a repeated field, it maps to an array of whatever type is being repeated. Another field will be created for the actual number of entries stored. |
||||
|
||||
=============================================================================== ======================= |
||||
field in .proto autogenerated in .h |
||||
=============================================================================== ======================= |
||||
required string name = 1; pb_callback_t name; |
||||
required string name = 1 [(nanopb).max_size = 40]; char name[40]; |
||||
repeated string name = 1 [(nanopb).max_size = 40]; pb_callback_t name; |
||||
repeated string name = 1 [(nanopb).max_size = 40, (nanopb).max_count = 5]; | size_t name_count; |
||||
| char name[5][40]; |
||||
required bytes data = 1 [(nanopb).max_size = 40]; | typedef struct { |
||||
| size_t size; |
||||
| pb_byte_t bytes[40]; |
||||
| } Person_data_t; |
||||
| Person_data_t data; |
||||
required bytes data = 1 [(nanopb).max_size = 40, (nanopb.type) = FT_INLINE]; | pb_byte_t data[40]; |
||||
=============================================================================== ======================= |
||||
|
||||
The maximum lengths are checked in runtime. If string/bytes/array exceeds the allocated length, *pb_decode* will return false. |
||||
|
||||
Note: for the *bytes* datatype, the field length checking may not be exact. |
||||
The compiler may add some padding to the *pb_bytes_t* structure, and the nanopb runtime doesn't know how much of the structure size is padding. Therefore it uses the whole length of the structure for storing data, which is not very smart but shouldn't cause problems. In practise, this means that if you specify *(nanopb).max_size=5* on a *bytes* field, you may be able to store 6 bytes there. For the *string* field type, the length limit is exact. |
||||
|
||||
Field callbacks |
||||
=============== |
||||
When a field has dynamic length, nanopb cannot statically allocate storage for it. Instead, it allows you to handle the field in whatever way you want, using a callback function. |
||||
|
||||
The `pb_callback_t`_ structure contains a function pointer and a *void* pointer called *arg* you can use for passing data to the callback. If the function pointer is NULL, the field will be skipped. A pointer to the *arg* is passed to the function, so that it can modify it and retrieve the value. |
||||
|
||||
The actual behavior of the callback function is different in encoding and decoding modes. In encoding mode, the callback is called once and should write out everything, including field tags. In decoding mode, the callback is called repeatedly for every data item. |
||||
|
||||
.. _`pb_callback_t`: reference.html#pb-callback-t |
||||
|
||||
Encoding callbacks |
||||
------------------ |
||||
:: |
||||
|
||||
bool (*encode)(pb_ostream_t *stream, const pb_field_t *field, void * const *arg); |
||||
|
||||
When encoding, the callback should write out complete fields, including the wire type and field number tag. It can write as many or as few fields as it likes. For example, if you want to write out an array as *repeated* field, you should do it all in a single call. |
||||
|
||||
Usually you can use `pb_encode_tag_for_field`_ to encode the wire type and tag number of the field. However, if you want to encode a repeated field as a packed array, you must call `pb_encode_tag`_ instead to specify a wire type of *PB_WT_STRING*. |
||||
|
||||
If the callback is used in a submessage, it will be called multiple times during a single call to `pb_encode`_. In this case, it must produce the same amount of data every time. If the callback is directly in the main message, it is called only once. |
||||
|
||||
.. _`pb_encode`: reference.html#pb-encode |
||||
.. _`pb_encode_tag_for_field`: reference.html#pb-encode-tag-for-field |
||||
.. _`pb_encode_tag`: reference.html#pb-encode-tag |
||||
|
||||
This callback writes out a dynamically sized string:: |
||||
|
||||
bool write_string(pb_ostream_t *stream, const pb_field_t *field, void * const *arg) |
||||
{ |
||||
char *str = get_string_from_somewhere(); |
||||
if (!pb_encode_tag_for_field(stream, field)) |
||||
return false; |
||||
|
||||
return pb_encode_string(stream, (uint8_t*)str, strlen(str)); |
||||
} |
||||
|
||||
Decoding callbacks |
||||
------------------ |
||||
:: |
||||
|
||||
bool (*decode)(pb_istream_t *stream, const pb_field_t *field, void **arg); |
||||
|
||||
When decoding, the callback receives a length-limited substring that reads the contents of a single field. The field tag has already been read. For *string* and *bytes*, the length value has already been parsed, and is available at *stream->bytes_left*. |
||||
|
||||
The callback will be called multiple times for repeated fields. For packed fields, you can either read multiple values until the stream ends, or leave it to `pb_decode`_ to call your function over and over until all values have been read. |
||||
|
||||
.. _`pb_decode`: reference.html#pb-decode |
||||
|
||||
This callback reads multiple integers and prints them:: |
||||
|
||||
bool read_ints(pb_istream_t *stream, const pb_field_t *field, void **arg) |
||||
{ |
||||
while (stream->bytes_left) |
||||
{ |
||||
uint64_t value; |
||||
if (!pb_decode_varint(stream, &value)) |
||||
return false; |
||||
printf("%lld\n", value); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
Field description array |
||||
======================= |
||||
|
||||
For using the *pb_encode* and *pb_decode* functions, you need an array of pb_field_t constants describing the structure you wish to encode. This description is usually autogenerated from .proto file. |
||||
|
||||
For example this submessage in the Person.proto file:: |
||||
|
||||
message Person { |
||||
message PhoneNumber { |
||||
required string number = 1 [(nanopb).max_size = 40]; |
||||
optional PhoneType type = 2 [default = HOME]; |
||||
} |
||||
} |
||||
|
||||
generates this field description array for the structure *Person_PhoneNumber*:: |
||||
|
||||
const pb_field_t Person_PhoneNumber_fields[3] = { |
||||
PB_FIELD( 1, STRING , REQUIRED, STATIC, Person_PhoneNumber, number, number, 0), |
||||
PB_FIELD( 2, ENUM , OPTIONAL, STATIC, Person_PhoneNumber, type, number, &Person_PhoneNumber_type_default), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
Oneof |
||||
===== |
||||
Protocol Buffers supports `oneof`_ sections. Here is an example of ``oneof`` usage:: |
||||
|
||||
message MsgType1 { |
||||
required int32 value = 1; |
||||
} |
||||
|
||||
message MsgType2 { |
||||
required bool value = 1; |
||||
} |
||||
|
||||
message MsgType3 { |
||||
required int32 value1 = 1; |
||||
required int32 value2 = 2; |
||||
} |
||||
|
||||
message MyMessage { |
||||
required uint32 uid = 1; |
||||
required uint32 pid = 2; |
||||
required uint32 utime = 3; |
||||
|
||||
oneof payload { |
||||
MsgType1 msg1 = 4; |
||||
MsgType2 msg2 = 5; |
||||
MsgType3 msg3 = 6; |
||||
} |
||||
} |
||||
|
||||
Nanopb will generate ``payload`` as a C union and add an additional field ``which_payload``:: |
||||
|
||||
typedef struct _MyMessage { |
||||
uint32_t uid; |
||||
uint32_t pid; |
||||
uint32_t utime; |
||||
pb_size_t which_payload; |
||||
union { |
||||
MsgType1 msg1; |
||||
MsgType2 msg2; |
||||
MsgType3 msg3; |
||||
} payload; |
||||
/* @@protoc_insertion_point(struct:MyMessage) */ |
||||
} MyMessage; |
||||
|
||||
``which_payload`` indicates which of the ``oneof`` fields is actually set. |
||||
The user is expected to set the filed manually using the correct field tag:: |
||||
|
||||
MyMessage msg = MyMessage_init_zero; |
||||
msg.payload.msg2.value = true; |
||||
msg.which_payload = MyMessage_msg2_tag; |
||||
|
||||
Notice that neither ``which_payload`` field nor the unused fileds in ``payload`` |
||||
will consume any space in the resulting encoded message. |
||||
|
||||
.. _`oneof`: https://developers.google.com/protocol-buffers/docs/reference/proto2-spec#oneof_and_oneof_field |
||||
|
||||
Extension fields |
||||
================ |
||||
Protocol Buffers supports a concept of `extension fields`_, which are |
||||
additional fields to a message, but defined outside the actual message. |
||||
The definition can even be in a completely separate .proto file. |
||||
|
||||
The base message is declared as extensible by keyword *extensions* in |
||||
the .proto file:: |
||||
|
||||
message MyMessage { |
||||
.. fields .. |
||||
extensions 100 to 199; |
||||
} |
||||
|
||||
For each extensible message, *nanopb_generator.py* declares an additional |
||||
callback field called *extensions*. The field and associated datatype |
||||
*pb_extension_t* forms a linked list of handlers. When an unknown field is |
||||
encountered, the decoder calls each handler in turn until either one of them |
||||
handles the field, or the list is exhausted. |
||||
|
||||
The actual extensions are declared using the *extend* keyword in the .proto, |
||||
and are in the global namespace:: |
||||
|
||||
extend MyMessage { |
||||
optional int32 myextension = 100; |
||||
} |
||||
|
||||
For each extension, *nanopb_generator.py* creates a constant of type |
||||
*pb_extension_type_t*. To link together the base message and the extension, |
||||
you have to: |
||||
|
||||
1. Allocate storage for your field, matching the datatype in the .proto. |
||||
For example, for a *int32* field, you need a *int32_t* variable to store |
||||
the value. |
||||
2. Create a *pb_extension_t* constant, with pointers to your variable and |
||||
to the generated *pb_extension_type_t*. |
||||
3. Set the *message.extensions* pointer to point to the *pb_extension_t*. |
||||
|
||||
An example of this is available in *tests/test_encode_extensions.c* and |
||||
*tests/test_decode_extensions.c*. |
||||
|
||||
.. _`extension fields`: https://developers.google.com/protocol-buffers/docs/proto#extensions |
||||
|
||||
Message framing |
||||
=============== |
||||
Protocol Buffers does not specify a method of framing the messages for transmission. |
||||
This is something that must be provided by the library user, as there is no one-size-fits-all |
||||
solution. Typical needs for a framing format are to: |
||||
|
||||
1. Encode the message length. |
||||
2. Encode the message type. |
||||
3. Perform any synchronization and error checking that may be needed depending on application. |
||||
|
||||
For example UDP packets already fullfill all the requirements, and TCP streams typically only |
||||
need a way to identify the message length and type. Lower level interfaces such as serial ports |
||||
may need a more robust frame format, such as HDLC (high-level data link control). |
||||
|
||||
Nanopb provides a few helpers to facilitate implementing framing formats: |
||||
|
||||
1. Functions *pb_encode_delimited* and *pb_decode_delimited* prefix the message data with a varint-encoded length. |
||||
2. Union messages and oneofs are supported in order to implement top-level container messages. |
||||
3. Message IDs can be specified using the *(nanopb_msgopt).msgid* option and can then be accessed from the header. |
||||
|
||||
Return values and error handling |
||||
================================ |
||||
|
||||
Most functions in nanopb return bool: *true* means success, *false* means failure. There is also some support for error messages for debugging purposes: the error messages go in *stream->errmsg*. |
||||
|
||||
The error messages help in guessing what is the underlying cause of the error. The most common error conditions are: |
||||
|
||||
1) Running out of memory, i.e. stack overflow. |
||||
2) Invalid field descriptors (would usually mean a bug in the generator). |
||||
3) IO errors in your own stream callbacks. |
||||
4) Errors that happen in your callback functions. |
||||
5) Exceeding the max_size or bytes_left of a stream. |
||||
6) Exceeding the max_size of a string or array field |
||||
7) Invalid protocol buffers binary message. |
After Width: | Height: | Size: 112 KiB |
@ -0,0 +1,127 @@ |
||||
============================================= |
||||
Nanopb: Protocol Buffers with small code size |
||||
============================================= |
||||
|
||||
.. include :: menu.rst |
||||
|
||||
Nanopb is an ANSI-C library for encoding and decoding messages in Google's `Protocol Buffers`__ format with minimal requirements for RAM and code space. |
||||
It is primarily suitable for 32-bit microcontrollers. |
||||
|
||||
__ https://developers.google.com/protocol-buffers/docs/reference/overview |
||||
|
||||
Overall structure |
||||
================= |
||||
|
||||
For the runtime program, you always need *pb.h* for type declarations. |
||||
Depending on whether you want to encode, decode, or both, you also need *pb_encode.h/c* or *pb_decode.h/c*. |
||||
|
||||
The high-level encoding and decoding functions take an array of *pb_field_t* structures, which describes the fields of a message structure. Usually you want these autogenerated from a *.proto* file. The tool script *nanopb_generator.py* accomplishes this. |
||||
|
||||
.. image:: generator_flow.png |
||||
|
||||
So a typical project might include these files: |
||||
|
||||
1) Nanopb runtime library: |
||||
- pb.h |
||||
- pb_common.h and pb_common.c (always needed) |
||||
- pb_decode.h and pb_decode.c (needed for decoding messages) |
||||
- pb_encode.h and pb_encode.c (needed for encoding messages) |
||||
2) Protocol description (you can have many): |
||||
- person.proto (just an example) |
||||
- person.pb.c (autogenerated, contains initializers for const arrays) |
||||
- person.pb.h (autogenerated, contains type declarations) |
||||
|
||||
Features and limitations |
||||
======================== |
||||
|
||||
**Features** |
||||
|
||||
#) Pure C runtime |
||||
#) Small code size (2–10 kB depending on processor, plus any message definitions) |
||||
#) Small ram usage (typically ~300 bytes, plus any message structs) |
||||
#) Allows specifying maximum size for strings and arrays, so that they can be allocated statically. |
||||
#) No malloc needed: everything can be allocated statically or on the stack. Optional malloc support available. |
||||
#) You can use either encoder or decoder alone to cut the code size in half. |
||||
#) Support for most protobuf features, including: all data types, nested submessages, default values, repeated and optional fields, oneofs, packed arrays, extension fields. |
||||
#) Callback mechanism for handling messages larger than can fit in available RAM. |
||||
#) Extensive set of tests. |
||||
|
||||
**Limitations** |
||||
|
||||
#) Some speed has been sacrificed for code size. |
||||
#) Encoding is focused on writing to streams. For memory buffers only it could be made more efficient. |
||||
#) The deprecated Protocol Buffers feature called "groups" is not supported. |
||||
#) Fields in the generated structs are ordered by the tag number, instead of the natural ordering in .proto file. |
||||
#) Unknown fields are not preserved when decoding and re-encoding a message. |
||||
#) Reflection (runtime introspection) is not supported. E.g. you can't request a field by giving its name in a string. |
||||
#) Numeric arrays are always encoded as packed, even if not marked as packed in .proto. |
||||
#) Cyclic references between messages are supported only in callback and malloc mode. |
||||
|
||||
Getting started |
||||
=============== |
||||
|
||||
For starters, consider this simple message:: |
||||
|
||||
message Example { |
||||
required int32 value = 1; |
||||
} |
||||
|
||||
Save this in *message.proto* and compile it:: |
||||
|
||||
user@host:~$ protoc -omessage.pb message.proto |
||||
user@host:~$ python nanopb/generator/nanopb_generator.py message.pb |
||||
|
||||
You should now have in *message.pb.h*:: |
||||
|
||||
typedef struct { |
||||
int32_t value; |
||||
} Example; |
||||
|
||||
extern const pb_field_t Example_fields[2]; |
||||
|
||||
Now in your main program do this to encode a message:: |
||||
|
||||
Example mymessage = {42}; |
||||
uint8_t buffer[10]; |
||||
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); |
||||
pb_encode(&stream, Example_fields, &mymessage); |
||||
|
||||
After that, buffer will contain the encoded message. |
||||
The number of bytes in the message is stored in *stream.bytes_written*. |
||||
You can feed the message to *protoc --decode=Example message.proto* to verify its validity. |
||||
|
||||
For a complete example of the simple case, see *example/simple.c*. |
||||
For a more complex example with network interface, see the *example/network_server* subdirectory. |
||||
|
||||
Compiler requirements |
||||
===================== |
||||
Nanopb should compile with most ansi-C compatible compilers. It however |
||||
requires a few header files to be available: |
||||
|
||||
#) *string.h*, with these functions: *strlen*, *memcpy*, *memset* |
||||
#) *stdint.h*, for definitions of *int32_t* etc. |
||||
#) *stddef.h*, for definition of *size_t* |
||||
#) *stdbool.h*, for definition of *bool* |
||||
|
||||
If these header files do not come with your compiler, you can use the |
||||
file *extra/pb_syshdr.h* instead. It contains an example of how to provide |
||||
the dependencies. You may have to edit it a bit to suit your custom platform. |
||||
|
||||
To use the pb_syshdr.h, define *PB_SYSTEM_HEADER* as *"pb_syshdr.h"* (including the quotes). |
||||
Similarly, you can provide a custom include file, which should provide all the dependencies |
||||
listed above. |
||||
|
||||
Running the test cases |
||||
====================== |
||||
Extensive unittests and test cases are included under the *tests* folder. |
||||
|
||||
To build the tests, you will need the `scons`__ build system. The tests should |
||||
be runnable on most platforms. Windows and Linux builds are regularly tested. |
||||
|
||||
__ http://www.scons.org/ |
||||
|
||||
In addition to the build system, you will also need a working Google Protocol |
||||
Buffers *protoc* compiler, and the Python bindings for Protocol Buffers. On |
||||
Debian-based systems, install the following packages: *protobuf-compiler*, |
||||
*python-protobuf* and *libprotobuf-dev*. |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue