MCPcopy Create free account
hub / github.com/diem/move / load_function_def

Function load_function_def

language/move-binary-format/src/deserializer.rs:1251–1323  ·  view source on GitHub ↗

Deserializes a `FunctionDefinition`.

(cursor: &mut VersionedCursor)

Source from the content-addressed store, hash-verified

1249
1250/// Deserializes a `FunctionDefinition`.
1251fn load_function_def(cursor: &mut VersionedCursor) -> BinaryLoaderResult<FunctionDefinition> {
1252 let function = load_function_handle_index(cursor)?;
1253
1254 let mut flags = cursor.read_u8().map_err(|_| {
1255 PartialVMError::new(StatusCode::MALFORMED).with_message("Unexpected EOF".to_string())
1256 })?;
1257
1258 // NOTE: changes compared with VERSION_1
1259 // - in VERSION_1: the flags is a byte compositing both the visibility info and whether
1260 // the function is a native function
1261 // - in VERSION_2 onwards: the flags only represent the visibility info and we need to
1262 // advance the cursor to read up the next byte as flags
1263 // - in VERSION_5 onwards: script visibility has been deprecated for an entry function flag
1264 let (visibility, is_entry, mut extra_flags) = if cursor.version() == VERSION_1 {
1265 let vis = if (flags & FunctionDefinition::DEPRECATED_PUBLIC_BIT) != 0 {
1266 flags ^= FunctionDefinition::DEPRECATED_PUBLIC_BIT;
1267 Visibility::Public
1268 } else {
1269 Visibility::Private
1270 };
1271 (vis, false, flags)
1272 } else if cursor.version() < VERSION_5 {
1273 let (vis, is_entry) = if flags == Visibility::DEPRECATED_SCRIPT {
1274 (Visibility::Public, true)
1275 } else {
1276 let vis = flags.try_into().map_err(|_| {
1277 PartialVMError::new(StatusCode::MALFORMED)
1278 .with_message("Invalid visibility byte".to_string())
1279 })?;
1280 (vis, false)
1281 };
1282 let extra_flags = cursor.read_u8().map_err(|_| {
1283 PartialVMError::new(StatusCode::MALFORMED).with_message("Unexpected EOF".to_string())
1284 })?;
1285 (vis, is_entry, extra_flags)
1286 } else {
1287 let vis = flags.try_into().map_err(|_| {
1288 PartialVMError::new(StatusCode::MALFORMED)
1289 .with_message("Invalid visibility byte".to_string())
1290 })?;
1291
1292 let mut extra_flags = cursor.read_u8().map_err(|_| {
1293 PartialVMError::new(StatusCode::MALFORMED).with_message("Unexpected EOF".to_string())
1294 })?;
1295 let is_entry = (extra_flags & FunctionDefinition::ENTRY) != 0;
1296 if is_entry {
1297 extra_flags ^= FunctionDefinition::ENTRY;
1298 }
1299 (vis, is_entry, extra_flags)
1300 };
1301
1302 let acquires_global_resources = load_struct_definition_indices(cursor)?;
1303 let code_unit = if (extra_flags & FunctionDefinition::NATIVE) != 0 {
1304 extra_flags ^= FunctionDefinition::NATIVE;
1305 None
1306 } else {
1307 Some(load_code_unit(cursor)?)
1308 };

Callers 1

load_function_defsFunction · 0.85

Calls 8

load_code_unitFunction · 0.85
read_u8Method · 0.80
with_messageMethod · 0.80
to_stringMethod · 0.80
versionMethod · 0.45
try_intoMethod · 0.45

Tested by

no test coverage detected