|
39 | 39 | /**
|
40 | 40 | * The Bind message.
|
41 | 41 | */
|
42 |
| -public final class Bind implements FrontendMessage { |
| 42 | +public final class Bind implements FrontendMessage, FrontendMessage.DirectEncoder { |
43 | 43 |
|
44 | 44 | /**
|
45 | 45 | * A marker indicating a {@code NULL} value.
|
@@ -95,30 +95,41 @@ public Publisher<ByteBuf> encode(ByteBufAllocator byteBufAllocator) {
|
95 | 95 | return Mono.fromSupplier(() -> {
|
96 | 96 | ByteBuf out = byteBufAllocator.ioBuffer();
|
97 | 97 |
|
98 |
| - writeByte(out, 'B'); |
99 |
| - writeLengthPlaceholder(out); |
100 |
| - writeCStringUTF8(out, this.name); |
101 |
| - writeCStringUTF8(out, this.source); |
102 |
| - |
103 |
| - writeShort(out, this.parameterFormats.size()); |
104 |
| - this.parameterFormats.forEach(format -> writeShort(out, format.getDiscriminator())); |
105 |
| - |
106 |
| - writeShort(out, this.parameters.size()); |
107 |
| - this.parameters.forEach(parameters -> { |
108 |
| - if (parameters == NULL_VALUE) { |
109 |
| - writeInt(out, NULL); |
110 |
| - } else { |
111 |
| - writeInt(out, parameters.readableBytes()); |
112 |
| - writeBytes(out, parameters); |
113 |
| - parameters.release(); |
114 |
| - } |
115 |
| - }); |
116 |
| - |
117 |
| - writeShort(out, this.resultFormats.size()); |
118 |
| - this.resultFormats.forEach(format -> writeShort(out, format.getDiscriminator())); |
119 |
| - |
120 |
| - return writeSize(out); |
| 98 | + encode(out); |
| 99 | + |
| 100 | + return out; |
| 101 | + }); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public void encode(ByteBuf byteBuf) { |
| 106 | + |
| 107 | + writeByte(byteBuf, 'B'); |
| 108 | + |
| 109 | + int writerIndex = byteBuf.writerIndex(); |
| 110 | + |
| 111 | + writeLengthPlaceholder(byteBuf); |
| 112 | + writeCStringUTF8(byteBuf, this.name); |
| 113 | + writeCStringUTF8(byteBuf, this.source); |
| 114 | + |
| 115 | + writeShort(byteBuf, this.parameterFormats.size()); |
| 116 | + this.parameterFormats.forEach(format -> writeShort(byteBuf, format.getDiscriminator())); |
| 117 | + |
| 118 | + writeShort(byteBuf, this.parameters.size()); |
| 119 | + this.parameters.forEach(parameters -> { |
| 120 | + if (parameters == NULL_VALUE) { |
| 121 | + writeInt(byteBuf, NULL); |
| 122 | + } else { |
| 123 | + writeInt(byteBuf, parameters.readableBytes()); |
| 124 | + writeBytes(byteBuf, parameters); |
| 125 | + parameters.release(); |
| 126 | + } |
121 | 127 | });
|
| 128 | + |
| 129 | + writeShort(byteBuf, this.resultFormats.size()); |
| 130 | + this.resultFormats.forEach(format -> writeShort(byteBuf, format.getDiscriminator())); |
| 131 | + |
| 132 | + writeSize(byteBuf, writerIndex); |
122 | 133 | }
|
123 | 134 |
|
124 | 135 | @Override
|
|
0 commit comments