Exemple #1
0
 inline mtn::byte_t*
 encode_index_key(uint16_t             partition,
                  const mtn::byte_t*   bucket,
                  uint16_t             bucket_size,
                  const mtn::byte_t*   field,
                  uint16_t             field_size,
                  mtn_index_address_t value,
                  mtn_index_address_t offset,
                  mtn::byte_t*         output)
 {
     mtn::byte_t* pos = encode_parition(partition, &output[0]);
     pos = encode_bytes(bucket, bucket_size, pos);
     pos = encode_bytes(field, field_size, pos);
     pos = encode_uint128(value, pos);
     return encode_uint128(offset, pos);
 }
Exemple #2
0
static int gen_dump_string(struct parse_string *p,
			   const struct parse_struct *pinfo, 
			   const char *data, 
			   unsigned indent)
{
	const char *ptr = *(char **)data;
	char *s = encode_bytes(ptr, strlen(ptr));
	if (addtabbed(p, pinfo->name, indent) ||
	    addstr(p, " = ") ||
	    addchar(p,'{') ||
	    addstr(p, s) ||
	    addstr(p, "}\n")) {
		free(s);
		return -1;
	}
	FREE(s);
	return 0;
}
Exemple #3
0
/* dump a single non-array element, hanlding struct and enum */
static int gen_dump_one(struct parse_string *p, 
			 const struct parse_struct *pinfo,
			 const char *ptr,
			 unsigned indent)
{
	if (pinfo->dump_fn == gen_dump_char && pinfo->ptr_count == 1) {
		char *s = encode_bytes(ptr, strlen(ptr));
		if (addchar(p,'{') ||
		    addstr(p, s) ||
		    addstr(p, "}")) {
			free(s);
			return -1;
		}
		FREE(s);
		return 0;
	}

	return pinfo->dump_fn(p, ptr, indent);
}
Exemple #4
0
static size_t encode_strbuf(void *c, const void *hd, const char *buf,
                            size_t len, const upb_bufhandle *h) {
  UPB_UNUSED(hd);
  UPB_UNUSED(h);
  return encode_bytes(c, buf, len) ? len : 0;
}
Exemple #5
0
static bool encode_fixed32(upb_pb_encoder *e, uint32_t val) {
  // TODO(haberman): byte-swap for big endian.
  return encode_bytes(e, &val, sizeof(uint32_t));
}
Exemple #6
0
static bool encode_tag(upb_pb_encoder *e, const tag_t *tag) {
  return encode_bytes(e, tag->tag, tag->bytes);
}
Exemple #7
0
/* handle dumping of an array of arbitrary type */
static int gen_dump_array(struct parse_string *p,
			  const struct parse_struct *pinfo, 
			  const char *ptr,
			  int array_len,
			  int indent)
{
	int i, count=0;

	/* special handling of fixed length strings */
	if (array_len != 0 && 
	    pinfo->ptr_count == 0 &&
	    pinfo->dump_fn == gen_dump_char) {
		char *s = encode_bytes(ptr, array_len);
		if (!s) return -1;
			if (addtabbed(p, pinfo->name, indent) ||
				addstr(p, " = {") ||
				addstr(p, s) ||
				addstr(p, "}\n")) {
				free(s);
				return -1;
			}
		
				
		
		free(s);
		return 0;
	}

	for (i=0;i<array_len;i++) {
		const char *p2 = ptr;
		unsigned size = pinfo->size;

		/* generic pointer dereference */
		if (pinfo->ptr_count) {
			p2 = *(const char **)ptr;
			size = sizeof(void *);
		}
		
		if ((count || pinfo->ptr_count) && 
		    !(pinfo->flags & FLAG_ALWAYS) &&
		    all_zero(ptr, size)) {
			ptr += size;
			continue;
		}
		if (count == 0) {
			if (addtabbed(p, pinfo->name, indent) ||
			    addshort(p, " = %u:", i)) {
				return -1;
			}
		} else {
			if (addshort(p, ", %u:", i) != 0) {
				return -1;
			}
		}
		if (gen_dump_one(p, pinfo, p2, indent) != 0) {
			return -1;
		}
		ptr += size;
		count++;
	}
	if (count) {
		return addstr(p, "\n");
	}
	return 0;
}