1 /*
2 * Copyright 2012 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package io.netty5.handler.codec;
17
18 import io.netty5.buffer.api.Buffer;
19
20 import static io.netty5.buffer.api.DefaultBufferAllocators.onHeapAllocator;
21
22 /**
23 * A set of commonly used delimiters for {@link DelimiterBasedFrameDecoder}.
24 */
25 public final class Delimiters {
26
27 /**
28 * Returns a {@code NUL (0x00)} delimiter, which could be used for
29 * Flash XML socket or any similar protocols.
30 */
31 public static Buffer[] nulDelimiter() {
32 return new Buffer[] {
33 onHeapAllocator().copyOf(new byte[] { 0 }).makeReadOnly()
34 };
35 }
36
37 /**
38 * Returns {@code CR ('\r')} and {@code LF ('\n')} delimiters, which could
39 * be used for text-based line protocols.
40 */
41 public static Buffer[] lineDelimiter() {
42 return new Buffer[] {
43 onHeapAllocator().copyOf(new byte[] { '\r', '\n' }).makeReadOnly(),
44 onHeapAllocator().copyOf(new byte[] { '\n' }).makeReadOnly(),
45 };
46 }
47
48 private Delimiters() {
49 // Unused
50 }
51 }