Решение на Network Packets от Людмил Данаилов
Към профила на Людмил Данаилов
Резултати
- 1 точка от тестове
- 0 бонус точки
- 1 точка общо
- 1 успешни тест(а)
- 14 неуспешни тест(а)
Код
Лог от изпълнението
Compiling solution v0.1.0 (/tmp/d20200111-2173579-1t1pumg/solution) warning: unused import: `std::str` --> src/lib.rs:2:5 | 2 | use std::str; | ^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused variable: `source` --> src/lib.rs:27:24 | 27 | pub fn from_source(source: &[u8], size: u8) -> (Self, &[u8]) { | ^^^^^^ help: consider prefixing with an underscore: `_source` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `size` --> src/lib.rs:27:39 | 27 | pub fn from_source(source: &[u8], size: u8) -> (Self, &[u8]) { | ^^^^ help: consider prefixing with an underscore: `_size` warning: unused variable: `bytes` --> src/lib.rs:47:24 | 47 | pub fn deserialize(bytes: &[u8]) -> Result<(Packet, &[u8]), PacketError> { | ^^^^^ help: consider prefixing with an underscore: `_bytes` warning: unused variable: `packet_size` --> src/lib.rs:71:26 | 71 | fn to_packets(&self, packet_size: u8) -> PacketSerializer { | ^^^^^^^^^^^ help: consider prefixing with an underscore: `_packet_size` warning: unused variable: `packet_size` --> src/lib.rs:75:30 | 75 | fn to_packet_data(&self, packet_size: u8) -> Vec<u8> { | ^^^^^^^^^^^ help: consider prefixing with an underscore: `_packet_size` warning: unused variable: `packet_data` --> src/lib.rs:79:25 | 79 | fn from_packet_data(packet_data: &[u8]) -> Result<Self, PacketError> { | ^^^^^^^^^^^ help: consider prefixing with an underscore: `_packet_data` warning: unused import: `std::str` --> src/lib.rs:2:5 | 2 | use std::str; | ^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused variable: `source` --> src/lib.rs:27:24 | 27 | pub fn from_source(source: &[u8], size: u8) -> (Self, &[u8]) { | ^^^^^^ help: consider prefixing with an underscore: `_source` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `size` --> src/lib.rs:27:39 | 27 | pub fn from_source(source: &[u8], size: u8) -> (Self, &[u8]) { | ^^^^ help: consider prefixing with an underscore: `_size` warning: unused variable: `bytes` --> src/lib.rs:47:24 | 47 | pub fn deserialize(bytes: &[u8]) -> Result<(Packet, &[u8]), PacketError> { | ^^^^^ help: consider prefixing with an underscore: `_bytes` warning: unused variable: `packet_size` --> src/lib.rs:71:26 | 71 | fn to_packets(&self, packet_size: u8) -> PacketSerializer { | ^^^^^^^^^^^ help: consider prefixing with an underscore: `_packet_size` warning: unused variable: `packet_size` --> src/lib.rs:75:30 | 75 | fn to_packet_data(&self, packet_size: u8) -> Vec<u8> { | ^^^^^^^^^^^ help: consider prefixing with an underscore: `_packet_size` warning: unused variable: `packet_data` --> src/lib.rs:79:25 | 79 | fn from_packet_data(packet_data: &[u8]) -> Result<Self, PacketError> { | ^^^^^^^^^^^ help: consider prefixing with an underscore: `_packet_data` Finished test [unoptimized + debuginfo] target(s) in 3.42s Running target/debug/deps/solution-a73e64ec87929bd0 running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out Running target/debug/deps/solution_test-38971695424b36d5 running 15 tests test solution_test::test_construct_packet_from_unicode ... FAILED test solution_test::test_construct_packet_no_remainder ... FAILED test solution_test::test_construct_packet_with_remainder ... FAILED test solution_test::test_construct_packet_with_remainder_cyrillic ... FAILED test solution_test::test_consuming_packets ... thread '<unnamed>' panicked at 'not yet implemented', src/lib.rs:72:9 FAILED test solution_test::test_deserialize_invalid_packet ... FAILED test solution_test::test_deserialize_packet ... FAILED test solution_test::test_deserialize_unicode_packet ... FAILED test solution_test::test_full_roundtrip ... thread '<unnamed>' panicked at 'not yet implemented', src/lib.rs:76:9 FAILED test solution_test::test_full_roundtrip_for_zero_size_string ... thread '<unnamed>' panicked at 'not yet implemented', src/lib.rs:76:9 FAILED test solution_test::test_invalid_packet_combination ... thread '<unnamed>' panicked at 'not yet implemented', src/lib.rs:72:9 FAILED test solution_test::test_iterating_packets ... thread '<unnamed>' panicked at 'not yet implemented', src/lib.rs:72:9 FAILED test solution_test::test_iterating_packets_for_zero_size_string ... thread '<unnamed>' panicked at 'not yet implemented', src/lib.rs:72:9 FAILED test solution_test::test_serialize_packet ... FAILED test solution_test::test_zero_size ... ok failures: ---- solution_test::test_construct_packet_from_unicode stdout ---- thread 'main' panicked at 'not yet implemented', src/lib.rs:36:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. ---- solution_test::test_construct_packet_no_remainder stdout ---- thread 'main' panicked at 'not yet implemented', src/lib.rs:36:9 ---- solution_test::test_construct_packet_with_remainder stdout ---- thread 'main' panicked at 'not yet implemented', src/lib.rs:36:9 ---- solution_test::test_construct_packet_with_remainder_cyrillic stdout ---- thread 'main' panicked at 'not yet implemented', src/lib.rs:36:9 ---- solution_test::test_consuming_packets stdout ---- thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21 ---- solution_test::test_deserialize_invalid_packet stdout ---- thread 'main' panicked at 'not yet implemented', src/lib.rs:48:9 ---- solution_test::test_deserialize_packet stdout ---- thread 'main' panicked at 'not yet implemented', src/lib.rs:36:9 ---- solution_test::test_deserialize_unicode_packet stdout ---- thread 'main' panicked at 'not yet implemented', src/lib.rs:36:9 ---- solution_test::test_full_roundtrip stdout ---- thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21 ---- solution_test::test_full_roundtrip_for_zero_size_string stdout ---- thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21 ---- solution_test::test_invalid_packet_combination stdout ---- thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21 ---- solution_test::test_iterating_packets stdout ---- thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21 ---- solution_test::test_iterating_packets_for_zero_size_string stdout ---- thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21 ---- solution_test::test_serialize_packet stdout ---- thread 'main' panicked at 'not yet implemented', src/lib.rs:36:9 failures: solution_test::test_construct_packet_from_unicode solution_test::test_construct_packet_no_remainder solution_test::test_construct_packet_with_remainder solution_test::test_construct_packet_with_remainder_cyrillic solution_test::test_consuming_packets solution_test::test_deserialize_invalid_packet solution_test::test_deserialize_packet solution_test::test_deserialize_unicode_packet solution_test::test_full_roundtrip solution_test::test_full_roundtrip_for_zero_size_string solution_test::test_invalid_packet_combination solution_test::test_iterating_packets solution_test::test_iterating_packets_for_zero_size_string solution_test::test_serialize_packet test result: FAILED. 1 passed; 14 failed; 0 ignored; 0 measured; 0 filtered out error: test failed, to rerun pass '--test solution_test'
Като за начало, няма нужда да ползваш
str::from_utf8
, последвано от.to_string()
, има сиString::from_utf8
. Иначе, няма причина да конвертираш байтовете до низ -- ако искахме пакетите да са само utf8-валидни низове, щяхме да очаквамеsource
да е низ. Пакета може да обхваща всякакъв комплект от байтове, не задължително валиден низ.Оттам нататък, не ми е съвсем ясно какво се опитваш да направиш. Почваш да броиш от 1 до
payload.len() - size
, но защо? Изглежда първо искаш да събереш остатъка, а после да сложиш payload-а, което е малко наобратно.Не знам какво значи "doesn't work" оттук нататък, може би не се е компилирал кода или тестовете са гърмели? Но прегледай останалите решения, примерно моето, и се опитай да разбереш кода, може би и да си имплементираш собствено решение за упражнение.