Skip to content

Commit 18395a2

Browse files
Fix minimal javadoc wording for coder encode decode
1 parent 7609051 commit 18395a2

1 file changed

Lines changed: 14 additions & 51 deletions

File tree

  • sdks/java/core/src/main/java/org/apache/beam/sdk/coders

sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,6 @@
5353
*
5454
* @param <T> the type of values being encoded and decoded
5555
*/
56-
/**
57-
* <b>Example usage:</b>
58-
*
59-
* <pre>{@code
60-
* Coder<String> coder = StringUtf8Coder.of();
61-
*
62-
* // Encoding a single standalone value(typically uses OUTER context)
63-
* coder.encode("hello", outStream);
64-
*
65-
* // Encoding multiple values (NESTED context scenario)
66-
* for (String value : values) {
67-
* coder.encode(value, outStream);
68-
* }
69-
* }</pre>
70-
*
71-
* <p>When multiple values are encoded into the same stream, coders must ensure that each value can
72-
* be correctly decoded. This is typically done by encoding length or delimiter information.
73-
*/
7456
public abstract class Coder<T> implements Serializable {
7557
/**
7658
* The context in which encoding or decoding is being done.
@@ -82,31 +64,21 @@ public abstract class Coder<T> implements Serializable {
8264
@Deprecated
8365
public static class Context {
8466
/**
85-
* The outer context indicates that the value being encoded or decoded occupies the entire
86-
* remaining stream.
87-
*
88-
* <p>In this context, the coder does not need to include length or boundary information, since
89-
* the value extends to the end of the stream.
90-
*
91-
* <p><b>Example:</b> Encoding a single standalone value.
67+
* The outer context: the value being encoded or decoded takes up the remainder of the
68+
* record/stream contents.
9269
*/
9370
public static final Context OUTER = new Context(true);
71+
9472
/**
95-
* The nested context indicates that the value being encoded or decoded is part of a larger
96-
* structure or stream containing multiple values.
97-
*
98-
* <p>In this context, the coder must include enough information (such as length or delimiters)
99-
* to allow correct decoding of individual elements.
100-
*
101-
* <p><b>Example:</b> Encoding elements inside a collection or record.
73+
* The nested context: the value being encoded or decoded is (potentially) a part of a larger
74+
* record/stream contents, and may have other parts encoded or decoded after it.
10275
*/
10376
public static final Context NESTED = new Context(false);
10477

10578
/**
106-
* Indicates whether the encoded/decoded value consumes the entire remaining stream.
107-
*
108-
* <p>If true, no additional length information is required. If false, the coder must encode
109-
* boundaries to allow correct decoding.
79+
* Whether the encoded or decoded value fills the remainder of the output or input (resp.)
80+
* record/stream contents. If so, then the size of the decoded value can be determined from the
81+
* remaining size of the record/stream contents, and so explicit lengths aren't required.
11082
*/
11183
public final boolean isWholeStream;
11284

@@ -145,11 +117,8 @@ public String toString() {
145117
* know how many bytes to read when decoding. A common approach is to prefix the encoding with the
146118
* element's encoded length.
147119
*
148-
* <p>The behavior of encoding depends on the {@link Context} in which it is used. When using
149-
* {@link Context#OUTER}, the encoded value may consume the entire remaining stream, so no
150-
* additional length information is required. In contrast, when using {@link Context#NESTED}, the
151-
* encoded value is part of a larger structure, and the coder must include sufficient boundary
152-
* information (such as length prefixes) to allow correct decoding of individual elements.
120+
* @throws IOException if writing to the {@code OutputStream} fails for some reason
121+
* @throws CoderException if the value could not be encoded for some reason
153122
*/
154123
public abstract void encode(T value, OutputStream outStream) throws CoderException, IOException;
155124

@@ -167,16 +136,10 @@ public void encode(T value, OutputStream outStream, Context context)
167136
}
168137

169138
/**
170-
* Decodes a value of type {@code T} from the given input stream and returns the decoded value.
171-
*
172-
* <p>When multiple elements are encoded in the same stream, the coder must be able to determine
173-
* how many bytes to read for each element. This is typically achieved by encoding length or
174-
* delimiter information during encoding.
175-
*
176-
* <p>The behavior of decoding depends on the {@link Context} in which it is used. When decoding
177-
* in {@link Context#OUTER}, the value is expected to consume the entire remaining stream. In
178-
* {@link Context#NESTED}, the value is part of a larger structure, so the coder must rely on
179-
* encoded boundaries (such as length prefixes) to correctly extract individual elements.
139+
* Decodes a value of type {@code T} from the given input stream in the given context. Returns the
140+
* decoded value. Multiple elements can be encoded next to each other on the input stream, each
141+
* coder should encode information to know how many bytes to read when decoding. A common approach
142+
* is to prefix the encoding with the element's encoded length.
180143
*
181144
* @throws IOException if reading from the {@code InputStream} fails for some reason
182145
* @throws CoderException if the value could not be decoded for some reason

0 commit comments

Comments
 (0)