Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package swim.ws;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
public abstract class WsEncoder {
public abstract boolean isMasked();
public abstract void maskingKey(byte[] maskingKey);
public Encoder, WsFrame> frameEncoder(WsFrame frame) {
final WsOpcode opcode = frame.opcode();
switch (opcode) {
case CONTINUATION: return Encoder.error(new EncoderException("invalid opcode: " + opcode));
case TEXT: return textFrameEncoder(frame);
case BINARY: return binaryFrameEncoder(frame);
case CLOSE: return closeFrameEncoder(frame);
case PING: return pingFrameEncoder(frame);
case PONG: return pongFrameEncoder(frame);
default: return Encoder.error(new EncoderException("reserved opcode: " + opcode));
}
}
public Encoder, WsFrame> encodeFrame(WsFrame frame, OutputBuffer> output) {
final WsOpcode opcode = frame.opcode();
switch (opcode) {
case CONTINUATION: return Encoder.error(new EncoderException("invalid opcode: " + opcode));
case TEXT: return encodeTextFrame(frame, output);
case BINARY: return encodeBinaryFrame(frame, output);
case CLOSE: return encodeCloseFrame(frame, output);
case PING: return encodePingFrame(frame, output);
case PONG: return encodePongFrame(frame, output);
default: return Encoder.error(new EncoderException("reserved opcode: " + opcode));
}
}
public Encoder, WsFrame> textFrameEncoder(WsFrame frame) {
return new WsFrameEncoder(this, frame);
}
public Encoder, WsFrame> encodeTextFrame(WsFrame frame, OutputBuffer> output) {
return WsFrameEncoder.encode(output, this, frame);
}
public Encoder, WsFrame> binaryFrameEncoder(WsFrame frame) {
return new WsFrameEncoder(this, frame);
}
public Encoder, WsFrame> encodeBinaryFrame(WsFrame frame, OutputBuffer> output) {
return WsFrameEncoder.encode(output, this, frame);
}
public Encoder, WsFrame> closeFrameEncoder(WsFrame frame) {
return new WsFrameEncoder(this, frame);
}
public Encoder, WsFrame> encodeCloseFrame(WsFrame frame, OutputBuffer> output) {
return WsFrameEncoder.encode(output, this, frame);
}
public Encoder, WsFrame> pingFrameEncoder(WsFrame frame) {
return new WsFrameEncoder(this, frame);
}
public Encoder, WsFrame> encodePingFrame(WsFrame frame, OutputBuffer> output) {
return WsFrameEncoder.encode(output, this, frame);
}
public Encoder, WsFrame> pongFrameEncoder(WsFrame frame) {
return new WsFrameEncoder(this, frame);
}
public Encoder, WsFrame> encodePongFrame(WsFrame frame, OutputBuffer> output) {
return WsFrameEncoder.encode(output, this, frame);
}
}