• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PB_RETURN_ERROR函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PB_RETURN_ERROR函数的典型用法代码示例。如果您正苦于以下问题:C++ PB_RETURN_ERROR函数的具体用法?C++ PB_RETURN_ERROR怎么用?C++ PB_RETURN_ERROR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PB_RETURN_ERROR函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: pb_read

bool checkreturn pb_read(pb_istream_t *stream, uint8_t *buf, size_t count)
{
#ifndef PB_BUFFER_ONLY
	if (buf == NULL && stream->callback != buf_read)
	{
		/* Skip input bytes */
		uint8_t tmp[16];
		while (count > 16)
		{
			if (!pb_read(stream, tmp, 16))
				return false;
			
			count -= 16;
		}
		
		return pb_read(stream, tmp, count);
	}
#endif

    if (stream->bytes_left < count)
        PB_RETURN_ERROR(stream, "end-of-stream");
    
#ifndef PB_BUFFER_ONLY
    if (!stream->callback(stream, buf, count))
        PB_RETURN_ERROR(stream, "io error");
#else
    if (!buf_read(stream, buf, count))
        return false;
#endif
    
    stream->bytes_left -= count;
    return true;
}
开发者ID:Cribstone,项目名称:hardware-bitcoin-wallet,代码行数:33,代码来源:pb_decode.c


示例2: pb_decode_tag

static inline int  pb_decode_tag(pb_field_t *f)
{
    if (pb_decode_varint(f))
    {
        if(f->left == 0)
            f->eom = 1; // signal end-of-message
        return -1;
    }

    if (f->val.i64 == 0)
    {
        f->eom = 1; // Allow 0-terminated messages.
        PB_RETURN_ERROR(f, -2, "0-terminated msg");
    }

    f->tag = f->val.i64 >> 3;
    f->type = (pb_wire_type_t)(f->val.i32 & 7);

    DBGOUT("tag %u, type %u\n", f->tag, f->type);
    switch (f->type)
    {
        case PB_WT_VARINT: return pb_decode_varint(f);
        case PB_WT_FIXED64: return pb_decode_fixed64(f);
        case PB_WT_STRING: return pb_decode_string(f);
        case PB_WT_FIXED32: return pb_decode_fixed32(f);
        default: PB_RETURN_ERROR(f, -3, "invalid wire_type");
    }

    return 0;
}
开发者ID:EFLql,项目名称:conet,代码行数:30,代码来源:pbc.cpp


示例3: encode_basic_field

/* Encode a field with static or pointer allocation, i.e. one whose data
 * is available to the encoder directly. */
static bool checkreturn encode_basic_field(pb_ostream_t *stream,
    const pb_field_t *field, const void *pData)
{
    pb_encoder_t func;
    const void *pSize;
    bool implicit_has = true;
    
    func = PB_ENCODERS[PB_LTYPE(field->type)];
    
    if (field->size_offset)
        pSize = (const char*)pData + field->size_offset;
    else
        pSize = &implicit_has;

    if (PB_ATYPE(field->type) == PB_ATYPE_POINTER)
    {
        /* pData is a pointer to the field, which contains pointer to
         * the data. If the 2nd pointer is NULL, it is interpreted as if
         * the has_field was false.
         */
        
        pData = *(const void* const*)pData;
        implicit_has = (pData != NULL);
    }

    switch (PB_HTYPE(field->type))
    {
        case PB_HTYPE_REQUIRED:
            if (!pData)
                PB_RETURN_ERROR(stream, "missing required field");
            if (!pb_encode_tag_for_field(stream, field))
                return false;
            if (!func(stream, field, pData))
                return false;
            break;
        
        case PB_HTYPE_OPTIONAL:
            if (*(const bool*)pSize)
            {
                if (!pb_encode_tag_for_field(stream, field))
                    return false;
            
                if (!func(stream, field, pData))
                    return false;
            }
            break;
        
        case PB_HTYPE_REPEATED:
            if (!encode_array(stream, field, pData, *(const size_t*)pSize, func))
                return false;
            break;
        
        default:
            PB_RETURN_ERROR(stream, "invalid field type");
    }
    
    return true;
}
开发者ID:d0c-s4vage,项目名称:nanopb,代码行数:60,代码来源:pb_encode.c


示例4: pb_read

bool checkreturn pb_read(pb_istream_t *stream, uint8_t *buf, size_t count)
{
    if (stream->bytes_left < count)
        PB_RETURN_ERROR(stream, "end-of-stream");

    if (!stream->callback(stream, buf, count))
        PB_RETURN_ERROR(stream, "io error");

    stream->bytes_left -= count;
    return true;
}
开发者ID:ilyevsky,项目名称:beerduino,代码行数:11,代码来源:pb_decode.c


示例5: pb_encode_submessage

bool checkreturn pb_encode_submessage(pb_ostream_t *stream, const pb_field_t fields[], const void *src_struct)
{
    /* First calculate the message size using a non-writing substream. */
    pb_ostream_t substream = PB_OSTREAM_SIZING;
    size_t size;
    bool status;
    
    if (!pb_encode(&substream, fields, src_struct))
    {
#ifndef PB_NO_ERRMSG
        stream->errmsg = substream.errmsg;
#endif
        return false;
    }
    
    size = substream.bytes_written;
    
    if (!pb_encode_varint(stream, (uint64_t)size))
        return false;
    
    if (stream->callback == NULL)
        return pb_write(stream, NULL, size); /* Just sizing */
    
    if (stream->bytes_written + size > stream->max_size)
        PB_RETURN_ERROR(stream, "stream full");
        
    /* Use a substream to verify that a callback doesn't write more than
     * what it did the first time. */
    substream.callback = stream->callback;
    substream.state = stream->state;
    substream.max_size = size;
    substream.bytes_written = 0;
#ifndef PB_NO_ERRMSG
    substream.errmsg = NULL;
#endif
    
    status = pb_encode(&substream, fields, src_struct);
    
    stream->bytes_written += substream.bytes_written;
    stream->state = substream.state;
#ifndef PB_NO_ERRMSG
    stream->errmsg = substream.errmsg;
#endif
    
    if (substream.bytes_written != size)
        PB_RETURN_ERROR(stream, "submsg size changed");
    
    return status;
}
开发者ID:XYZeelab,项目名称:octotanuki,代码行数:49,代码来源:pb_encode.c


示例6: pb_enc_submessage

static bool checkreturn pb_enc_submessage(pb_ostream_t *stream, const pb_field_t *field, const void *src)
{
    if (field->ptr == NULL)
        PB_RETURN_ERROR(stream, "invalid field descriptor");
    
    return pb_encode_submessage(stream, (const pb_field_t*)field->ptr, src);
}
开发者ID:XYZeelab,项目名称:octotanuki,代码行数:7,代码来源:pb_encode.c


示例7: pb_encode_tag_for_field

bool checkreturn pb_encode_tag_for_field(pb_ostream_t *stream, const pb_field_t *field)
{
    pb_wire_type_t wiretype;
    switch (PB_LTYPE(field->type))
    {
        case PB_LTYPE_VARINT:
        case PB_LTYPE_UVARINT:
        case PB_LTYPE_SVARINT:
            wiretype = PB_WT_VARINT;
            break;
        
        case PB_LTYPE_FIXED32:
            wiretype = PB_WT_32BIT;
            break;
        
        case PB_LTYPE_FIXED64:
            wiretype = PB_WT_64BIT;
            break;
        
        case PB_LTYPE_BYTES:
        case PB_LTYPE_STRING:
        case PB_LTYPE_SUBMESSAGE:
            wiretype = PB_WT_STRING;
            break;
        
        default:
            PB_RETURN_ERROR(stream, "invalid field type");
    }
    
    return pb_encode_tag(stream, wiretype, field->tag);
}
开发者ID:XYZeelab,项目名称:octotanuki,代码行数:31,代码来源:pb_encode.c


示例8: pb_decode_varint32

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))
        return false;
    
    if (!(byte & 0x80))
    {
        /* Quick case, 1 byte value */
        result = byte;
    }
    else
    {
        /* Multibyte case */
        uint8_t bitpos = 7;
        result = byte & 0x7F;
        
        do
        {
            if (bitpos >= 32)
                PB_RETURN_ERROR(stream, "varint overflow");
            
            if (!pb_read(stream, &byte, 1))
                return false;
            
            result |= (uint32_t)(byte & 0x7F) << bitpos;
            bitpos = (uint8_t)(bitpos + 7);
        } while (byte & 0x80);
   }
   
   *dest = result;
   return true;
}
开发者ID:Cribstone,项目名称:hardware-bitcoin-wallet,代码行数:35,代码来源:pb_decode.c


示例9: read_raw_value

/* Read a raw value to buffer, for the purpose of passing it to callback as
 * a substream. Size is maximum size on call, and actual size on return.
 */
static bool checkreturn read_raw_value(pb_istream_t *stream, pb_wire_type_t wire_type, uint8_t *buf, size_t *size)
{
    size_t max_size = *size;
    switch (wire_type)
    {
    case PB_WT_VARINT:
        *size = 0;
        do
        {
            (*size)++;
            if (*size > max_size) return false;
            if (!pb_read(stream, buf, 1)) return false;
        } while (*buf++ & 0x80);
        return true;

    case PB_WT_64BIT:
        *size = 8;
        return pb_read(stream, buf, 8);

    case PB_WT_32BIT:
        *size = 4;
        return pb_read(stream, buf, 4);

    default:
        PB_RETURN_ERROR(stream, "invalid wire_type");
    }
}
开发者ID:ilyevsky,项目名称:beerduino,代码行数:30,代码来源:pb_decode.c


示例10: encode_dictionary

/* Parse a dictionary in format {'name': value} and encode it directly to protobuf */
static bool encode_dictionary(pb_ostream_t *stream, const pb_field_t *field, void * const *arg)
{
    int textlen;
    char *p = (char*)*arg;
    if (*p == '{') p++;
    while (*p != '}')
    {
        KeyValuePair pair = KeyValuePair_init_zero;
        
        if (*p != '\'')
            PB_RETURN_ERROR(stream, "invalid key, missing quote");
        
        p++; /* Starting quote of key */
        textlen = strchr(p, '\'') - p;
        strncpy(pair.key, p, textlen);
        pair.key[textlen] = 0;
        p += textlen + 2;
        
        while (*p == ' ') p++;
        
        if (*p == '[')
        {
            /* Value is a tree */
            pair.treeValue.funcs.encode = encode_tree;
            pair.treeValue.arg = p;
        }
        else if (*p == '\'')
        {
            /* Value is a string */
            pair.has_stringValue = true;
            p++;
            textlen = strchr(p, '\'') - p;
            strncpy(pair.stringValue, p, textlen);
            pair.stringValue[textlen] = 0;
        }
        else if (*p == '{')
        {
            /* Value is a dictionary */
            pair.has_dictValue = true;
            pair.dictValue.dictItem.funcs.encode = encode_dictionary;
            pair.dictValue.dictItem.arg = p;
        }
        else
        {
            /* Value is integer */
            pair.has_intValue = true;
            pair.intValue = atoi(p);
        }
        
        p = find_end_of_item(p);
        
        if (!pb_encode_tag_for_field(stream, field))
            return false;
        
        if (!pb_encode_submessage(stream, KeyValuePair_fields, &pair))
            return false;
    }

    return true;
}
开发者ID:01org,项目名称:CODK-A-Firmware,代码行数:61,代码来源:encode_cyclic_callback.c


示例11: pb_readbyte

/* 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;    
}
开发者ID:HargicStudio,项目名称:SmartCup_MiCOKit_v2.4.0.0,代码行数:19,代码来源:pb_decode.c


示例12: pb_enc_bytes

bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *src)
{
    const pb_bytes_array_t *bytes = (const pb_bytes_array_t*)src;

    if (bytes->size + offsetof(pb_bytes_array_t, bytes) > field->data_size)
        PB_RETURN_ERROR(stream, "bytes size exceeded");
    
    return pb_encode_string(stream, bytes->bytes, bytes->size);
}
开发者ID:BrotherPhil,项目名称:hardware-bitcoin-wallet,代码行数:9,代码来源:pb_encode.c


示例13: pb_write

bool checkreturn pb_write(pb_ostream_t *stream, const uint8_t *buf, size_t count)
{
    if (stream->callback != NULL)
    {
        if (stream->bytes_written + count > stream->max_size)
            PB_RETURN_ERROR(stream, "stream full");

#ifdef PB_BUFFER_ONLY
        if (!buf_write(stream, buf, count))
            PB_RETURN_ERROR(stream, "io error");
#else        
        if (!stream->callback(stream, buf, count))
            PB_RETURN_ERROR(stream, "io error");
#endif
    }
    
    stream->bytes_written += count;
    return true;
}
开发者ID:XYZeelab,项目名称:octotanuki,代码行数:19,代码来源:pb_encode.c


示例14: pb_get_byte

static inline int  pb_get_byte(pb_field_t *f, uint8_t *buf)
{
    if (f->left < 1)
        PB_RETURN_ERROR(f, -1, "end-of-buffer");

    if(buf) *buf = *(uint8_t*)f->ptr;
    f->ptr += 1;
    f->left -= 1;
    return 0;
}
开发者ID:EFLql,项目名称:conet,代码行数:10,代码来源:pbc.cpp


示例15: pb_get_ddword

static inline int  pb_get_ddword(pb_field_t *f, uint64_t *buf)
{
    if (f->left < 8)
        PB_RETURN_ERROR(f, -1, "end-of-buffer");

    if(buf) *buf = *(uint64_t*)f->ptr;
    f->ptr += 8;
    f->left -= 8;
    return 0;
}
开发者ID:EFLql,项目名称:conet,代码行数:10,代码来源:pbc.cpp


示例16: pb_skip_field

int  pb_skip_field(pb_field_t *f, pb_wire_type_t wire_type)
{
    switch (wire_type)
    {
        case PB_WT_VARINT: return pb_skip_varint(f);
        case PB_WT_FIXED64: return pb_get_ddword(f, NULL);
        case PB_WT_STRING: return pb_skip_string(f);
        case PB_WT_FIXED32: return pb_get_dword(f, NULL);
        default: PB_RETURN_ERROR(f, -1, "invalid wire_type");
    }
}
开发者ID:EFLql,项目名称:conet,代码行数:11,代码来源:pbc.cpp


示例17: pb_skip_field

bool checkreturn pb_skip_field(pb_istream_t *stream, pb_wire_type_t wire_type)
{
    switch (wire_type)
    {
        case PB_WT_VARINT: return pb_skip_varint(stream);
        case PB_WT_64BIT: return pb_read(stream, NULL, 8);
        case PB_WT_STRING: return pb_skip_string(stream);
        case PB_WT_32BIT: return pb_read(stream, NULL, 4);
        default: PB_RETURN_ERROR(stream, "invalid wire_type");
    }
}
开发者ID:Cribstone,项目名称:hardware-bitcoin-wallet,代码行数:11,代码来源:pb_decode.c


示例18: pb_get

static inline int  pb_get(pb_field_t *f, uint8_t *buf, size_t count)
{
    if ((size_t )f->left < count)
        PB_RETURN_ERROR(f, -1, "end-of-buffer");

    if(buf) memcpy(buf, f->ptr, count);
    f->ptr += count;
    f->left -= count;

    return 0;
}
开发者ID:EFLql,项目名称:conet,代码行数:11,代码来源:pbc.cpp


示例19: pb_add_ddword

static inline int  pb_add_ddword(pb_buff_t *b, uint64_t val)
{
    if(b->left < 8)
        PB_RETURN_ERROR(b, -1, "buf overflow");

    *(uint64_t*)b->ptr = val;
    DBGOUT("add_ddword: %02x %02x %02x %02x %02x %02x %02x %02x\n", b->ptr[0], b->ptr[1], b->ptr[2], b->ptr[3], b->ptr[4], b->ptr[5], b->ptr[6], b->ptr[7]);
    b->ptr += 8;
    b->left -= 8;

    return 0;
}
开发者ID:EFLql,项目名称:conet,代码行数:12,代码来源:pbc.cpp


示例20: pb_add_byte

/*
static inline int  pb_add_byte(pb_buff_t *b, const uint8_t *buf)
{
    if(b->left < 1)
        PB_RETURN_ERROR(b, -1, "buf overflow");

    *(uint8_t*)b->ptr = *buf;
    b->ptr += 1;
    b->left -= 1;

    DBGOUT("add_byte: %02x\n", *buf);
    return 0;
}
*/
static inline int  pb_add_dword(pb_buff_t *b, uint32_t val)
{
    if(b->left < 4)
        PB_RETURN_ERROR(b, -1, "buf overflow");

    *(uint32_t*)b->ptr = val;
    DBGOUT("add_dword: %02x %02x %02x %02x\n", b->ptr[0], b->ptr[1], b->ptr[2], b->ptr[3]);
    b->ptr += 4;
    b->left -= 4;

    return 0;
}
开发者ID:EFLql,项目名称:conet,代码行数:26,代码来源:pbc.cpp



注:本文中的PB_RETURN_ERROR函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PCGetOperators函数代码示例发布时间:2022-05-30
下一篇:
C++ PBL_IF_ROUND_ELSE函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap