MCPcopy Create free account
hub / github.com/cretz/stackparam / write_stack_map_table

Method write_stack_map_table

src/bytecode/io/writer.rs:258–291  ·  view source on GitHub ↗
(&mut self, table: &Vec<StackMapFrame>, cp: &ConstantPool)

Source from the content-addressed store, hash-verified

256 }
257
258 fn write_stack_map_table(&mut self, table: &Vec<StackMapFrame>, cp: &ConstantPool) -> Result<usize, Error> {
259 // attribute_name_index
260 self.write_u16(cp.get_utf8_index("StackMapTable") as u16)
261 // attribute_length = number_of_entries length (2) + sum of entries' length
262 .and(self.write_u32(2 + table.iter().map(|st| st.len()).fold(0, |acc, x| acc + x) as u32))
263 // number_of_entries
264 .and(self.write_u16(table.len() as u16))
265 // entries
266 .and(table.iter().fold(Ok(0), |_, x| {
267 match x {
268 &StackMapFrame::SameFrame { tag } => self.write_u8(tag),
269 &StackMapFrame::SameLocals1StackItemFrame{ tag, ref stack } => self.write_u8(tag).and(self.write_verification_type(stack)),
270 &StackMapFrame::SameLocals1StackItemFrameExtended { offset_delta, ref stack } => self.write_u8(247).and(self.write_u16(offset_delta)).and(self.write_verification_type(stack)),
271 &StackMapFrame::ChopFrame { tag, offset_delta } => self.write_u8(tag).and(self.write_u16(offset_delta)),
272 &StackMapFrame::SameFrameExtended { offset_delta } => self.write_u8(251).and(self.write_u16(offset_delta)),
273 &StackMapFrame::AppendFrame { tag, offset_delta, ref locals } => self.write_u8(tag).and(self.write_u16(offset_delta)).and(locals.iter().fold(Ok(0), |_, x| self.write_verification_type(x))),
274 &StackMapFrame::FullFrame { offset_delta, ref locals, ref stack } => {
275 // full frame tag
276 self.write_u8(255)
277 // offset_delta
278 .and(self.write_u16(offset_delta))
279 // number_of_locals
280 .and(self.write_u16(locals.len() as u16))
281 // locals
282 .and(locals.iter().fold(Ok(0), |_, x| self.write_verification_type(x)))
283 // number_of_stack_items
284 .and(self.write_u16(stack.len() as u16))
285 // stack
286 .and(stack.iter().fold(Ok(0), |_, x| self.write_verification_type(x)))
287 },
288 &StackMapFrame::FutureUse { tag } => self.write_u8(tag)
289 }
290 }))
291 }
292
293 fn write_verification_type(&mut self, info: &VerificationType) -> Result<usize, Error> {
294 match info {

Callers 1

write_attributeMethod · 0.80

Calls 6

write_u16Method · 0.80
get_utf8_indexMethod · 0.80
write_u32Method · 0.80
lenMethod · 0.80
write_u8Method · 0.80

Tested by

no test coverage detected