pub fn utf8_decode(mybuf: & mut EightBytes, last_buffer: bool) -> Utf8EndEnum {
    match mybuf.front() {
        Option::Some(v) => {
            let v1 = v as u32;
            // println!("in start state with v1={:#02x} and len()={}", v1, mybuf.len());
            if v1 < 0xE0 {
                if v1 < 0xC2 {
                    mybuf.pop_front();
                    if v1 < 0x80 {
                        // Action 0
                        // 1 byte format: code point from 0x0 to 0x7F
                        // println!("in action 0 with v1={:#02x}", v1);
                        Utf8EndEnum::Finish(v1)
                    }
                    else {
                        // 80 to C1: not valid first byte
                        // println!("80 to C1 bad decode");
                        Utf8EndEnum::BadDecode(1)
                    }
                }
                else {
                    // Byte 1 is between 0xC2 and 0xDF
                    // 2 byte format
                    if (mybuf.len() < 2) && ! last_buffer {
                        // We wait for more bytes if not the last buffer.
                        // Our design cannot back-out procesed bytes.
                        // println!("TypeUnknown");
                        Utf8EndEnum::TypeUnknown
                    }
                    else {
                        // Action 1
                        // println!("in action 1 with v1={:#02x}", v1);
                        mybuf.pop_front();
                        byte2_action9(mybuf, v1 & 0x1F)
                    }
                }
            }
            else {
                if v1 < 0xF0 {
                    // 3 byte format
                    // Byte 1 is between 0xE0 and 0xEF
                    if (mybuf.len() < 3) && ! last_buffer {
                        // We wait for more bytes if not the last buffer.
                        // Our design cannot back-out procesed bytes.
                        // println!("TypeUnknown");
                        Utf8EndEnum::TypeUnknown
                    }
                    else if v1 < 0xED {
                        mybuf.pop_front();
                        if v1 == 0xE0 {
                            // Action 2
                            // v1 is 0xE0.
                            // println!("in action 2 with v1={:#02x}", v1);
                            byte2_action14(mybuf, v1 & 0xF)
                        }
                        else {
                            // Action 3
                            // v1 is between 0xE1 and 0xEC.
                            // println!("in action 3 with v1={:#02x}", v1);
                            byte2_action10(mybuf, v1 & 0xF)
                        }
                    }
                    else {
                        mybuf.pop_front();
                        if v1 == 0xED {
                            // Action 4
                            // println!("in action 4 with v1={:#02x}", v1);
                            byte2_action15(mybuf, v1 & 0xF)
                        }
                        else {
                            // Action 5
                            // v1 is 0xEE or 0xEF.
                            // println!("in action 5 with v1={:#02x}", v1);
                            byte2_action11(mybuf, v1 & 0xF)
                        }
                    }
                }
                else {
                    // 4 byte cases if byte 1 is between 0xF0 and 0xF4
                    if v1 > 0xF4 {
                        // codepoint too large
                        // println!("greater than F4 bad decode");
                        mybuf.pop_front();
                        Utf8EndEnum::BadDecode(1)
                    }
                    else if (mybuf.len() < 4) && ! last_buffer {
                        // We wait for more bytes if not the last buffer.
                        // Our design cannot back-out procesed bytes.
                        // println!("TypeUnknown");
                        Utf8EndEnum::TypeUnknown
                    }
                    else {
                        mybuf.pop_front();
                        if v1 == 0xF0 {
                            // Action 6
                            // println!("in action 6 with v1={:#02x}", v1);
                            byte2_action16(mybuf, v1 & 0x7)
                        }
                        else if v1 < 0xF4 {
                            // Action 7
                            // Byte 1 is between 0xF1 and 0xF3.
                            // println!("in action 7 with v1={:#02x}", v1);
                            byte2_action12(mybuf, v1 & 0x7)
                        }
                        else {
                            // Action 8
                            // Byte 1 is 0xF4.
                            // println!("in action 8 with v1={:#02x}", v1);
                            byte2_action13(mybuf, v1 & 0x7)
                        }
                    }
                }
            }
        }
        Option::None => {
            // println!("TypeUnknown");
            Utf8EndEnum::TypeUnknown
        }
    }
}
/// Decode from UTF8 to Unicode code point using a finate state machine.
///
/// # Arguments
///
/// * `mybuf` - contains the bytes to be decoded
///
/// * `last_buffer` - is true when we are working on the last byte buffer.
///
/// When 'last_buffer' is false, with additional buffers to be processed,
/// then the parser would refuse to work on potential partial decodes,
/// and returns Utf8EndEnum::TypeUnknown to ask for more data.
///
/// When 'last_buffer' is true, with no more data to process than
/// what is available in 'mybuf', then partial decodes results in
/// Utf8EndEnum:BadDecode(n) where n is length of error from 1 to 3 bytes.

Decode from UTF8 to Unicode code point using a finate state machine.
Decode from UTF8 to Unicode code point using a finate state machine .
pub fn utf8_decode(mybuf: & mut EightBytes, last_buffer: bool) -> Utf8EndEnum {
    match mybuf.front() {
        Option::Some(v) => {
            let v1 = v as u32;
            // println!("in start state with v1={:#02x} and len()={}", v1, mybuf.len());
            if v1 < 0xE0 {
                if v1 < 0xC2 {
                    mybuf.pop_front();
                    if v1 < 0x80 {
                        // Action 0
                        // 1 byte format: code point from 0x0 to 0x7F
                        // println!("in action 0 with v1={:#02x}", v1);
                        Utf8EndEnum::Finish(v1)
                    }
                    else {
                        // 80 to C1: not valid first byte
                        // println!("80 to C1 bad decode");
                        Utf8EndEnum::BadDecode(1)
                    }
                }
                else {
                    // Byte 1 is between 0xC2 and 0xDF
                    // 2 byte format
                    if (mybuf.len() < 2) && ! last_buffer {
                        // We wait for more bytes if not the last buffer.
                        // Our design cannot back-out procesed bytes.
                        // println!("TypeUnknown");
                        Utf8EndEnum::TypeUnknown
                    }
                    else {
                        // Action 1
                        // println!("in action 1 with v1={:#02x}", v1);
                        mybuf.pop_front();
                        byte2_action9(mybuf, v1 & 0x1F)
                    }
                }
            }
            else {
                if v1 < 0xF0 {
                    // 3 byte format
                    // Byte 1 is between 0xE0 and 0xEF
                    if (mybuf.len() < 3) && ! last_buffer {
                        // We wait for more bytes if not the last buffer.
                        // Our design cannot back-out procesed bytes.
                        // println!("TypeUnknown");
                        Utf8EndEnum::TypeUnknown
                    }
                    else if v1 < 0xED {
                        mybuf.pop_front();
                        if v1 == 0xE0 {
                            // Action 2
                            // v1 is 0xE0.
                            // println!("in action 2 with v1={:#02x}", v1);
                            byte2_action14(mybuf, v1 & 0xF)
                        }
                        else {
                            // Action 3
                            // v1 is between 0xE1 and 0xEC.
                            // println!("in action 3 with v1={:#02x}", v1);
                            byte2_action10(mybuf, v1 & 0xF)
                        }
                    }
                    else {
                        mybuf.pop_front();
                        if v1 == 0xED {
                            // Action 4
                            // println!("in action 4 with v1={:#02x}", v1);
                            byte2_action15(mybuf, v1 & 0xF)
                        }
                        else {
                            // Action 5
                            // v1 is 0xEE or 0xEF.
                            // println!("in action 5 with v1={:#02x}", v1);
                            byte2_action11(mybuf, v1 & 0xF)
                        }
                    }
                }
                else {
                    // 4 byte cases if byte 1 is between 0xF0 and 0xF4
                    if v1 > 0xF4 {
                        // codepoint too large
                        // println!("greater than F4 bad decode");
                        mybuf.pop_front();
                        Utf8EndEnum::BadDecode(1)
                    }
                    else if (mybuf.len() < 4) && ! last_buffer {
                        // We wait for more bytes if not the last buffer.
                        // Our design cannot back-out procesed bytes.
                        // println!("TypeUnknown");
                        Utf8EndEnum::TypeUnknown
                    }
                    else {
                        mybuf.pop_front();
                        if v1 == 0xF0 {
                            // Action 6
                            // println!("in action 6 with v1={:#02x}", v1);
                            byte2_action16(mybuf, v1 & 0x7)
                        }
                        else if v1 < 0xF4 {
                            // Action 7
                            // Byte 1 is between 0xF1 and 0xF3.
                            // println!("in action 7 with v1={:#02x}", v1);
                            byte2_action12(mybuf, v1 & 0x7)
                        }
                        else {
                            // Action 8
                            // Byte 1 is 0xF4.
                            // println!("in action 8 with v1={:#02x}", v1);
                            byte2_action13(mybuf, v1 & 0x7)
                        }
                    }
                }
            }
        }
        Option::None => {
            // println!("TypeUnknown");
            Utf8EndEnum::TypeUnknown
        }
    }
}
pub fn utf8_decode ( mybuf : & mut EightBytes , last_buffer : bool ) -> Utf8EndEnum { match mybuf . front ( ) { Option :: Some ( v ) => { let v1 = v as u32 ; // println!("in start state with v1={:#02x} and len()={}", v1, mybuf.len());
 if v1 < 0xE0 { if v1 < 0xC2 { mybuf . pop_front ( ) ; if v1 < 0x80 { // Action 0
 // 1 byte format: code point from 0x0 to 0x7F
 // println!("in action 0 with v1={:#02x}", v1);
 Utf8EndEnum :: Finish ( v1 ) } else { // 80 to C1: not valid first byte
 // println!("80 to C1 bad decode");
 Utf8EndEnum :: BadDecode ( 1 ) } } else { // Byte 1 is between 0xC2 and 0xDF
 // 2 byte format
 if ( mybuf . len ( ) < 2 ) && ! last_buffer { // We wait for more bytes if not the last buffer.
 // Our design cannot back-out procesed bytes.
 // println!("TypeUnknown");
 Utf8EndEnum :: TypeUnknown } else { // Action 1
 // println!("in action 1 with v1={:#02x}", v1);
 mybuf . pop_front ( ) ; byte2_action9 ( mybuf , v1 & 0x1F ) } } } else { if v1 < 0xF0 { // 3 byte format
 // Byte 1 is between 0xE0 and 0xEF
 if ( mybuf . len ( ) < 3 ) && ! last_buffer { // We wait for more bytes if not the last buffer.
 // Our design cannot back-out procesed bytes.
 // println!("TypeUnknown");
 Utf8EndEnum :: TypeUnknown } else if v1 < 0xED { mybuf . pop_front ( ) ; if v1 == 0xE0 { // Action 2
 // v1 is 0xE0.
 // println!("in action 2 with v1={:#02x}", v1);
 byte2_action14 ( mybuf , v1 & 0xF ) } else { // Action 3
 // v1 is between 0xE1 and 0xEC.
 // println!("in action 3 with v1={:#02x}", v1);
 byte2_action10 ( mybuf , v1 & 0xF ) } } else { mybuf . pop_front ( ) ; if v1 == 0xED { // Action 4
 // println!("in action 4 with v1={:#02x}", v1);
 byte2_action15 ( mybuf , v1 & 0xF ) } else { // Action 5
 // v1 is 0xEE or 0xEF.
 // println!("in action 5 with v1={:#02x}", v1);
 byte2_action11 ( mybuf , v1 & 0xF ) } } } else { // 4 byte cases if byte 1 is between 0xF0 and 0xF4
 if v1 > 0xF4 { // codepoint too large
 // println!("greater than F4 bad decode");
 mybuf . pop_front ( ) ; Utf8EndEnum :: BadDecode ( 1 ) } else if ( mybuf . len ( ) < 4 ) && ! last_buffer { // We wait for more bytes if not the last buffer.
 // Our design cannot back-out procesed bytes.
 // println!("TypeUnknown");
 Utf8EndEnum :: TypeUnknown } else { mybuf . pop_front ( ) ; if v1 == 0xF0 { // Action 6
 // println!("in action 6 with v1={:#02x}", v1);
 byte2_action16 ( mybuf , v1 & 0x7 ) } else if v1 < 0xF4 { // Action 7
 // Byte 1 is between 0xF1 and 0xF3.
 // println!("in action 7 with v1={:#02x}", v1);
 byte2_action12 ( mybuf , v1 & 0x7 ) } else { // Action 8
 // Byte 1 is 0xF4.
 // println!("in action 8 with v1={:#02x}", v1);
 byte2_action13 ( mybuf , v1 & 0x7 ) } } } } } Option :: None => { // println!("TypeUnknown");
 Utf8EndEnum :: TypeUnknown } } }
Decode from UTF8 to Unicode code point using a finate state machine.
Decode from UTF8 to Unicode code point using a finate state machine .
mybuf
& mut EightBytes
last_buffer
bool
mybuf
& mut EightBytes
last_buffer
bool
arguments

`mybuf` - contains the bytes to be decoded

`last_buffer` - is true when we are working on the last byte buffer.

When 'last_buffer' is false, with additional buffers to be processed,
then the parser would refuse to work on potential partial decodes,
and returns Utf8EndEnum::TypeUnknown to ask for more data.

When 'last_buffer' is true, with no more data to process than
what is available in 'mybuf', then partial decodes results in
Utf8EndEnum:BadDecode(n) where n is length of error from 1 to 3 bytes.
` mybuf ` - contains the bytes to be decoded ` last_buffer ` - is true when we are working on the last byte buffer . When ' last_buffer ' is false with additional buffers to be processed then the parser would refuse to work on potential partial decodes and returns Utf8EndEnum :: TypeUnknown to ask for more data . When ' last_buffer ' is true with no more data to process than what is available in ' mybuf ' then partial decodes results in Utf8EndEnum : BadDecode ( n ) where n is length of error from 1 to 3 bytes .