Stream Codecs
Stream codecs are a serialization tool used to describe how an object should be stored and read from a stream, such as buffers. Stream codecs are primarly used by Vanilla's networking system to sync data.
As stream codecs are roughly analagous to codecs, this page has been formatted in the same way to show the similarities.
Using Stream Codecs
Stream codecs encode and decode objects into some stream using StreamCodec#encode and StreamCodec#decode, respectively. encode takes in the stream and the object to encode into the stream. decode takes in the stream and returns the decoded object. Typically, the stream is either a ByteBuf, FriendlyByteBuf, or RegistryFriendlyByteBuf.
// Let exampleStreamCodec represent a StreamCodec<ExampleJavaObject>
// Let exampleObject be a ExampleJavaObject
// Let buffer be a RegistryFriendlyByteBuf
// Encode Java object into the buffer stream
exampleStreamCodec.encode(buffer, exampleObject);
// Read Java object from buffer stream
ExampleJavaObject obj = exampleStreamCodec.decode(buffer);
Unless you are manually handling the buffer object, you will generally never call encode and decode.