pub trait Decode<'a>: Sized {
// Required method
fn decode(r: &mut &'a [u8]) -> Result<Self, Error>;
}
Expand description
The Decode
trait allows objects to be read from the Minecraft protocol. It
is the inverse of Encode
.
Decode
is parameterized by a lifetime. This allows the decoded value to
borrow data from the byte slice it was read from.
§Deriving
This trait can be implemented automatically for structs and enums by using
the Decode
derive macro. All components of the type must
implement Decode
. Components are decoded in the order they appear in the
type definition.
For enums, the variant to decode is determined by a leading VarInt
discriminant (tag). The discriminant value can be changed using the
#[packet(tag = ...)]
attribute on the variant in question. Discriminant
values are assigned to variants using rules similar to regular enum
discriminants.
use valence_protocol::Decode;
#[derive(PartialEq, Debug, Decode)]
struct MyStruct {
first: i32,
second: MyEnum,
}
#[derive(PartialEq, Debug, Decode)]
enum MyEnum {
First, // tag = 0
Second, // tag = 1
#[packet(tag = 25)]
Third, // tag = 25
Fourth, // tag = 26
}
let mut r: &[u8] = &[0, 0, 0, 0, 26];
let value = MyStruct::decode(&mut r).unwrap();
let expected = MyStruct {
first: 0,
second: MyEnum::Fourth,
};
assert_eq!(value, expected);
assert!(r.is_empty());
Required Methods§
Object Safety§
Implementations on Foreign Types§
§impl<'a, A, B, C, D> Decode<'a> for (A, B, C, D)
impl<'a, A, B, C, D> Decode<'a> for (A, B, C, D)
§impl<'a, A, B, C, D, E> Decode<'a> for (A, B, C, D, E)
impl<'a, A, B, C, D, E> Decode<'a> for (A, B, C, D, E)
§impl<'a, A, B, C, D, E, F> Decode<'a> for (A, B, C, D, E, F)
impl<'a, A, B, C, D, E, F> Decode<'a> for (A, B, C, D, E, F)
§impl<'a, A, B, C, D, E, F, G> Decode<'a> for (A, B, C, D, E, F, G)
impl<'a, A, B, C, D, E, F, G> Decode<'a> for (A, B, C, D, E, F, G)
§impl<'a, A, B, C, D, E, F, G, H> Decode<'a> for (A, B, C, D, E, F, G, H)
impl<'a, A, B, C, D, E, F, G, H> Decode<'a> for (A, B, C, D, E, F, G, H)
§impl<'a, A, B, C, D, E, F, G, H, I> Decode<'a> for (A, B, C, D, E, F, G, H, I)
impl<'a, A, B, C, D, E, F, G, H, I> Decode<'a> for (A, B, C, D, E, F, G, H, I)
§impl<'a, A, B, C, D, E, F, G, H, I, J> Decode<'a> for (A, B, C, D, E, F, G, H, I, J)
impl<'a, A, B, C, D, E, F, G, H, I, J> Decode<'a> for (A, B, C, D, E, F, G, H, I, J)
§impl<'a, A, B, C, D, E, F, G, H, I, J, K> Decode<'a> for (A, B, C, D, E, F, G, H, I, J, K)
impl<'a, A, B, C, D, E, F, G, H, I, J, K> Decode<'a> for (A, B, C, D, E, F, G, H, I, J, K)
§impl<'a, A, B, C, D, E, F, G, H, I, J, K, L> Decode<'a> for (A, B, C, D, E, F, G, H, I, J, K, L)
impl<'a, A, B, C, D, E, F, G, H, I, J, K, L> Decode<'a> for (A, B, C, D, E, F, G, H, I, J, K, L)
§impl<'a, const N: usize> Decode<'a> for &'a [u8; N]
impl<'a, const N: usize> Decode<'a> for &'a [u8; N]
References to fixed-length arrays are not length prefixed.
Implementors§
impl Decode<'_> for BlockKind
impl Decode<'_> for ItemKind
impl Decode<'_> for VillagerData
impl Decode<'_> for DQuat
impl Decode<'_> for DVec2
impl Decode<'_> for DVec3
impl Decode<'_> for IVec3
impl Decode<'_> for Quat
impl Decode<'_> for Vec2
impl Decode<'_> for Vec3
impl Decode<'_> for Vec3A
impl Decode<'_> for Vec4
impl Decode<'_> for Compound
impl Decode<'_> for OptGameMode
impl Decode<'_> for ChunkDeltaUpdateEntry
impl Decode<'_> for BlockPos
impl Decode<'_> for BlockState
impl Decode<'_> for ByteAngle
impl Decode<'_> for ChunkSectionPos
impl Decode<'_> for ItemStack
impl Decode<'_> for Text
impl Decode<'_> for VarInt
impl Decode<'_> for VarLong
impl<'a> Decode<'a> for BlockEntityKind
impl<'a> Decode<'a> for BoatKind
impl<'a> Decode<'a> for CatKind
impl<'a> Decode<'a> for FrogKind
impl<'a> Decode<'a> for PaintingKind
impl<'a> Decode<'a> for Pose
impl<'a> Decode<'a> for SnifferState
impl<'a> Decode<'a> for VillagerKind
impl<'a> Decode<'a> for VillagerProfession
impl<'a> Decode<'a> for Difficulty
impl<'a> Decode<'a> for Direction
impl<'a> Decode<'a> for GameMode
impl<'a> Decode<'a> for Hand
impl<'a> Decode<'a> for HandshakeNextState
impl<'a> Decode<'a> for BossBarAction<'a>
impl<'a> Decode<'a> for BossBarColor
impl<'a> Decode<'a> for BossBarDivision
impl<'a> Decode<'a> for MessageFilterType
impl<'a> Decode<'a> for ChatSuggestionsAction
impl<'a> Decode<'a> for ClickMode
impl<'a> Decode<'a> for ClientCommand
impl<'a> Decode<'a> for ChatMode
impl<'a> Decode<'a> for MainArm
impl<'a> Decode<'a> for Parser
impl<'a> Decode<'a> for StringArg
impl<'a> Decode<'a> for AdvancementTabC2s<'a>
impl<'a> Decode<'a> for ClientStatusC2s
impl<'a> Decode<'a> for ResourcePackStatusC2s
impl<'a> Decode<'a> for UpdatePlayerAbilitiesC2s
impl<'a> Decode<'a> for GameEventKind
impl<'a> Decode<'a> for FeetOrEyes
impl<'a> Decode<'a> for IconType
impl<'a> Decode<'a> for WindowType
impl<'a> Decode<'a> for PlayerAction
impl<'a> Decode<'a> for EntityInteraction
impl<'a> Decode<'a> for RecipeBookId
impl<'a> Decode<'a> for ScoreboardPosition
impl<'a> Decode<'a> for ObjectiveMode<'a>
impl<'a> Decode<'a> for ObjectiveRenderType
impl<'a> Decode<'a> for ScoreboardPlayerUpdateAction<'a>
impl<'a> Decode<'a> for CraftingShapedCategory
impl<'a> Decode<'a> for valence::protocol::packets::play::team_s2c::Mode<'a>
impl<'a> Decode<'a> for TeamColor
impl<'a> Decode<'a> for UpdateCommandBlockMode
impl<'a> Decode<'a> for Action
impl<'a> Decode<'a> for Mirror
impl<'a> Decode<'a> for valence::protocol::packets::play::update_structure_block_c2s::Mode
impl<'a> Decode<'a> for Rotation
impl<'a> Decode<'a> for SoundCategory
impl<'a> Decode<'a> for SoundId<'a>
impl<'a> Decode<'a> for EulerAngle
impl<'a> Decode<'a> for Uuid
impl<'a> Decode<'a> for PackedBlockPos
impl<'a> Decode<'a> for PackedChunkSectionPos
impl<'a> Decode<'a> for HandshakeC2s<'a>
impl<'a> Decode<'a> for LoginCompressionS2c
impl<'a> Decode<'a> for LoginDisconnectS2c<'a>
impl<'a> Decode<'a> for LoginHelloC2s<'a>
impl<'a> Decode<'a> for LoginHelloS2c<'a>
impl<'a> Decode<'a> for LoginKeyC2s<'a>
impl<'a> Decode<'a> for LoginQueryRequestS2c<'a>
impl<'a> Decode<'a> for LoginQueryResponseC2s<'a>
impl<'a> Decode<'a> for LoginSuccessS2c<'a>
impl<'a> Decode<'a> for AdvancementCriteria<'a>
impl<'a> Decode<'a> for AdvancementRequirements<'a>
impl<'a> Decode<'a> for BossBarFlags
impl<'a> Decode<'a> for MessageSignature<'a>
impl<'a> Decode<'a> for ChunkBiome<'a>
impl<'a> Decode<'a> for ChunkDataBlockEntity<'a>
impl<'a> Decode<'a> for SlotChange
impl<'a> Decode<'a> for DisplayedSkinParts
impl<'a> Decode<'a> for CommandArgumentSignature<'a>
impl<'a> Decode<'a> for CommandSuggestionsMatch<'a>
impl<'a> Decode<'a> for Node
impl<'a> Decode<'a> for AttributeModifier
impl<'a> Decode<'a> for AttributeProperty<'a>
impl<'a> Decode<'a> for EquipmentEntry
impl<'a> Decode<'a> for valence::protocol::packets::play::entity_status_effect_s2c::Flags
impl<'a> Decode<'a> for LookAtEntity
impl<'a> Decode<'a> for Icon<'a>
impl<'a> Decode<'a> for PlayerAbilitiesFlags
impl<'a> Decode<'a> for PlayerInputFlags
impl<'a> Decode<'a> for ChatData<'a>
impl<'a> Decode<'a> for PlayerPositionLookFlags
impl<'a> Decode<'a> for TradeOffer
impl<'a> Decode<'a> for Statistic
impl<'a> Decode<'a> for BlockBreakingProgressS2c
impl<'a> Decode<'a> for BlockEntityUpdateS2c<'a>
impl<'a> Decode<'a> for BlockEventS2c
impl<'a> Decode<'a> for BlockUpdateS2c
impl<'a> Decode<'a> for BoatPaddleStateC2s
impl<'a> Decode<'a> for BookUpdateC2s<'a>
impl<'a> Decode<'a> for BossBarS2c<'a>
impl<'a> Decode<'a> for BundleSplitterS2c
impl<'a> Decode<'a> for ButtonClickC2s
impl<'a> Decode<'a> for ChatMessageC2s<'a>
impl<'a> Decode<'a> for ChatMessageS2c<'a>
impl<'a> Decode<'a> for ChatSuggestionsS2c<'a>
impl<'a> Decode<'a> for ChunkBiomeDataS2c<'a>
impl<'a> Decode<'a> for ChunkDataS2c<'a>
impl<'a> Decode<'a> for ChunkDeltaUpdateS2c<'a>
impl<'a> Decode<'a> for ChunkLoadDistanceS2c
impl<'a> Decode<'a> for ChunkRenderDistanceCenterS2c
impl<'a> Decode<'a> for ClearTitleS2c
impl<'a> Decode<'a> for ClickSlotC2s<'a>
impl<'a> Decode<'a> for ClientCommandC2s
impl<'a> Decode<'a> for ClientSettingsC2s<'a>
impl<'a> Decode<'a> for CloseHandledScreenC2s
impl<'a> Decode<'a> for CloseScreenS2c
impl<'a> Decode<'a> for CommandExecutionC2s<'a>
impl<'a> Decode<'a> for CommandSuggestionsS2c<'a>
impl<'a> Decode<'a> for CommandTreeS2c
impl<'a> Decode<'a> for CooldownUpdateS2c
impl<'a> Decode<'a> for CraftFailedResponseS2c<'a>
impl<'a> Decode<'a> for CraftRequestC2s<'a>
impl<'a> Decode<'a> for CreativeInventoryActionC2s
impl<'a> Decode<'a> for CustomPayloadC2s<'a>
impl<'a> Decode<'a> for CustomPayloadS2c<'a>
impl<'a> Decode<'a> for DamageTiltS2c
impl<'a> Decode<'a> for DeathMessageS2c<'a>
impl<'a> Decode<'a> for DifficultyS2c
impl<'a> Decode<'a> for DisconnectS2c<'a>
impl<'a> Decode<'a> for EndCombatS2c
impl<'a> Decode<'a> for EnterCombatS2c
impl<'a> Decode<'a> for EntitiesDestroyS2c<'a>
impl<'a> Decode<'a> for EntityAnimationS2c
impl<'a> Decode<'a> for EntityAttachS2c
impl<'a> Decode<'a> for EntityAttributesS2c<'a>
impl<'a> Decode<'a> for EntityDamageS2c
impl<'a> Decode<'a> for EntityEquipmentUpdateS2c
impl<'a> Decode<'a> for EntityPassengersSetS2c<'a>
impl<'a> Decode<'a> for EntityPositionS2c
impl<'a> Decode<'a> for EntitySetHeadYawS2c
impl<'a> Decode<'a> for EntitySpawnS2c
impl<'a> Decode<'a> for EntityStatusEffectS2c
impl<'a> Decode<'a> for EntityStatusS2c
impl<'a> Decode<'a> for EntityTrackerUpdateS2c<'a>
impl<'a> Decode<'a> for EntityVelocityUpdateS2c
impl<'a> Decode<'a> for ExperienceBarUpdateS2c
impl<'a> Decode<'a> for ExperienceOrbSpawnS2c
impl<'a> Decode<'a> for ExplosionS2c<'a>
impl<'a> Decode<'a> for FeaturesS2c<'a>
impl<'a> Decode<'a> for FullC2s
impl<'a> Decode<'a> for GameJoinS2c<'a>
impl<'a> Decode<'a> for GameMessageS2c<'a>
impl<'a> Decode<'a> for GameStateChangeS2c
impl<'a> Decode<'a> for HandSwingC2s
impl<'a> Decode<'a> for HealthUpdateS2c
impl<'a> Decode<'a> for InventoryS2c<'a>
impl<'a> Decode<'a> for ItemPickupAnimationS2c
impl<'a> Decode<'a> for JigsawGeneratingC2s
impl<'a> Decode<'a> for KeepAliveC2s
impl<'a> Decode<'a> for KeepAliveS2c
impl<'a> Decode<'a> for LightUpdateS2c<'a>
impl<'a> Decode<'a> for LookAndOnGroundC2s
impl<'a> Decode<'a> for LookAtS2c
impl<'a> Decode<'a> for MapUpdateS2c<'a>
impl<'a> Decode<'a> for MessageAcknowledgmentC2s
impl<'a> Decode<'a> for MoveRelativeS2c
impl<'a> Decode<'a> for NbtQueryResponseS2c
impl<'a> Decode<'a> for OnGroundOnlyC2s
impl<'a> Decode<'a> for OpenHorseScreenS2c
impl<'a> Decode<'a> for OpenScreenS2c<'a>
impl<'a> Decode<'a> for OpenWrittenBookS2c
impl<'a> Decode<'a> for OverlayMessageS2c<'a>
impl<'a> Decode<'a> for ParticleS2c<'a>
impl<'a> Decode<'a> for PickFromInventoryC2s
impl<'a> Decode<'a> for PlayPingS2c
impl<'a> Decode<'a> for PlayPongC2s
impl<'a> Decode<'a> for PlaySoundFromEntityS2c
impl<'a> Decode<'a> for PlaySoundS2c<'a>
impl<'a> Decode<'a> for PlayerAbilitiesS2c
impl<'a> Decode<'a> for PlayerActionC2s
impl<'a> Decode<'a> for PlayerActionResponseS2c
impl<'a> Decode<'a> for PlayerInputC2s
impl<'a> Decode<'a> for PlayerInteractBlockC2s
impl<'a> Decode<'a> for PlayerInteractEntityC2s
impl<'a> Decode<'a> for PlayerInteractItemC2s
impl<'a> Decode<'a> for PlayerListHeaderS2c<'a>
impl<'a> Decode<'a> for PlayerListS2c<'a>
impl<'a> Decode<'a> for PlayerPositionLookS2c
impl<'a> Decode<'a> for PlayerRemoveS2c<'a>
impl<'a> Decode<'a> for PlayerRespawnS2c<'a>
impl<'a> Decode<'a> for PlayerSessionC2s<'a>
impl<'a> Decode<'a> for PlayerSpawnPositionS2c
impl<'a> Decode<'a> for PlayerSpawnS2c
impl<'a> Decode<'a> for PositionAndOnGroundC2s
impl<'a> Decode<'a> for ProfilelessChatMessageS2c<'a>
impl<'a> Decode<'a> for QueryBlockNbtC2s
impl<'a> Decode<'a> for QueryEntityNbtC2s
impl<'a> Decode<'a> for RecipeBookDataC2s<'a>
impl<'a> Decode<'a> for RecipeCategoryOptionsC2s
impl<'a> Decode<'a> for RemoveEntityStatusEffectS2c
impl<'a> Decode<'a> for RemoveMessageS2c<'a>
impl<'a> Decode<'a> for RenameItemC2s<'a>
impl<'a> Decode<'a> for RequestCommandCompletionsC2s<'a>
impl<'a> Decode<'a> for ResourcePackSendS2c<'a>
impl<'a> Decode<'a> for RotateAndMoveRelativeS2c
impl<'a> Decode<'a> for RotateS2c
impl<'a> Decode<'a> for ScoreboardDisplayS2c<'a>
impl<'a> Decode<'a> for ScoreboardObjectiveUpdateS2c<'a>
impl<'a> Decode<'a> for ScoreboardPlayerUpdateS2c<'a>
impl<'a> Decode<'a> for ScreenHandlerPropertyUpdateS2c
impl<'a> Decode<'a> for ScreenHandlerSlotUpdateS2c<'a>
impl<'a> Decode<'a> for SelectAdvancementTabS2c<'a>
impl<'a> Decode<'a> for SelectMerchantTradeC2s
impl<'a> Decode<'a> for ServerMetadataS2c<'a>
impl<'a> Decode<'a> for SetCameraEntityS2c
impl<'a> Decode<'a> for SetTradeOffersS2c
impl<'a> Decode<'a> for SignEditorOpenS2c
impl<'a> Decode<'a> for SimulationDistanceS2c
impl<'a> Decode<'a> for SpectatorTeleportC2s
impl<'a> Decode<'a> for StatisticsS2c
impl<'a> Decode<'a> for StopSoundS2c<'a>
impl<'a> Decode<'a> for SubtitleS2c<'a>
impl<'a> Decode<'a> for SynchronizeRecipesS2c<'a>
impl<'a> Decode<'a> for SynchronizeTagsS2c<'a>
impl<'a> Decode<'a> for TeamS2c<'a>
impl<'a> Decode<'a> for TeleportConfirmC2s
impl<'a> Decode<'a> for TitleFadeS2c
impl<'a> Decode<'a> for TitleS2c<'a>
impl<'a> Decode<'a> for UnloadChunkS2c
impl<'a> Decode<'a> for UnlockRecipesS2c<'a>
impl<'a> Decode<'a> for UpdateBeaconC2s
impl<'a> Decode<'a> for UpdateCommandBlockC2s<'a>
impl<'a> Decode<'a> for UpdateCommandBlockMinecartC2s<'a>
impl<'a> Decode<'a> for UpdateDifficultyC2s
impl<'a> Decode<'a> for UpdateDifficultyLockC2s
impl<'a> Decode<'a> for UpdateJigsawC2s<'a>
impl<'a> Decode<'a> for UpdateSelectedSlotC2s
impl<'a> Decode<'a> for UpdateSelectedSlotS2c
impl<'a> Decode<'a> for UpdateSignC2s<'a>
impl<'a> Decode<'a> for UpdateStructureBlockC2s<'a>
impl<'a> Decode<'a> for VehicleMoveC2s
impl<'a> Decode<'a> for VehicleMoveS2c
impl<'a> Decode<'a> for WorldBorderCenterChangedS2c
impl<'a> Decode<'a> for WorldBorderInitializeS2c
impl<'a> Decode<'a> for WorldBorderInterpolateSizeS2c
impl<'a> Decode<'a> for WorldBorderSizeChangedS2c
impl<'a> Decode<'a> for WorldBorderWarningBlocksChangedS2c
impl<'a> Decode<'a> for WorldBorderWarningTimeChangedS2c
impl<'a> Decode<'a> for WorldEventS2c
impl<'a> Decode<'a> for WorldTimeUpdateS2c
impl<'a> Decode<'a> for TeamFlags
impl<'a> Decode<'a> for UpdateCommandBlockFlags
impl<'a> Decode<'a> for valence::protocol::packets::play::update_structure_block_c2s::Flags
impl<'a> Decode<'a> for QueryPingC2s
impl<'a> Decode<'a> for QueryPongS2c
impl<'a> Decode<'a> for QueryRequestC2s
impl<'a> Decode<'a> for QueryResponseS2c<'a>
impl<'a> Decode<'a> for ChunkPos
impl<'a> Decode<'a> for GlobalPos<'a>
impl<'a> Decode<'a> for RawBytes<'a>
impl<'a> Decode<'a> for Velocity
impl<'a, AM> Decode<'a> for GenericAdvancementUpdateS2c<'a, AM>where
AM: 'a + Decode<'a>,
impl<'a, I> Decode<'a> for Advancement<'a, I>where
I: Decode<'a>,
impl<'a, I> Decode<'a> for AdvancementDisplay<'a, I>where
I: Decode<'a>,
impl<'a, S> Decode<'a> for Property<S>where
S: Decode<'a>,
impl<'a, S> Decode<'a> for Ident<S>
impl<'a, T, const MAX_LEN: usize> Decode<'a> for Bounded<Box<[T]>, MAX_LEN>where
T: Decode<'a>,
impl<'a, T, const MAX_LEN: usize> Decode<'a> for Bounded<Vec<T>, MAX_LEN>where
T: Decode<'a>,
impl<'a, T, const N: usize> Decode<'a> for FixedArray<T, N>where
T: Decode<'a>,
impl<'a, const MAX_BYTES: usize> Decode<'a> for Bounded<RawBytes<'a>, MAX_BYTES>
Raises a decoding error if the remainder of the input is larger than
MAX_BYTES
.