upb_TextEncode.

pull/13171/head
Joshua Haberman 3 years ago
parent 0c541f3305
commit cd214fe73d
  1. 5
      python/message.c
  2. 1
      rename.sed
  3. 6
      tests/conformance_upb.c
  4. 8
      upb/bindings/lua/msg.c
  5. 2
      upb/text_encode.c
  6. 2
      upb/text_encode.h

@ -680,13 +680,12 @@ static PyObject* PyUpb_CMessage_ToString(PyUpb_CMessage* self) {
const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(msgdef));
char buf[1024];
int options = UPB_TXTENC_SKIPUNKNOWN;
size_t size = upb_text_encode(msg, msgdef, symtab, options, buf, sizeof(buf));
size_t size = upb_TextEncode(msg, msgdef, symtab, options, buf, sizeof(buf));
if (size < sizeof(buf)) {
return PyUnicode_FromStringAndSize(buf, size);
} else {
char* buf2 = malloc(size + 1);
size_t size2 =
upb_text_encode(msg, msgdef, symtab, options, buf2, size + 1);
size_t size2 = upb_TextEncode(msg, msgdef, symtab, options, buf2, size + 1);
assert(size == size2);
PyObject* ret = PyUnicode_FromStringAndSize(buf2, size2);
free(buf2);

@ -444,3 +444,4 @@ s/upb_extreg_new/upb_ExtensionRegistry_New/g;
s/upb_msg\b/upb_Message/g;
s/_upb_decode\b/upb_Decode/g;
s/upb_EncodeEx\b/upb_Encode/g;
s/upb_text_encode/upb_TextEncode/g;

@ -124,9 +124,9 @@ void serialize_text(const upb_Message* msg, const upb_MessageDef* m,
opts |= UPB_TXTENC_SKIPUNKNOWN;
}
len = upb_text_encode(msg, m, c->symtab, opts, NULL, 0);
len = upb_TextEncode(msg, m, c->symtab, opts, NULL, 0);
data = upb_Arena_Malloc(c->arena, len + 1);
len2 = upb_text_encode(msg, m, c->symtab, opts, data, len + 1);
len2 = upb_TextEncode(msg, m, c->symtab, opts, data, len + 1);
UPB_ASSERT(len == len2);
conformance_ConformanceResponse_set_text_payload(
c->response, upb_StringView_FromDataAndSize(data, len));
@ -262,7 +262,7 @@ void DoTest(const ctx* c) {
void debug_print(const char* label, const upb_Message* msg,
const upb_MessageDef* m, const ctx* c) {
char buf[512];
upb_text_encode(msg, m, c->symtab, UPB_TXTENC_SINGLELINE, buf, sizeof(buf));
upb_TextEncode(msg, m, c->symtab, UPB_TXTENC_SINGLELINE, buf, sizeof(buf));
fprintf(stderr, "%s: %s\n", label, buf);
}

@ -907,13 +907,13 @@ static int lupb_msg_tostring(lua_State* L) {
lua_getiuservalue(L, 1, LUPB_MSGDEF_INDEX);
m = lupb_MessageDef_check(L, -1);
size = upb_text_encode(msg, m, NULL, 0, buf, sizeof(buf));
size = upb_TextEncode(msg, m, NULL, 0, buf, sizeof(buf));
if (size < sizeof(buf)) {
lua_pushlstring(L, buf, size);
} else {
char* ptr = malloc(size + 1);
upb_text_encode(msg, m, NULL, 0, ptr, size + 1);
upb_TextEncode(msg, m, NULL, 0, ptr, size + 1);
lua_pushlstring(L, ptr, size);
free(ptr);
}
@ -1070,13 +1070,13 @@ static int lupb_textencode(lua_State* L) {
char buf[1024];
size_t size;
size = upb_text_encode(msg, m, NULL, options, buf, sizeof(buf));
size = upb_TextEncode(msg, m, NULL, options, buf, sizeof(buf));
if (size < sizeof(buf)) {
lua_pushlstring(L, buf, size);
} else {
char* ptr = malloc(size + 1);
upb_text_encode(msg, m, NULL, options, ptr, size + 1);
upb_TextEncode(msg, m, NULL, options, ptr, size + 1);
lua_pushlstring(L, ptr, size);
free(ptr);
}

@ -445,7 +445,7 @@ size_t txtenc_nullz(txtenc* e, size_t size) {
return ret;
}
size_t upb_text_encode(const upb_Message* msg, const upb_MessageDef* m,
size_t upb_TextEncode(const upb_Message* msg, const upb_MessageDef* m,
const upb_DefPool* ext_pool, int options, char* buf,
size_t size) {
txtenc e;

@ -53,7 +53,7 @@ enum {
* size (excluding NULL) is returned. This means that a return value >= |size|
* implies that the output was truncated. (These are the same semantics as
* snprintf()). */
size_t upb_text_encode(const upb_Message* msg, const upb_MessageDef* m,
size_t upb_TextEncode(const upb_Message* msg, const upb_MessageDef* m,
const upb_DefPool* ext_pool, int options, char* buf,
size_t size);

Loading…
Cancel
Save