Compare commits

..

7 Commits

Author SHA1 Message Date
Petteri Aimonen
17c10119dd Remove the PB_ENCODERS array. 2013-11-14 19:36:53 +02:00
Petteri Aimonen
97210c91a9 Remove the PB_DECODERS array.
Reduces code size by 2% and is overall cleaner.
2013-11-14 19:26:47 +02:00
Petteri Aimonen
cace53dfbd Change the API for pb_make_string_substream() to use less stack.
If your own application uses this function, you have to change
the old style:

    pb_istream_t substream;
    if (!pb_make_string_substream(stream, &substream))
        return false;
    .. do stuff with substream ..
    pb_close_string_substream(stream, &substream);

to the new style:

    size_t remaining;
    if (!pb_make_string_substream(stream, &remaining))
        return false;
    .. do stuff with stream ..
    pb_close_string_substream(stream, remaining);
2013-11-14 19:16:49 +02:00
Petteri Aimonen
eff9e11150 Optimize the common case of 1-byte reads for varints.
For PB_BUFFER_ONLY configuration, this gives 20% speedup without
increasing code size.
2013-11-14 17:56:42 +02:00
Petteri Aimonen
5813144246 Make tests build in a separate folder, add to gitignore 2013-11-13 22:10:42 +02:00
Petteri Aimonen
171d64734a Fix path in FindNanopb.cmake.
Update issue 94
Status: FixedInGit
2013-11-11 09:22:32 +02:00
Petteri Aimonen
321ca6c1d5 Setting version to 0.2.5-dev 2013-11-07 16:47:14 +02:00
23 changed files with 169 additions and 143 deletions

19
.gitignore vendored
View File

@@ -5,17 +5,22 @@
*.pb.c
*.pb.h
*.pb
*.pyc
*~
*.tar.gz
.sconsign.dblite
config.log
.sconf_temp
tests/build
julkaisu.txt
docs/*.html
docs/generator_flow.png
example/client
example/server
example_avr_double/decode_double
example_avr_double/encode_double
example_avr_double/test_conversions
example_unions/decode
example_unions/encode
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

View File

@@ -148,7 +148,7 @@ function(NANOPB_GENERATE_CPP SRCS HDRS)
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
COMMAND python
ARGS ${NANOPB_GENERATOR_EXECUTABLE} ${FIL_WE}.pb
DEPENDS ${FIL_WE}.pb
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb"
COMMENT "Running nanopb generator on ${FIL_WE}.pb"
VERBATIM )
endforeach()

View File

@@ -1,7 +1,7 @@
#!/usr/bin/python
'''Generate header file for nanopb from a ProtoBuf FileDescriptorSet.'''
nanopb_version = "nanopb-0.2.4"
nanopb_version = "nanopb-0.2.5-dev"
try:
import google.protobuf.descriptor_pb2 as descriptor

2
pb.h
View File

@@ -43,7 +43,7 @@
/* Version of the nanopb library. Just in case you want to check it in
* your own program. */
#define NANOPB_VERSION nanopb-0.2.4
#define NANOPB_VERSION nanopb-0.2.5-dev
/* Include all the system headers needed by nanopb. You will need the
* definitions of the following:

View File

@@ -32,7 +32,6 @@ typedef struct {
void *pSize; /* Pointer where to store the size of current array field */
} pb_field_iterator_t;
typedef bool (*pb_decoder_t)(pb_istream_t *stream, const pb_field_t *field, void *dest) checkreturn;
static bool checkreturn buf_read(pb_istream_t *stream, uint8_t *buf, size_t count);
static bool checkreturn pb_decode_varint32(pb_istream_t *stream, uint32_t *dest);
@@ -40,6 +39,7 @@ static bool checkreturn read_raw_value(pb_istream_t *stream, pb_wire_type_t wire
static void pb_field_init(pb_field_iterator_t *iter, const pb_field_t *fields, void *dest_struct);
static bool pb_field_next(pb_field_iterator_t *iter);
static bool checkreturn pb_field_find(pb_field_iterator_t *iter, uint32_t tag);
static bool checkreturn decode_ltype(pb_istream_t *stream, const pb_field_t *field, void *dest, pb_type_t type);
static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iterator_t *iter);
static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iterator_t *iter);
static bool checkreturn decode_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iterator_t *iter);
@@ -57,21 +57,6 @@ static bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t
static bool checkreturn pb_skip_varint(pb_istream_t *stream);
static bool checkreturn pb_skip_string(pb_istream_t *stream);
/* --- Function pointers to field decoders ---
* Order in the array must match pb_action_t LTYPE numbering.
*/
static const pb_decoder_t PB_DECODERS[PB_LTYPES_COUNT] = {
&pb_dec_varint,
&pb_dec_svarint,
&pb_dec_fixed32,
&pb_dec_fixed64,
&pb_dec_bytes,
&pb_dec_string,
&pb_dec_submessage,
NULL /* extensions */
};
/*******************************
* pb_istream_t implementation *
*******************************/
@@ -124,6 +109,26 @@ bool checkreturn pb_read(pb_istream_t *stream, uint8_t *buf, size_t count)
return true;
}
/* Read a single byte from input stream. buf may not be NULL.
* This is an optimization for the varint decoding. */
static bool checkreturn pb_readbyte(pb_istream_t *stream, uint8_t *buf)
{
if (!stream->bytes_left)
PB_RETURN_ERROR(stream, "end-of-stream");
#ifndef PB_BUFFER_ONLY
if (!stream->callback(stream, buf, 1))
PB_RETURN_ERROR(stream, "io error");
#else
*buf = *(uint8_t*)stream->state;
stream->state = (uint8_t*)stream->state + 1;
#endif
stream->bytes_left--;
return true;
}
pb_istream_t pb_istream_from_buffer(uint8_t *buf, size_t bufsize)
{
pb_istream_t stream;
@@ -149,7 +154,7 @@ static bool checkreturn pb_decode_varint32(pb_istream_t *stream, uint32_t *dest)
uint8_t byte;
uint32_t result;
if (!pb_read(stream, &byte, 1))
if (!pb_readbyte(stream, &byte))
return false;
if (!(byte & 0x80))
@@ -168,7 +173,7 @@ static bool checkreturn pb_decode_varint32(pb_istream_t *stream, uint32_t *dest)
if (bitpos >= 32)
PB_RETURN_ERROR(stream, "varint overflow");
if (!pb_read(stream, &byte, 1))
if (!pb_readbyte(stream, &byte))
return false;
result |= (uint32_t)(byte & 0x7F) << bitpos;
@@ -191,7 +196,7 @@ bool checkreturn pb_decode_varint(pb_istream_t *stream, uint64_t *dest)
if (bitpos >= 64)
PB_RETURN_ERROR(stream, "varint overflow");
if (!pb_read(stream, &byte, 1))
if (!pb_readbyte(stream, &byte))
return false;
result |= (uint64_t)(byte & 0x7F) << bitpos;
@@ -293,28 +298,23 @@ static bool checkreturn read_raw_value(pb_istream_t *stream, pb_wire_type_t wire
/* Decode string length from stream and return a substream with limited length.
* Remember to close the substream using pb_close_string_substream().
*/
bool checkreturn pb_make_string_substream(pb_istream_t *stream, pb_istream_t *substream)
bool checkreturn pb_make_string_substream(pb_istream_t *stream, size_t *remaining_length)
{
uint32_t size;
if (!pb_decode_varint32(stream, &size))
return false;
*substream = *stream;
if (substream->bytes_left < size)
if (stream->bytes_left < size)
PB_RETURN_ERROR(stream, "parent stream too short");
substream->bytes_left = size;
stream->bytes_left -= size;
*remaining_length = stream->bytes_left - size;
stream->bytes_left = size;
return true;
}
void pb_close_string_substream(pb_istream_t *stream, pb_istream_t *substream)
void pb_close_string_substream(pb_istream_t *stream, size_t remaining_length)
{
stream->state = substream->state;
#ifndef PB_NO_ERRMSG
stream->errmsg = substream->errmsg;
#endif
stream->bytes_left += remaining_length;
}
static void pb_field_init(pb_field_iterator_t *iter, const pb_field_t *fields, void *dest_struct)
@@ -381,22 +381,37 @@ static bool checkreturn pb_field_find(pb_field_iterator_t *iter, uint32_t tag)
* Decode a single field *
*************************/
/* Invoke a decoder function based on the ltype of a field. */
static bool checkreturn decode_ltype(pb_istream_t *stream,
const pb_field_t *field, void *dest, pb_type_t type)
{
switch (PB_LTYPE(type))
{
case PB_LTYPE_VARINT: return pb_dec_varint(stream, field, dest);
case PB_LTYPE_SVARINT: return pb_dec_svarint(stream, field, dest);
case PB_LTYPE_FIXED32: return pb_dec_fixed32(stream, field, dest);
case PB_LTYPE_FIXED64: return pb_dec_fixed64(stream, field, dest);
case PB_LTYPE_BYTES: return pb_dec_bytes(stream, field, dest);
case PB_LTYPE_STRING: return pb_dec_string(stream, field, dest);
case PB_LTYPE_SUBMESSAGE: return pb_dec_submessage(stream, field, dest);
default: PB_RETURN_ERROR(stream, "invalid field type");
}
}
static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iterator_t *iter)
{
pb_type_t type;
pb_decoder_t func;
type = iter->pos->type;
func = PB_DECODERS[PB_LTYPE(type)];
switch (PB_HTYPE(type))
{
case PB_HTYPE_REQUIRED:
return func(stream, iter->pos, iter->pData);
return decode_ltype(stream, iter->pos, iter->pData, type);
case PB_HTYPE_OPTIONAL:
*(bool*)iter->pSize = true;
return func(stream, iter->pos, iter->pData);
return decode_ltype(stream, iter->pos, iter->pData, type);
case PB_HTYPE_REPEATED:
if (wire_type == PB_WT_STRING
@@ -405,24 +420,25 @@ static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t
/* Packed array */
bool status = true;
size_t *size = (size_t*)iter->pSize;
pb_istream_t substream;
if (!pb_make_string_substream(stream, &substream))
size_t remaining_length;
if (!pb_make_string_substream(stream, &remaining_length))
return false;
while (substream.bytes_left && *size < iter->pos->array_size)
while (stream->bytes_left)
{
void *pItem = (uint8_t*)iter->pData + iter->pos->data_size * (*size);
if (!func(&substream, iter->pos, pItem))
if (*size >= iter->pos->array_size)
PB_RETURN_ERROR(stream, "array overflow");
if (!decode_ltype(stream, iter->pos, pItem, type))
{
status = false;
break;
}
(*size)++;
}
pb_close_string_substream(stream, &substream);
if (substream.bytes_left != 0)
PB_RETURN_ERROR(stream, "array overflow");
pb_close_string_substream(stream, remaining_length);
return status;
}
@@ -435,7 +451,7 @@ static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t
PB_RETURN_ERROR(stream, "array overflow");
(*size)++;
return func(stream, iter->pos, pItem);
return decode_ltype(stream, iter->pos, pItem, type);
}
default:
@@ -458,18 +474,18 @@ static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type
if (wire_type == PB_WT_STRING)
{
pb_istream_t substream;
size_t remaining_length;
if (!pb_make_string_substream(stream, &substream))
if (!pb_make_string_substream(stream, &remaining_length))
return false;
do
{
if (!pCallback->funcs.decode(&substream, iter->pos, arg))
if (!pCallback->funcs.decode(stream, iter->pos, arg))
PB_RETURN_ERROR(stream, "callback failed");
} while (substream.bytes_left);
} while (stream->bytes_left);
pb_close_string_substream(stream, &substream);
pb_close_string_substream(stream, remaining_length);
return true;
}
else
@@ -726,14 +742,14 @@ bool checkreturn pb_decode(pb_istream_t *stream, const pb_field_t fields[], void
bool pb_decode_delimited(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct)
{
pb_istream_t substream;
size_t remaining_length;
bool status;
if (!pb_make_string_substream(stream, &substream))
if (!pb_make_string_substream(stream, &remaining_length))
return false;
status = pb_decode(&substream, fields, dest_struct);
pb_close_string_substream(stream, &substream);
status = pb_decode(stream, fields, dest_struct);
pb_close_string_substream(stream, remaining_length);
return status;
}
@@ -876,10 +892,10 @@ bool checkreturn pb_dec_string(pb_istream_t *stream, const pb_field_t *field, vo
bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field, void *dest)
{
bool status;
pb_istream_t substream;
size_t remaining_length;
const pb_field_t* submsg_fields = (const pb_field_t*)field->ptr;
if (!pb_make_string_substream(stream, &substream))
if (!pb_make_string_substream(stream, &remaining_length))
return false;
if (field->ptr == NULL)
@@ -888,10 +904,10 @@ bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field
/* New array entries need to be initialized, while required and optional
* submessages have already been initialized in the top-level pb_decode. */
if (PB_HTYPE(field->type) == PB_HTYPE_REPEATED)
status = pb_decode(&substream, submsg_fields, dest);
status = pb_decode(stream, submsg_fields, dest);
else
status = pb_decode_noinit(&substream, submsg_fields, dest);
status = pb_decode_noinit(stream, submsg_fields, dest);
pb_close_string_substream(stream, &substream);
pb_close_string_substream(stream, remaining_length);
return status;
}

View File

@@ -128,8 +128,8 @@ bool pb_decode_fixed32(pb_istream_t *stream, void *dest);
bool pb_decode_fixed64(pb_istream_t *stream, void *dest);
/* Make a limited-length substream for reading a PB_WT_STRING field. */
bool pb_make_string_substream(pb_istream_t *stream, pb_istream_t *substream);
void pb_close_string_substream(pb_istream_t *stream, pb_istream_t *substream);
bool pb_make_string_substream(pb_istream_t *stream, size_t *remaining_length);
void pb_close_string_substream(pb_istream_t *stream, size_t remaining_length);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -20,10 +20,9 @@
/**************************************
* Declarations internal to this file *
**************************************/
typedef bool (*pb_encoder_t)(pb_ostream_t *stream, const pb_field_t *field, const void *src) checkreturn;
static bool checkreturn buf_write(pb_ostream_t *stream, const uint8_t *buf, size_t count);
static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *field, const void *pData, size_t count, pb_encoder_t func);
static bool checkreturn encode_ltype(pb_ostream_t *stream, const pb_field_t *field, const void *src, pb_type_t type);
static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *field, const void *pData, size_t count);
static bool checkreturn encode_field(pb_ostream_t *stream, const pb_field_t *field, const void *pData);
static bool checkreturn default_extension_encoder(pb_ostream_t *stream, const pb_extension_t *extension);
static bool checkreturn encode_extension_field(pb_ostream_t *stream, const pb_field_t *field, const void *pData);
@@ -35,21 +34,6 @@ static bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *fie
static bool checkreturn pb_enc_string(pb_ostream_t *stream, const pb_field_t *field, const void *src);
static bool checkreturn pb_enc_submessage(pb_ostream_t *stream, const pb_field_t *field, const void *src);
/* --- Function pointers to field encoders ---
* Order in the array must match pb_action_t LTYPE numbering.
*/
static const pb_encoder_t PB_ENCODERS[PB_LTYPES_COUNT] = {
&pb_enc_varint,
&pb_enc_svarint,
&pb_enc_fixed32,
&pb_enc_fixed64,
&pb_enc_bytes,
&pb_enc_string,
&pb_enc_submessage,
NULL /* extensions */
};
/*******************************
* pb_ostream_t implementation *
*******************************/
@@ -106,9 +90,28 @@ bool checkreturn pb_write(pb_ostream_t *stream, const uint8_t *buf, size_t count
* Encode a single field *
*************************/
/* Invoke an encoder function based on the ltype of a field. */
static bool checkreturn encode_ltype(pb_ostream_t *stream,
const pb_field_t *field, const void *src, pb_type_t type)
{
switch (PB_LTYPE(type))
{
case PB_LTYPE_VARINT: return pb_enc_varint(stream, field, src);
case PB_LTYPE_SVARINT: return pb_enc_svarint(stream, field, src);
case PB_LTYPE_FIXED32: return pb_enc_fixed32(stream, field, src);
case PB_LTYPE_FIXED64: return pb_enc_fixed64(stream, field, src);
case PB_LTYPE_BYTES: return pb_enc_bytes(stream, field, src);
case PB_LTYPE_STRING: return pb_enc_string(stream, field, src);
case PB_LTYPE_SUBMESSAGE: return pb_enc_submessage(stream, field, src);
default: PB_RETURN_ERROR(stream, "invalid field type");
}
}
/* Encode a static array. Handles the size calculations and possible packing. */
static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *field,
const void *pData, size_t count, pb_encoder_t func)
const void *pData, size_t count)
{
size_t i;
const void *p;
@@ -141,7 +144,7 @@ static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *fie
p = pData;
for (i = 0; i < count; i++)
{
if (!func(&sizestream, field, p))
if (!encode_ltype(&sizestream, field, p, field->type))
return false;
p = (const char*)p + field->data_size;
}
@@ -158,7 +161,7 @@ static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *fie
p = pData;
for (i = 0; i < count; i++)
{
if (!func(stream, field, p))
if (!encode_ltype(stream, field, p, field->type))
return false;
p = (const char*)p + field->data_size;
}
@@ -170,7 +173,7 @@ static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *fie
{
if (!pb_encode_tag_for_field(stream, field))
return false;
if (!func(stream, field, p))
if (!encode_ltype(stream, field, p, field->type))
return false;
p = (const char*)p + field->data_size;
}
@@ -184,12 +187,9 @@ static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *fie
static bool checkreturn encode_static_field(pb_ostream_t *stream,
const pb_field_t *field, const void *pData)
{
pb_encoder_t func;
const void *pSize;
bool dummy = true;
func = PB_ENCODERS[PB_LTYPE(field->type)];
if (field->size_offset)
pSize = (const char*)pData + field->size_offset;
else
@@ -200,7 +200,7 @@ static bool checkreturn encode_static_field(pb_ostream_t *stream,
case PB_HTYPE_REQUIRED:
if (!pb_encode_tag_for_field(stream, field))
return false;
if (!func(stream, field, pData))
if (!encode_ltype(stream, field, pData, field->type))
return false;
break;
@@ -210,13 +210,13 @@ static bool checkreturn encode_static_field(pb_ostream_t *stream,
if (!pb_encode_tag_for_field(stream, field))
return false;
if (!func(stream, field, pData))
if (!encode_ltype(stream, field, pData, field->type))
return false;
}
break;
case PB_HTYPE_REPEATED:
if (!encode_array(stream, field, pData, *(const size_t*)pSize, func))
if (!encode_array(stream, field, pData, *(const size_t*)pSize))
return false;
break;

View File

@@ -26,7 +26,7 @@ if 'CXXFLAGS' in ARGUMENTS: env.Append(CCFLAGS = ARGUMENTS['CXXFLAGS'])
add_nanopb_builders(env)
# Path to the files shared by tests, and to the nanopb core.
env.Append(CPPPATH = ["#../", "#common"])
env.Append(CPPPATH = ["#../", "$COMMON"])
# Path for finding nanopb.proto
env.Append(PROTOCPATH = '#../generator')
@@ -110,5 +110,10 @@ elif 'cl' in env['CXX']:
env.Append(CXXFLAGS = '/Zi /W2 /WX')
# Now include the SConscript files from all subdirectories
SConscript(Glob('*/SConscript'), exports = 'env')
import os.path
env['VARIANT_DIR'] = 'build'
env['BUILD'] = '#' + env['VARIANT_DIR']
env['COMMON'] = '#' + env['VARIANT_DIR'] + '/common'
for subdir in Glob('*/SConscript'):
SConscript(subdir, exports = 'env', variant_dir = env['VARIANT_DIR'] + '/' + os.path.dirname(str(subdir)))

View File

@@ -3,9 +3,9 @@
Import("env")
env.NanopbProto("alltypes")
enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "#common/pb_encode.o"])
dec = env.Program(["decode_alltypes.c", "alltypes.pb.c", "#common/pb_decode.o"])
env.NanopbProto(["alltypes", "alltypes.options"])
enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o"])
dec = env.Program(["decode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_decode.o"])
env.RunTest(enc)
env.RunTest([dec, "encode_alltypes.output"])

View File

@@ -3,8 +3,8 @@
Import("env")
enc = env.Program(["encode_legacy.c", "alltypes_legacy.c", "#common/pb_encode.o"])
dec = env.Program(["decode_legacy.c", "alltypes_legacy.c", "#common/pb_decode.o"])
enc = env.Program(["encode_legacy.c", "alltypes_legacy.c", "$COMMON/pb_encode.o"])
dec = env.Program(["decode_legacy.c", "alltypes_legacy.c", "$COMMON/pb_decode.o"])
env.RunTest(enc)
env.RunTest([dec, "encode_legacy.output"])

View File

@@ -2,11 +2,11 @@
Import("env")
enc = env.Program(["encode_buffer.c", "#common/person.pb.c", "#common/pb_encode.o"])
dec = env.Program(["decode_buffer.c", "#common/person.pb.c", "#common/pb_decode.o"])
enc = env.Program(["encode_buffer.c", "$COMMON/person.pb.c", "$COMMON/pb_encode.o"])
dec = env.Program(["decode_buffer.c", "$COMMON/person.pb.c", "$COMMON/pb_decode.o"])
env.RunTest(enc)
env.RunTest([dec, "encode_buffer.output"])
env.Decode(["encode_buffer.output", "#common/person.proto"], MESSAGE = "Person")
env.Decode(["encode_buffer.output", "$COMMON/person.proto"], MESSAGE = "Person")
env.Compare(["decode_buffer.output", "encode_buffer.decoded"])

View File

@@ -2,11 +2,11 @@
Import("env")
enc = env.Program(["encode_stream.c", "#common/person.pb.c", "#common/pb_encode.o"])
dec = env.Program(["decode_stream.c", "#common/person.pb.c", "#common/pb_decode.o"])
enc = env.Program(["encode_stream.c", "$COMMON/person.pb.c", "$COMMON/pb_encode.o"])
dec = env.Program(["decode_stream.c", "$COMMON/person.pb.c", "$COMMON/pb_decode.o"])
env.RunTest(enc)
env.RunTest([dec, "encode_stream.output"])
env.Decode(["encode_stream.output", "#common/person.proto"], MESSAGE = "Person")
env.Decode(["encode_stream.output", "$COMMON/person.proto"], MESSAGE = "Person")
env.Compare(["decode_stream.output", "encode_stream.decoded"])

View File

@@ -6,10 +6,10 @@ Import("env")
c = Copy("$TARGET", "$SOURCE")
env.Command("pb_encode.c", "#../pb_encode.c", c)
env.Command("pb_decode.c", "#../pb_decode.c", c)
env.Command("alltypes.pb.h", "#alltypes/alltypes.pb.h", c)
env.Command("alltypes.pb.c", "#alltypes/alltypes.pb.c", c)
env.Command("encode_alltypes.c", "#alltypes/encode_alltypes.c", c)
env.Command("decode_alltypes.c", "#alltypes/decode_alltypes.c", c)
env.Command("alltypes.pb.h", "$BUILD/alltypes/alltypes.pb.h", c)
env.Command("alltypes.pb.c", "$BUILD/alltypes/alltypes.pb.c", c)
env.Command("encode_alltypes.c", "$BUILD/alltypes/encode_alltypes.c", c)
env.Command("decode_alltypes.c", "$BUILD/alltypes/decode_alltypes.c", c)
# Define the compilation options
opts = env.Clone()

View File

@@ -3,8 +3,8 @@
Import("env")
env.NanopbProto("callbacks")
enc = env.Program(["encode_callbacks.c", "callbacks.pb.c", "#common/pb_encode.o"])
dec = env.Program(["decode_callbacks.c", "callbacks.pb.c", "#common/pb_decode.o"])
enc = env.Program(["encode_callbacks.c", "callbacks.pb.c", "$COMMON/pb_encode.o"])
dec = env.Program(["decode_callbacks.c", "callbacks.pb.c", "$COMMON/pb_decode.o"])
env.RunTest(enc)
env.RunTest([dec, "encode_callbacks.output"])

View File

@@ -7,10 +7,10 @@ Import("env")
c = Copy("$TARGET", "$SOURCE")
env.Command("pb_encode.cxx", "#../pb_encode.c", c)
env.Command("pb_decode.cxx", "#../pb_decode.c", c)
env.Command("alltypes.pb.h", "#alltypes/alltypes.pb.h", c)
env.Command("alltypes.pb.cxx", "#alltypes/alltypes.pb.c", c)
env.Command("encode_alltypes.cxx", "#alltypes/encode_alltypes.c", c)
env.Command("decode_alltypes.cxx", "#alltypes/decode_alltypes.c", c)
env.Command("alltypes.pb.h", "$BUILD/alltypes/alltypes.pb.h", c)
env.Command("alltypes.pb.cxx", "$BUILD/alltypes/alltypes.pb.c", c)
env.Command("encode_alltypes.cxx", "$BUILD/alltypes/encode_alltypes.c", c)
env.Command("decode_alltypes.cxx", "$BUILD/alltypes/decode_alltypes.c", c)
# Now build and run the test normally.
enc = env.Program(["encode_alltypes.cxx", "alltypes.pb.cxx", "pb_encode.cxx"])

View File

@@ -1,4 +1,4 @@
Import('env')
p = env.Program(["decode_unittests.c", "#common/unittestproto.pb.c"])
p = env.Program(["decode_unittests.c", "$COMMON/unittestproto.pb.c"])
env.RunTest(p)

View File

@@ -1,5 +1,5 @@
# Build and run the stand-alone unit tests for the nanopb encoder part.
Import('env')
p = env.Program(["encode_unittests.c", "#common/unittestproto.pb.c"])
p = env.Program(["encode_unittests.c", "$COMMON/unittestproto.pb.c"])
env.RunTest(p)

View File

@@ -4,12 +4,12 @@ Import("env")
# We use the files from the alltypes test case
incpath = env.Clone()
incpath.Append(PROTOCPATH = '#alltypes')
incpath.Append(CPPPATH = '#alltypes')
incpath.Append(PROTOCPATH = '$BUILD/alltypes')
incpath.Append(CPPPATH = '$BUILD/alltypes')
incpath.NanopbProto("extensions")
enc = incpath.Program(["encode_extensions.c", "extensions.pb.c", "#alltypes/alltypes.pb$OBJSUFFIX", "#common/pb_encode.o"])
dec = incpath.Program(["decode_extensions.c", "extensions.pb.c", "#alltypes/alltypes.pb$OBJSUFFIX", "#common/pb_decode.o"])
incpath.NanopbProto(["extensions", "extensions.options"])
enc = incpath.Program(["encode_extensions.c", "extensions.pb.c", "$BUILD/alltypes/alltypes.pb$OBJSUFFIX", "$COMMON/pb_encode.o"])
dec = incpath.Program(["decode_extensions.c", "extensions.pb.c", "$BUILD/alltypes/alltypes.pb$OBJSUFFIX", "$COMMON/pb_decode.o"])
env.RunTest(enc)
env.RunTest([dec, "encode_extensions.output"])

View File

@@ -2,13 +2,13 @@
Import("env")
dec = env.GetBuildPath('#basic_buffer/${PROGPREFIX}decode_buffer${PROGSUFFIX}')
dec = env.GetBuildPath('$BUILD/basic_buffer/${PROGPREFIX}decode_buffer${PROGSUFFIX}')
env.RunTest('person_with_extra_field.output', [dec, "person_with_extra_field.pb"])
env.Compare(["person_with_extra_field.output", "person_with_extra_field.expected"])
dec = env.GetBuildPath('#basic_stream/${PROGPREFIX}decode_stream${PROGSUFFIX}')
dec = env.GetBuildPath('$BUILD/basic_stream/${PROGPREFIX}decode_stream${PROGSUFFIX}')
env.RunTest('person_with_extra_field_stream.output', [dec, "person_with_extra_field.pb"])
env.Compare(["person_with_extra_field_stream.output", "person_with_extra_field.expected"])
dec2 = env.GetBuildPath('#alltypes/${PROGPREFIX}decode_alltypes${PROGSUFFIX}')
dec2 = env.GetBuildPath('$BUILD/alltypes/${PROGPREFIX}decode_alltypes${PROGSUFFIX}')
env.RunTest('alltypes_with_extra_fields.output', [dec2, 'alltypes_with_extra_fields.pb'])

View File

@@ -7,10 +7,10 @@ Import("env")
c = Copy("$TARGET", "$SOURCE")
env.Command("pb_encode.c", "#../pb_encode.c", c)
env.Command("pb_decode.c", "#../pb_decode.c", c)
env.Command("encode_alltypes.c", "#alltypes/encode_alltypes.c", c)
env.Command("decode_alltypes.c", "#alltypes/decode_alltypes.c", c)
env.Command("encode_alltypes.c", "$BUILD/alltypes/encode_alltypes.c", c)
env.Command("decode_alltypes.c", "$BUILD/alltypes/decode_alltypes.c", c)
env.NanopbProto("alltypes")
env.NanopbProto(["alltypes", "alltypes.options"])
# Define the compilation options
opts = env.Clone()

View File

@@ -7,10 +7,10 @@ Import("env")
c = Copy("$TARGET", "$SOURCE")
env.Command("pb_encode.c", "#../pb_encode.c", c)
env.Command("pb_decode.c", "#../pb_decode.c", c)
env.Command("encode_alltypes.c", "#alltypes/encode_alltypes.c", c)
env.Command("decode_alltypes.c", "#alltypes/decode_alltypes.c", c)
env.Command("encode_alltypes.c", "$BUILD/alltypes/encode_alltypes.c", c)
env.Command("decode_alltypes.c", "$BUILD/alltypes/decode_alltypes.c", c)
env.NanopbProto("alltypes")
env.NanopbProto(["alltypes", "alltypes.options"])
# Define the compilation options
opts = env.Clone()

View File

@@ -3,6 +3,6 @@
Import("env")
env.NanopbProto("missing_fields")
test = env.Program(["missing_fields.c", "missing_fields.pb.c", "#common/pb_encode.o", "#common/pb_decode.o"])
test = env.Program(["missing_fields.c", "missing_fields.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_decode.o"])
env.RunTest(test)

View File

@@ -6,10 +6,10 @@ Import("env")
c = Copy("$TARGET", "$SOURCE")
env.Command("pb_encode.c", "#../pb_encode.c", c)
env.Command("pb_decode.c", "#../pb_decode.c", c)
env.Command("alltypes.pb.h", "#alltypes/alltypes.pb.h", c)
env.Command("alltypes.pb.c", "#alltypes/alltypes.pb.c", c)
env.Command("encode_alltypes.c", "#alltypes/encode_alltypes.c", c)
env.Command("decode_alltypes.c", "#alltypes/decode_alltypes.c", c)
env.Command("alltypes.pb.h", "$BUILD/alltypes/alltypes.pb.h", c)
env.Command("alltypes.pb.c", "$BUILD/alltypes/alltypes.pb.c", c)
env.Command("encode_alltypes.c", "$BUILD/alltypes/encode_alltypes.c", c)
env.Command("decode_alltypes.c", "$BUILD/alltypes/decode_alltypes.c", c)
# Define the compilation options
opts = env.Clone()