Lines Matching defs:buf

715 bool upb_decode(const char *buf, size_t size, void *msg, const upb_msglayout *l,
718 state.limit = buf + size;
726 decode_msg(&state, buf, msg, l);
746 static size_t upb_encode_varint(uint64_t val, char *buf) {
748 if (val < 128) { buf[0] = val; return 1; }
754 buf[i++] = byte;
764 char *buf, *ptr, *limit;
776 size_t old_size = e->limit - e->buf;
778 char *new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size);
783 memmove(new_buf + new_size - old_size, e->buf, old_size);
788 e->buf = new_buf;
795 CHK(UPB_LIKELY((size_t)(e->ptr - e->buf) >= bytes) ||
1145 e.buf = NULL;
4102 size_t getjsonname(const char *name, char *buf, size_t len) {
4108 if (dst < len) buf[dst - 1] = byte; \
4109 else if (dst == len) buf[dst - 1] = '\0'
5977 bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink sink) {
5981 handle.buf = buf;
5984 ret = (upb_bytessink_putbuf(sink, subc, buf, len, &handle) >= len);
7037 /* How many bytes can be safely read from d->ptr without reading past end-of-buf
7051 return d->bufstart_ofs + (d->ptr - d->buf);
7065 static bool in_buf(const char *p, const char *buf, const char *end) {
7066 return p >= buf && p <= end;
7077 if (delim_ofs <= (size_t)(d->end - d->buf)) {
7078 d->delim_end = d->buf + delim_ofs;
7086 static void switchtobuf(upb_pbdecoder *d, const char *buf, const char *end) {
7087 d->ptr = buf;
7088 d->buf = buf;
7093 static void advancetobuf(upb_pbdecoder *d, const char *buf, size_t len) {
7095 d->bufstart_ofs += (d->end - d->buf);
7096 switchtobuf(d, buf, buf + len);
7128 d->bufstart_ofs += (d->end - d->buf);
7137 int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf,
7156 buf = &dummy_char;
7164 * calculations assume that d->ptr/d->buf is relative to this. */
7165 d->buf_param = buf;
7167 if (!buf) {
7168 /* NULL buf is ok if its entire span is covered by the "skip" above, but
7178 switchtobuf(d, buf, buf + size);
7205 /* Checkpoint was in residual buf; no user bytes were consumed. */
7211 UPB_ASSERT(d->buf == d->buf_param || d->buf == &dummy_char);
7213 d->bufstart_ofs += (d->checkpoint - d->buf);
7230 /* Checkpoint was in residual buf; append user byte(s) to residual buf. */
7239 /* Checkpoint was in user buf; old residual bytes not needed. */
7255 /* Copies the next "bytes" bytes into "buf" and advances the stream.
7257 UPB_FORCEINLINE static void consumebytes(upb_pbdecoder *d, void *buf,
7260 memcpy(buf, d->ptr, bytes);
7267 UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf,
7270 consumebytes(d, buf, avail);
7277 consumebytes(d, (char *)buf + avail, bytes);
7290 UPB_FORCEINLINE static int32_t getbytes(upb_pbdecoder *d, void *buf,
7294 consumebytes(d, buf, bytes);
7297 return getbytes_slow(d, buf, bytes);
7301 UPB_NOINLINE static size_t peekbytes_slow(upb_pbdecoder *d, void *buf,
7304 memcpy(buf, d->ptr, ret);
7307 memcpy((char *)buf + ret, d->buf_param, copy);
7313 UPB_FORCEINLINE static size_t peekbytes(upb_pbdecoder *d, void *buf,
7316 memcpy(buf, d->ptr, bytes);
7319 return peekbytes_slow(d, buf, bytes);
7635 (int)(d->ptr - d->buf),
7638 (int)((d->top->end_ofs - d->bufstart_ofs) - (d->ptr - d->buf)),
7877 size_t upb_pbdecoder_decode(void *decoder, const void *group, const char *buf,
7879 int32_t result = upb_pbdecoder_resume(decoder, NULL, buf, size, handle);
7894 d->buf = d->residual;
8085 /* The output buffer and limit, and our current write position. "buf"
8088 char *buf, *ptr, *limit;
8110 static void putbuf(upb_pb_encoder *e, const char *buf, size_t len) {
8111 size_t n = upb_bytessink_putbuf(e->output_, e->subc, buf, len, NULL);
8125 size_t needed = bytes + (e->ptr - e->buf);
8126 size_t old_size = e->limit - e->buf;
8134 new_buf = upb_arena_realloc(e->arena, e->buf, old_size, new_size);
8140 e->ptr = new_buf + (e->ptr - e->buf);
8141 e->runbegin = new_buf + (e->runbegin - e->buf);
8143 e->buf = new_buf;
8165 putbuf(e, e->buf, e->ptr - e->buf);
8166 e->ptr = e->buf;
8248 char buf[UPB_PB_VARINT_MAX_LEN];
8250 const char *ptr = e->buf;
8252 size_t lenbytes = upb_vencode64(s->msglen, buf);
8253 putbuf(e, buf, lenbytes);
8258 e->ptr = e->buf;
8357 static bool encode_unknown(void *c, const void *hd, const char *buf,
8360 return encode_bytes(c, buf, len) && commit(c);
8381 static size_t encode_strbuf(void *c, const void *hd, const char *buf,
8385 return encode_bytes(c, buf, len) ? len : 0;
8524 e->buf = upb_arena_malloc(arena, initial_bufsize);
8528 if (!e->buf || !e->segbuf || !e->stack) {
8532 e->limit = e->buf + initial_bufsize;
8542 e->ptr = e->buf;
8597 static int putescaped(upb_textprinter *p, const char *buf, size_t len,
8601 const char *end = buf + len;
8608 for (; buf < end; buf++) {
8617 switch (*buf) {
8625 /* Note that if we emit \xNN and the buf character after that is a hex
8628 if ((!preserve_utf8 || (uint8_t)*buf < 0x80) &&
8629 (!isprint(*buf) || (last_hex_escape && isxdigit(*buf)))) {
8630 sprintf(dst, (use_hex ? "\\x%02x" : "\\%03o"), (uint8_t)*buf);
8634 *(dst++) = *buf; break;
8766 static size_t textprinter_putstr(void *closure, const void *hd, const char *buf,
8771 CHECK(putescaped(p, buf, len, upb_fielddef_type(f) == UPB_TYPE_STRING));
9056 size_t parse(void *closure, const void *hd, const char *buf, size_t size,
9584 static bool accumulate_append(upb_json_parser *p, const char *buf, size_t len,
9589 p->accumulated = buf;
9608 memcpy(p->accumulate_buf + p->accumulated_len, buf, len);
9668 static bool multipart_text(upb_json_parser *p, const char *buf, size_t len,
9677 if (!accumulate_append(p, buf, len, can_alias)) {
9684 upb_sink_putstring(p->top->sink, p->string_selector, buf, len, handle);
9899 /* |buf| is NULL-terminated. |buf| itself will never include quotes;
9901 static bool parse_number_from_buffer(upb_json_parser *p, const char *buf,
9903 size_t len = strlen(buf);
9904 const char *bufend = buf + len;
9913 if (len == 0 || buf[0] == ' ') {
9924 long val = strtol(buf, &end, 0);
9935 unsigned long val = strtoul(buf, &end, 0);
9948 long val = strtol(buf, &end, 0);
9976 if (len == strlen("Infinity") && strcmp(buf, "Infinity") == 0) {
9979 } else if (len == strlen("-Infinity") && strcmp(buf, "-Infinity") == 0) {
9982 val = strtod(buf, &end);
10024 const char *buf;
10032 buf = accumulate_getptr(p, &len);
10034 if (parse_number_from_buffer(p, buf, is_quoted)) {
10038 upb_status_seterrf(p->status, "error parsing number: %s", buf);
10243 const char *buf = accumulate_getptr(p, &len);
10254 upb_sink_putstring(inner->sink, sel, buf, len, NULL);
10261 if (strncmp(buf, "type.googleapis.com/", 20) == 0 && len > 20) {
10263 buf += 20;
10266 payload_type = upb_symtab_lookupmsg2(p->symtab, buf, len);
10269 p->status, "Cannot find packed type: %.*s\n", (int)len, buf);
10278 p->status, "Invalid type url: %.*s\n", (int)len, buf);
10321 const char *buf = accumulate_getptr(p, &len);
10324 ok = upb_enumdef_ntoi(enumdef, buf, len, &int_val);
10330 upb_status_seterrf(p->status, "Enum value unknown: '%.*s'", len, buf);
10408 const char *buf;
10423 buf = accumulate_getptr(p, &len);
10431 for (fraction_start = 0; fraction_start < len && buf[fraction_start] != '.';
10435 memcpy(seconds_buf, buf, fraction_start);
10459 memcpy(nanos_buf + 1, buf + fraction_start, len - fraction_start);
10497 const char *buf;
10504 buf = accumulate_getptr(p, &len);
10505 val = atoi(buf);
10594 const char *buf;
10607 buf = accumulate_getptr(p, &len);
10617 memcpy(nanos_buf + 1, buf, len);
10679 const char *buf;
10688 buf = accumulate_getptr(p, &len);
10690 if (buf[0] != 'Z') {
10691 if (sscanf(buf + 1, "%2d:00", &hours) != 1) {
10696 if (buf[0] == '+') {
10802 const char *buf = accumulate_getptr(p, &len);
10826 if (len == 4 && !strncmp(buf, "true", 4)) {
10830 } else if (len == 5 && !strncmp(buf, "false", 5)) {
10847 upb_sink_putstring(subsink, sel, buf, len, NULL);
10930 const char *buf = accumulate_getptr(p, &len);
10933 if (upb_strtable_lookup2(p->top->name_table, buf, len, &v)) {
10943 upb_status_seterrf(p->status, "No such field: %.*s\n", (int)len, buf);
10951 const char *buf = accumulate_getptr(p, &len);
10954 if (len == 5 && strncmp(buf, "@type", len) == 0) {
11796 size_t parse(void *closure, const void *hd, const char *buf, size_t size,
11805 const char *p = buf;
11806 const char *pe = buf + size;
11814 capture_resume(parser, buf);
12204 return p - buf;
12481 upb_json_printer *p, const char *buf, size_t len) {
12483 size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL);
12521 static void putstring(upb_json_printer *p, const char *buf, size_t len) {
12525 char c = buf[i];
12545 print_data(p, unescaped_run, &buf[i] - unescaped_run);
12553 unescaped_run = &buf[i];
12560 print_data(p, unescaped_run, &buf[len] - unescaped_run);
12573 static size_t fmt_double(double val, char* buf, size_t length) {
12576 strcpy(buf, inf);
12580 strcpy(buf, neginf);
12583 size_t n = _upb_snprintf(buf, length, "%.17g", val);
12589 static size_t fmt_float(float val, char* buf, size_t length) {
12590 size_t n = _upb_snprintf(buf, length, "%.8g", val);
12595 static size_t fmt_bool(bool val, char* buf, size_t length) {
12596 size_t n = _upb_snprintf(buf, length, "%s", (val ? "true" : "false"));
12601 static size_t fmt_int64_as_number(int64_t val, char* buf, size_t length) {
12602 size_t n = _upb_snprintf(buf, length, "%" PRId64, val);
12607 static size_t fmt_uint64_as_number(uint64_t val, char* buf, size_t length) {
12608 size_t n = _upb_snprintf(buf, length, "%" PRIu64, val);
12613 static size_t fmt_int64_as_string(int64_t val, char* buf, size_t length) {
12614 size_t n = _upb_snprintf(buf, length, "\"%" PRId64 "\"", val);
12619 static size_t fmt_uint64_as_string(uint64_t val, char* buf, size_t length) {
12620 size_t n = _upb_snprintf(buf, length, "\"%" PRIu64 "\"", val);