A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/protocolbuffers/protobuf/commit/e2fd7a0d9d9bd1daaf377f30cb55bbbb7abbf278 below:

Add [clear_and_]parse_dont_enforce_required() to Rust protobuf. · protocolbuffers/protobuf@e2fd7a0 · GitHub

@@ -111,10 +111,14 @@ void MessageMutClear(Context& ctx, const Descriptor& msg) {

111 111

}

112 112

}

113 113 114 -

void MessageMutClearAndParse(Context& ctx, const Descriptor& msg) {

114 +

void MessageMutClearAndParse(Context& ctx, const Descriptor& msg,

115 +

bool enforce_required) {

115 116

switch (ctx.opts().kernel) {

116 -

case Kernel::kCpp:

117 -

ctx.Emit({},

117 +

case Kernel::kCpp: {

118 +

absl::string_view parse_function =

119 +

enforce_required ? "proto2_rust_Message_parse"

120 +

: "proto2_rust_Message_parse_dont_enforce_required";

121 +

ctx.Emit({{"parse_function", parse_function}},

118 122

R"rs(

119 123

let success = unsafe {

120 124

// SAFETY: `data.as_ptr()` is valid to read for `data.len()`.

@@ -123,34 +127,41 @@ void MessageMutClearAndParse(Context& ctx, const Descriptor& msg) {

123 127

data.len(),

124 128

);

125 129 126 -

$pbr$::proto2_rust_Message_parse(self.raw_msg(), data)

130 +

$pbr$::$parse_function$(self.raw_msg(), data)

127 131

};

128 132

success.then_some(()).ok_or($pb$::ParseError)

129 133

)rs");

130 134

return;

131 - 132 -

case Kernel::kUpb:

133 -

ctx.Emit(

134 -

R"rs(

135 +

}

136 + 137 +

case Kernel::kUpb: {

138 +

absl::string_view decode_options =

139 +

enforce_required ? "$pbr$::wire::decode_options::CHECK_REQUIRED"

140 +

: "0";

141 +

ctx.Emit({{"decode_options",

142 +

[&ctx, decode_options] { ctx.Emit(decode_options); }}},

143 +

R"rs(

135 144

$pb$::Clear::clear(self);

136 145 137 146

// SAFETY:

138 147

// - `data.as_ptr()` is valid to read for `data.len()`

139 148

// - `mini_table` is the one used to construct `msg.raw_msg()`

140 149

// - `msg.arena().raw()` is held for the same lifetime as `msg`.

141 150

let status = unsafe {

142 -

$pbr$::wire::decode(

151 +

$pbr$::wire::decode_with_options(

143 152

data,

144 153

self.raw_msg(),

145 154

<Self as $pbr$::AssociatedMiniTable>::mini_table(),

146 -

self.arena())

155 +

self.arena(),

156 +

$decode_options$)

147 157

};

148 158

match status {

149 159

Ok(_) => Ok(()),

150 160

Err(_) => Err($pb$::ParseError),

151 161

}

152 162

)rs");

153 163

return;

164 +

}

154 165

}

155 166 156 167

ABSL_LOG(FATAL) << "unreachable";

@@ -700,7 +711,13 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {

700 711

{"Msg::serialize", [&] { MessageSerialize(ctx, msg); }},

701 712

{"MsgMut::clear", [&] { MessageMutClear(ctx, msg); }},

702 713

{"MsgMut::clear_and_parse",

703 -

[&] { MessageMutClearAndParse(ctx, msg); }},

714 +

[&] {

715 +

MessageMutClearAndParse(ctx, msg, /*enforce_required=*/true);

716 +

}},

717 +

{"MsgMut::clear_and_parse_dont_enforce_required",

718 +

[&] {

719 +

MessageMutClearAndParse(ctx, msg, /*enforce_required=*/false);

720 +

}},

704 721

{"Msg::drop", [&] { MessageDrop(ctx, msg); }},

705 722

{"Msg::debug", [&] { MessageDebug(ctx, msg); }},

706 723

{"MsgMut::take_copy_merge_from",

@@ -830,6 +847,10 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {

830 847

fn parse(serialized: &[u8]) -> $Result$<Self, $pb$::ParseError> {

831 848

Self::parse(serialized)

832 849

}

850 + 851 +

fn parse_dont_enforce_required(serialized: &[u8]) -> $Result$<Self, $pb$::ParseError> {

852 +

Self::parse_dont_enforce_required(serialized)

853 +

}

833 854

}

834 855 835 856

impl $std$::fmt::Debug for $Msg$ {

@@ -877,6 +898,11 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {

877 898

let mut m = self.as_mut();

878 899

$pb$::ClearAndParse::clear_and_parse(&mut m, data)

879 900

}

901 + 902 +

fn clear_and_parse_dont_enforce_required(&mut self, data: &[u8]) -> $Result$<(), $pb$::ParseError> {

903 +

let mut m = self.as_mut();

904 +

$pb$::ClearAndParse::clear_and_parse_dont_enforce_required(&mut m, data)

905 +

}

880 906

}

881 907 882 908

// SAFETY:

@@ -1014,6 +1040,10 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {

1014 1040

fn clear_and_parse(&mut self, data: &[u8]) -> $Result$<(), $pb$::ParseError> {

1015 1041

$MsgMut::clear_and_parse$

1016 1042

}

1043 + 1044 +

fn clear_and_parse_dont_enforce_required(&mut self, data: &[u8]) -> $Result$<(), $pb$::ParseError> {

1045 +

$MsgMut::clear_and_parse_dont_enforce_required$

1046 +

}

1017 1047

}

1018 1048 1019 1049

$MsgMut::take_copy_merge_from$

@@ -1116,6 +1146,11 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {

1116 1146

$pb$::ClearAndParse::clear_and_parse(&mut msg, data).map(|_| msg)

1117 1147

}

1118 1148 1149 +

pub fn parse_dont_enforce_required(data: &[u8]) -> $Result$<Self, $pb$::ParseError> {

1150 +

let mut msg = Self::new();

1151 +

$pb$::ClearAndParse::clear_and_parse_dont_enforce_required(&mut msg, data).map(|_| msg)

1152 +

}

1153 + 1119 1154

pub fn as_view(&self) -> $Msg$View {

1120 1155

$Msg$View::new($pbi$::Private, self.inner.msg)

1121 1156

}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4