pub fn encode_to_bytecode_v2(bind_program: BindProgram) -> Result<Vec<u8>, BindProgramEncodeError> {
    let mut symbol_table_encoder = SymbolTableEncoder::new();
    let mut instruction_bytecode =
        encode_instructions(bind_program.instructions, &mut symbol_table_encoder)?;

    let mut bytecode: Vec<u8> = vec![];

    // Encode the header.
    bytecode.extend_from_slice(&BIND_MAGIC_NUM.to_be_bytes());
    bytecode.extend_from_slice(&BYTECODE_VERSION.to_le_bytes());

    // Encode the symbol table.
    bytecode.extend_from_slice(&SYMB_MAGIC_NUM.to_be_bytes());
    bytecode.extend_from_slice(&(symbol_table_encoder.bytecode.len() as u32).to_le_bytes());
    bytecode.append(&mut symbol_table_encoder.bytecode);

    // Encode the instruction section.
    bytecode.extend_from_slice(&INSTRUCTION_MAGIC_NUM.to_be_bytes());
    bytecode.extend_from_slice(&(instruction_bytecode.len() as u32).to_le_bytes());
    bytecode.append(&mut instruction_bytecode);

    Ok(bytecode)
}
/// Functions for encoding the new bytecode format. When the
/// old bytecode format is deleted, the "v2" should be removed from the names.
Functions for encoding the new bytecode format. When the
old bytecode format is deleted, the "v2" should be removed from the names.
Functions for encoding the new bytecode format . When the old bytecode format is deleted the " v2 " should be removed from the names .
pub fn encode_to_bytecode_v2(bind_program: BindProgram) -> Result<Vec<u8>, BindProgramEncodeError> {
    let mut symbol_table_encoder = SymbolTableEncoder::new();
    let mut instruction_bytecode =
        encode_instructions(bind_program.instructions, &mut symbol_table_encoder)?;
    let mut bytecode: Vec<u8> = vec![];
    // Encode the header.
    bytecode.extend_from_slice(&BIND_MAGIC_NUM.to_be_bytes());
    bytecode.extend_from_slice(&BYTECODE_VERSION.to_le_bytes());
    // Encode the symbol table.
    bytecode.extend_from_slice(&SYMB_MAGIC_NUM.to_be_bytes());
    bytecode.extend_from_slice(&(symbol_table_encoder.bytecode.len() as u32).to_le_bytes());
    bytecode.append(&mut symbol_table_encoder.bytecode);
    // Encode the instruction section.
    bytecode.extend_from_slice(&INSTRUCTION_MAGIC_NUM.to_be_bytes());
    bytecode.extend_from_slice(&(instruction_bytecode.len() as u32).to_le_bytes());
    bytecode.append(&mut instruction_bytecode);
    Ok(bytecode)
}
pub fn encode_to_bytecode_v2 ( bind_program : BindProgram ) -> Result < Vec < u8 > , BindProgramEncodeError > { let mut symbol_table_encoder = SymbolTableEncoder :: new ( ) ; let mut instruction_bytecode = encode_instructions ( bind_program . instructions , & mut symbol_table_encoder ) ? ; let mut bytecode : Vec < u8 > = vec ! [ ] ; // Encode the header. bytecode . extend_from_slice ( & BIND_MAGIC_NUM . to_be_bytes ( ) ) ; bytecode . extend_from_slice ( & BYTECODE_VERSION . to_le_bytes ( ) ) ; // Encode the symbol table. bytecode . extend_from_slice ( & SYMB_MAGIC_NUM . to_be_bytes ( ) ) ; bytecode . extend_from_slice ( & ( symbol_table_encoder . bytecode . len ( ) as u32 ) . to_le_bytes ( ) ) ; bytecode . append ( & mut symbol_table_encoder . bytecode ) ; // Encode the instruction section. bytecode . extend_from_slice ( & INSTRUCTION_MAGIC_NUM . to_be_bytes ( ) ) ; bytecode . extend_from_slice ( & ( instruction_bytecode . len ( ) as u32 ) . to_le_bytes ( ) ) ; bytecode . append ( & mut instruction_bytecode ) ; Ok ( bytecode ) }
Functions for encoding the new bytecode format.
Functions for encoding the new bytecode format .
bind_program
BindProgram
bind_program
BindProgram