|
|
@ -29,13 +29,13 @@ namespace { |
|
|
|
void MessageNew(Context& ctx, const Descriptor& msg) { |
|
|
|
void MessageNew(Context& ctx, const Descriptor& msg) { |
|
|
|
switch (ctx.opts().kernel) { |
|
|
|
switch (ctx.opts().kernel) { |
|
|
|
case Kernel::kCpp: |
|
|
|
case Kernel::kCpp: |
|
|
|
ctx.Emit({{"new_thunk", Thunk(ctx, msg, "new")}}, R"rs( |
|
|
|
ctx.Emit({{"new_thunk", ThunkName(ctx, msg, "new")}}, R"rs( |
|
|
|
Self { inner: $pbr$::MessageInner { msg: unsafe { $new_thunk$() } } } |
|
|
|
Self { inner: $pbr$::MessageInner { msg: unsafe { $new_thunk$() } } } |
|
|
|
)rs"); |
|
|
|
)rs"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
case Kernel::kUpb: |
|
|
|
case Kernel::kUpb: |
|
|
|
ctx.Emit({{"new_thunk", Thunk(ctx, msg, "new")}}, R"rs( |
|
|
|
ctx.Emit({{"new_thunk", ThunkName(ctx, msg, "new")}}, R"rs( |
|
|
|
let arena = $pbr$::Arena::new(); |
|
|
|
let arena = $pbr$::Arena::new(); |
|
|
|
Self { |
|
|
|
Self { |
|
|
|
inner: $pbr$::MessageInner { |
|
|
|
inner: $pbr$::MessageInner { |
|
|
@ -53,13 +53,13 @@ void MessageNew(Context& ctx, const Descriptor& msg) { |
|
|
|
void MessageSerialize(Context& ctx, const Descriptor& msg) { |
|
|
|
void MessageSerialize(Context& ctx, const Descriptor& msg) { |
|
|
|
switch (ctx.opts().kernel) { |
|
|
|
switch (ctx.opts().kernel) { |
|
|
|
case Kernel::kCpp: |
|
|
|
case Kernel::kCpp: |
|
|
|
ctx.Emit({{"serialize_thunk", Thunk(ctx, msg, "serialize")}}, R"rs( |
|
|
|
ctx.Emit({{"serialize_thunk", ThunkName(ctx, msg, "serialize")}}, R"rs( |
|
|
|
unsafe { $serialize_thunk$(self.inner.msg) } |
|
|
|
unsafe { $serialize_thunk$(self.inner.msg) } |
|
|
|
)rs"); |
|
|
|
)rs"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
case Kernel::kUpb: |
|
|
|
case Kernel::kUpb: |
|
|
|
ctx.Emit({{"serialize_thunk", Thunk(ctx, msg, "serialize")}}, R"rs( |
|
|
|
ctx.Emit({{"serialize_thunk", ThunkName(ctx, msg, "serialize")}}, R"rs( |
|
|
|
let arena = $pbr$::Arena::new(); |
|
|
|
let arena = $pbr$::Arena::new(); |
|
|
|
let mut len = 0; |
|
|
|
let mut len = 0; |
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
@ -78,7 +78,7 @@ void MessageDeserialize(Context& ctx, const Descriptor& msg) { |
|
|
|
case Kernel::kCpp: |
|
|
|
case Kernel::kCpp: |
|
|
|
ctx.Emit( |
|
|
|
ctx.Emit( |
|
|
|
{ |
|
|
|
{ |
|
|
|
{"deserialize_thunk", Thunk(ctx, msg, "deserialize")}, |
|
|
|
{"deserialize_thunk", ThunkName(ctx, msg, "deserialize")}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
R"rs( |
|
|
|
R"rs( |
|
|
|
let success = unsafe { |
|
|
|
let success = unsafe { |
|
|
@ -94,7 +94,7 @@ void MessageDeserialize(Context& ctx, const Descriptor& msg) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
case Kernel::kUpb: |
|
|
|
case Kernel::kUpb: |
|
|
|
ctx.Emit({{"deserialize_thunk", Thunk(ctx, msg, "parse")}}, R"rs( |
|
|
|
ctx.Emit({{"deserialize_thunk", ThunkName(ctx, msg, "parse")}}, R"rs( |
|
|
|
let arena = $pbr$::Arena::new(); |
|
|
|
let arena = $pbr$::Arena::new(); |
|
|
|
let msg = unsafe { |
|
|
|
let msg = unsafe { |
|
|
|
$deserialize_thunk$(data.as_ptr(), data.len(), arena.raw()) |
|
|
|
$deserialize_thunk$(data.as_ptr(), data.len(), arena.raw()) |
|
|
@ -122,10 +122,10 @@ void MessageExterns(Context& ctx, const Descriptor& msg) { |
|
|
|
case Kernel::kCpp: |
|
|
|
case Kernel::kCpp: |
|
|
|
ctx.Emit( |
|
|
|
ctx.Emit( |
|
|
|
{ |
|
|
|
{ |
|
|
|
{"new_thunk", Thunk(ctx, msg, "new")}, |
|
|
|
{"new_thunk", ThunkName(ctx, msg, "new")}, |
|
|
|
{"delete_thunk", Thunk(ctx, msg, "delete")}, |
|
|
|
{"delete_thunk", ThunkName(ctx, msg, "delete")}, |
|
|
|
{"serialize_thunk", Thunk(ctx, msg, "serialize")}, |
|
|
|
{"serialize_thunk", ThunkName(ctx, msg, "serialize")}, |
|
|
|
{"deserialize_thunk", Thunk(ctx, msg, "deserialize")}, |
|
|
|
{"deserialize_thunk", ThunkName(ctx, msg, "deserialize")}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
R"rs( |
|
|
|
R"rs( |
|
|
|
fn $new_thunk$() -> $pbi$::RawMessage; |
|
|
|
fn $new_thunk$() -> $pbi$::RawMessage; |
|
|
@ -138,9 +138,9 @@ void MessageExterns(Context& ctx, const Descriptor& msg) { |
|
|
|
case Kernel::kUpb: |
|
|
|
case Kernel::kUpb: |
|
|
|
ctx.Emit( |
|
|
|
ctx.Emit( |
|
|
|
{ |
|
|
|
{ |
|
|
|
{"new_thunk", Thunk(ctx, msg, "new")}, |
|
|
|
{"new_thunk", ThunkName(ctx, msg, "new")}, |
|
|
|
{"serialize_thunk", Thunk(ctx, msg, "serialize")}, |
|
|
|
{"serialize_thunk", ThunkName(ctx, msg, "serialize")}, |
|
|
|
{"deserialize_thunk", Thunk(ctx, msg, "parse")}, |
|
|
|
{"deserialize_thunk", ThunkName(ctx, msg, "parse")}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
R"rs( |
|
|
|
R"rs( |
|
|
|
fn $new_thunk$(arena: $pbi$::RawArena) -> $pbi$::RawMessage; |
|
|
|
fn $new_thunk$(arena: $pbi$::RawArena) -> $pbi$::RawMessage; |
|
|
@ -160,7 +160,7 @@ void MessageDrop(Context& ctx, const Descriptor& msg) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Emit({{"delete_thunk", Thunk(ctx, msg, "delete")}}, R"rs( |
|
|
|
ctx.Emit({{"delete_thunk", ThunkName(ctx, msg, "delete")}}, R"rs( |
|
|
|
unsafe { $delete_thunk$(self.inner.msg); } |
|
|
|
unsafe { $delete_thunk$(self.inner.msg); } |
|
|
|
)rs"); |
|
|
|
)rs"); |
|
|
|
} |
|
|
|
} |
|
|
@ -173,8 +173,8 @@ void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, |
|
|
|
bool is_mut) { |
|
|
|
bool is_mut) { |
|
|
|
auto fieldName = field.name(); |
|
|
|
auto fieldName = field.name(); |
|
|
|
auto fieldType = field.type(); |
|
|
|
auto fieldType = field.type(); |
|
|
|
auto getter_thunk = Thunk(ctx, field, "get"); |
|
|
|
auto getter_thunk = ThunkName(ctx, field, "get"); |
|
|
|
auto setter_thunk = Thunk(ctx, field, "set"); |
|
|
|
auto setter_thunk = ThunkName(ctx, field, "set"); |
|
|
|
// If we're dealing with a Mut, the getter must be supplied
|
|
|
|
// If we're dealing with a Mut, the getter must be supplied
|
|
|
|
// self.inner.msg() whereas a View has to be supplied self.msg
|
|
|
|
// self.inner.msg() whereas a View has to be supplied self.msg
|
|
|
|
auto self = is_mut ? "self.inner.msg()" : "self.msg"; |
|
|
|
auto self = is_mut ? "self.inner.msg()" : "self.msg"; |
|
|
@ -552,10 +552,10 @@ void GenerateThunksCc(Context& ctx, const Descriptor& msg) { |
|
|
|
{{"abi", "\"C\""}, // Workaround for syntax highlight bug in VSCode.
|
|
|
|
{{"abi", "\"C\""}, // Workaround for syntax highlight bug in VSCode.
|
|
|
|
{"Msg", msg.name()}, |
|
|
|
{"Msg", msg.name()}, |
|
|
|
{"QualifiedMsg", cpp::QualifiedClassName(&msg)}, |
|
|
|
{"QualifiedMsg", cpp::QualifiedClassName(&msg)}, |
|
|
|
{"new_thunk", Thunk(ctx, msg, "new")}, |
|
|
|
{"new_thunk", ThunkName(ctx, msg, "new")}, |
|
|
|
{"delete_thunk", Thunk(ctx, msg, "delete")}, |
|
|
|
{"delete_thunk", ThunkName(ctx, msg, "delete")}, |
|
|
|
{"serialize_thunk", Thunk(ctx, msg, "serialize")}, |
|
|
|
{"serialize_thunk", ThunkName(ctx, msg, "serialize")}, |
|
|
|
{"deserialize_thunk", Thunk(ctx, msg, "deserialize")}, |
|
|
|
{"deserialize_thunk", ThunkName(ctx, msg, "deserialize")}, |
|
|
|
{"nested_msg_thunks", |
|
|
|
{"nested_msg_thunks", |
|
|
|
[&] { |
|
|
|
[&] { |
|
|
|
for (int i = 0; i < msg.nested_type_count(); ++i) { |
|
|
|
for (int i = 0; i < msg.nested_type_count(); ++i) { |
|
|
|