index int64 | repo_id string | file_path string | content string |
|---|---|---|---|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPingRespEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class MqttPingRespEncoder extends Encoder<Object, MqttPingResp> {
final MqttEncoder mqtt;
final MqttPingResp packet;
final int length;
final int remaining;
final int step;
MqttPingRespEncoder(MqttEncoder mqtt, MqttPingResp packet, int length, int remaining, int step) {
this.mqtt = mqtt;
this.packet = packet;
this.length = length;
this.remaining = remaining;
this.step = step;
}
MqttPingRespEncoder(MqttEncoder mqtt, MqttPingResp packet) {
this(mqtt, packet, 0, 0, 1);
}
@Override
public Encoder<Object, MqttPingResp> pull(OutputBuffer<?> output) {
return encode(output, this.mqtt, this.packet, this.length, this.remaining, this.step);
}
static Encoder<Object, MqttPingResp> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPingResp packet, int length, int remaining, int step) {
if (step == 1 && output.isCont()) {
length = packet.bodySize(mqtt);
remaining = length;
output = output.write(packet.packetType() << 4 | packet.packetFlags & 0x0f);
step = 2;
}
while (step >= 2 && step <= 5 && output.isCont()) {
int b = length & 0x7f;
length = length >>> 7;
if (length > 0) {
b |= 0x80;
}
output = output.write(b);
if (length == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long: " + remaining));
}
}
if (step == 6 && remaining == 0) {
return done(packet);
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttPingRespEncoder(mqtt, packet, length, remaining, step);
}
static Encoder<Object, MqttPingResp> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPingResp packet) {
return encode(output, mqtt, packet, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubAck.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.util.Murmur3;
public final class MqttPubAck extends MqttPacket<Object> implements Debug {
final int packetFlags;
final int packetId;
MqttPubAck(int packetFlags, int packetId) {
this.packetFlags = packetFlags;
this.packetId = packetId;
}
@Override
public int packetType() {
return 4;
}
@Override
public int packetFlags() {
return this.packetFlags;
}
public MqttPubAck packetFlags(int packetFlags) {
return new MqttPubAck(packetFlags, this.packetId);
}
public int packetId() {
return this.packetId;
}
public MqttPubAck packetId(int packetId) {
return new MqttPubAck(this.packetFlags, packetId);
}
@Override
int bodySize(MqttEncoder mqtt) {
return 2;
}
@Override
public Encoder<?, MqttPubAck> mqttEncoder(MqttEncoder mqtt) {
return mqtt.pubAckEncoder(this);
}
@Override
public Encoder<?, MqttPubAck> encodeMqtt(OutputBuffer<?> output, MqttEncoder mqtt) {
return mqtt.encodePubAck(this, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttPubAck) {
final MqttPubAck that = (MqttPubAck) other;
return this.packetFlags == that.packetFlags && this.packetId == that.packetId;
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttPubAck.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.packetFlags), this.packetId));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttPubAck").write('.').write("from").write('(')
.debug(this.packetId).write(')');
if (this.packetFlags != 0) {
output = output.write('.').write("packetFlags").write('(').debug(this.packetFlags).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static MqttPubAck from(int packetFlags, int packetId) {
return new MqttPubAck(packetFlags, packetId);
}
public static MqttPubAck from(int packetId) {
return new MqttPubAck(0, packetId);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubAckDecoder.java | // 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.mqtt;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class MqttPubAckDecoder extends Decoder<MqttPubAck> {
final MqttDecoder mqtt;
final int packetFlags;
final int packetId;
final int remaining;
final int step;
MqttPubAckDecoder(MqttDecoder mqtt, int packetFlags, int packetId, int remaining, int step) {
this.mqtt = mqtt;
this.packetFlags = packetFlags;
this.packetId = packetId;
this.remaining = remaining;
this.step = step;
}
MqttPubAckDecoder(MqttDecoder mqtt) {
this(mqtt, 0, 0, 0, 1);
}
@Override
public Decoder<MqttPubAck> feed(InputBuffer input) {
return decode(input, this.mqtt, this.packetFlags, this.packetId, this.remaining, this.step);
}
static Decoder<MqttPubAck> decode(InputBuffer input, MqttDecoder mqtt,
int packetFlags, int packetId, int remaining, int step) {
if (step == 1 && input.isCont()) {
packetFlags = input.head() & 0x0f;
input = input.step();
step = 2;
}
while (step >= 2 && step <= 5 && input.isCont()) {
final int b = input.head();
input = input.step();
remaining |= (b & 0x7f) << (7 * (step - 2));
if ((b & 0x80) == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long"));
}
}
if (step == 6 && remaining > 0 && input.isCont()) {
packetId = input.head() << 8;
input = input.step();
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && input.isCont()) {
packetId |= input.head();
input = input.step();
remaining -= 1;
step = 8;
}
if (step == 8 && remaining == 0) {
return done(mqtt.pubAck(packetFlags, packetId));
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new MqttPubAckDecoder(mqtt, packetFlags, packetId, remaining, step);
}
static Decoder<MqttPubAck> decode(InputBuffer input, MqttDecoder mqtt) {
return decode(input, mqtt, 0, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubAckEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class MqttPubAckEncoder extends Encoder<Object, MqttPubAck> {
final MqttEncoder mqtt;
final MqttPubAck packet;
final int length;
final int remaining;
final int step;
MqttPubAckEncoder(MqttEncoder mqtt, MqttPubAck packet, int length, int remaining, int step) {
this.mqtt = mqtt;
this.packet = packet;
this.length = length;
this.remaining = remaining;
this.step = step;
}
MqttPubAckEncoder(MqttEncoder mqtt, MqttPubAck packet) {
this(mqtt, packet, 0, 0, 1);
}
@Override
public Encoder<Object, MqttPubAck> pull(OutputBuffer<?> output) {
return encode(output, this.mqtt, this.packet, this.length, this.remaining, this.step);
}
static Encoder<Object, MqttPubAck> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPubAck packet, int length, int remaining, int step) {
if (step == 1 && output.isCont()) {
length = packet.bodySize(mqtt);
remaining = length;
output = output.write(packet.packetType() << 4 | packet.packetFlags & 0x0f);
step = 2;
}
while (step >= 2 && step <= 5 && output.isCont()) {
int b = length & 0x7f;
length = length >>> 7;
if (length > 0) {
b |= 0x80;
}
output = output.write(b);
if (length == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long: " + remaining));
}
}
if (step == 6 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId >>> 8);
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId);
remaining -= 1;
step = 8;
}
if (step == 8 && remaining == 0) {
return done(packet);
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttPubAckEncoder(mqtt, packet, length, remaining, step);
}
static Encoder<Object, MqttPubAck> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPubAck packet) {
return encode(output, mqtt, packet, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubComp.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.util.Murmur3;
public final class MqttPubComp extends MqttPacket<Object> implements Debug {
final int packetFlags;
final int packetId;
MqttPubComp(int packetFlags, int packetId) {
this.packetFlags = packetFlags;
this.packetId = packetId;
}
@Override
public int packetType() {
return 7;
}
@Override
public int packetFlags() {
return this.packetFlags;
}
public MqttPubComp packetFlags(int packetFlags) {
return new MqttPubComp(packetFlags, this.packetId);
}
public int packetId() {
return this.packetId;
}
public MqttPubComp packetId(int packetId) {
return new MqttPubComp(this.packetFlags, packetId);
}
@Override
int bodySize(MqttEncoder mqtt) {
return 2;
}
@Override
public Encoder<?, MqttPubComp> mqttEncoder(MqttEncoder mqtt) {
return mqtt.pubCompEncoder(this);
}
@Override
public Encoder<?, MqttPubComp> encodeMqtt(OutputBuffer<?> output, MqttEncoder mqtt) {
return mqtt.encodePubComp(this, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttPubComp) {
final MqttPubComp that = (MqttPubComp) other;
return this.packetFlags == that.packetFlags && this.packetId == that.packetId;
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttPubComp.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.packetFlags), this.packetId));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttPubComp").write('.').write("from").write('(')
.debug(this.packetId).write(')');
if (this.packetFlags != 0) {
output = output.write('.').write("packetFlags").write('(').debug(this.packetFlags).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static MqttPubComp from(int packetFlags, int packetId) {
return new MqttPubComp(packetFlags, packetId);
}
public static MqttPubComp from(int packetId) {
return new MqttPubComp(0, packetId);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubCompDecoder.java | // 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.mqtt;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class MqttPubCompDecoder extends Decoder<MqttPubComp> {
final MqttDecoder mqtt;
final int packetFlags;
final int packetId;
final int remaining;
final int step;
MqttPubCompDecoder(MqttDecoder mqtt, int packetFlags, int packetId, int remaining, int step) {
this.mqtt = mqtt;
this.packetFlags = packetFlags;
this.packetId = packetId;
this.remaining = remaining;
this.step = step;
}
MqttPubCompDecoder(MqttDecoder mqtt) {
this(mqtt, 0, 0, 0, 1);
}
@Override
public Decoder<MqttPubComp> feed(InputBuffer input) {
return decode(input, this.mqtt, this.packetFlags, this.packetId, this.remaining, this.step);
}
static Decoder<MqttPubComp> decode(InputBuffer input, MqttDecoder mqtt,
int packetFlags, int packetId, int remaining, int step) {
if (step == 1 && input.isCont()) {
packetFlags = input.head() & 0x0f;
input = input.step();
step = 2;
}
while (step >= 2 && step <= 5 && input.isCont()) {
final int b = input.head();
input = input.step();
remaining |= (b & 0x7f) << (7 * (step - 2));
if ((b & 0x80) == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long"));
}
}
if (step == 6 && remaining > 0 && input.isCont()) {
packetId = input.head() << 8;
input = input.step();
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && input.isCont()) {
packetId |= input.head();
input = input.step();
remaining -= 1;
step = 8;
}
if (step == 8 && remaining == 0) {
return done(mqtt.pubComp(packetFlags, packetId));
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new MqttPubCompDecoder(mqtt, packetFlags, packetId, remaining, step);
}
static Decoder<MqttPubComp> decode(InputBuffer input, MqttDecoder mqtt) {
return decode(input, mqtt, 0, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubCompEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class MqttPubCompEncoder extends Encoder<Object, MqttPubComp> {
final MqttEncoder mqtt;
final MqttPubComp packet;
final int length;
final int remaining;
final int step;
MqttPubCompEncoder(MqttEncoder mqtt, MqttPubComp packet, int length, int remaining, int step) {
this.mqtt = mqtt;
this.packet = packet;
this.length = length;
this.remaining = remaining;
this.step = step;
}
MqttPubCompEncoder(MqttEncoder mqtt, MqttPubComp packet) {
this(mqtt, packet, 0, 0, 1);
}
@Override
public Encoder<Object, MqttPubComp> pull(OutputBuffer<?> output) {
return encode(output, this.mqtt, this.packet, this.length, this.remaining, this.step);
}
static Encoder<Object, MqttPubComp> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPubComp packet, int length, int remaining, int step) {
if (step == 1 && output.isCont()) {
length = packet.bodySize(mqtt);
remaining = length;
output = output.write(packet.packetType() << 4 | packet.packetFlags & 0x0f);
step = 2;
}
while (step >= 2 && step <= 5 && output.isCont()) {
int b = length & 0x7f;
length = length >>> 7;
if (length > 0) {
b |= 0x80;
}
output = output.write(b);
if (length == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long: " + remaining));
}
}
if (step == 6 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId >>> 8);
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId);
remaining -= 1;
step = 8;
}
if (step == 8 && remaining == 0) {
return done(packet);
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttPubCompEncoder(mqtt, packet, length, remaining, step);
}
static Encoder<Object, MqttPubComp> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPubComp packet) {
return encode(output, mqtt, packet, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubRec.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.util.Murmur3;
public final class MqttPubRec extends MqttPacket<Object> implements Debug {
final int packetFlags;
final int packetId;
MqttPubRec(int packetFlags, int packetId) {
this.packetFlags = packetFlags;
this.packetId = packetId;
}
@Override
public int packetType() {
return 5;
}
@Override
public int packetFlags() {
return this.packetFlags;
}
public MqttPubRec packetFlags(int packetFlags) {
return new MqttPubRec(packetFlags, this.packetId);
}
public int packetId() {
return this.packetId;
}
public MqttPubRec packetId(int packetId) {
return new MqttPubRec(this.packetFlags, packetId);
}
@Override
int bodySize(MqttEncoder mqtt) {
return 2;
}
@Override
public Encoder<?, MqttPubRec> mqttEncoder(MqttEncoder mqtt) {
return mqtt.pubRecEncoder(this);
}
@Override
public Encoder<?, MqttPubRec> encodeMqtt(OutputBuffer<?> output, MqttEncoder mqtt) {
return mqtt.encodePubRec(this, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttPubRec) {
final MqttPubRec that = (MqttPubRec) other;
return this.packetFlags == that.packetFlags && this.packetId == that.packetId;
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttPubRec.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.packetFlags), this.packetId));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttPubRec").write('.').write("from").write('(')
.debug(this.packetId).write(')');
if (this.packetFlags != 0) {
output = output.write('.').write("packetFlags").write('(').debug(this.packetFlags).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static MqttPubRec from(int packetFlags, int packetId) {
return new MqttPubRec(packetFlags, packetId);
}
public static MqttPubRec from(int packetId) {
return new MqttPubRec(0, packetId);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubRecDecoder.java | // 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.mqtt;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class MqttPubRecDecoder extends Decoder<MqttPubRec> {
final MqttDecoder mqtt;
final int packetFlags;
final int remaining;
final int packetId;
final int step;
MqttPubRecDecoder(MqttDecoder mqtt, int packetFlags, int packetId, int remaining, int step) {
this.mqtt = mqtt;
this.packetFlags = packetFlags;
this.packetId = packetId;
this.remaining = remaining;
this.step = step;
}
MqttPubRecDecoder(MqttDecoder mqtt) {
this(mqtt, 0, 0, 0, 1);
}
@Override
public Decoder<MqttPubRec> feed(InputBuffer input) {
return decode(input, this.mqtt, this.packetFlags, this.packetId, this.remaining, this.step);
}
static Decoder<MqttPubRec> decode(InputBuffer input, MqttDecoder mqtt,
int packetFlags, int packetId, int remaining, int step) {
if (step == 1 && input.isCont()) {
packetFlags = input.head() & 0x0f;
input = input.step();
step = 2;
}
while (step >= 2 && step <= 5 && input.isCont()) {
final int b = input.head();
input = input.step();
remaining |= (b & 0x7f) << (7 * (step - 2));
if ((b & 0x80) == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long"));
}
}
if (step == 6 && remaining > 0 && input.isCont()) {
packetId = input.head() << 8;
input = input.step();
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && input.isCont()) {
packetId |= input.head();
input = input.step();
remaining -= 1;
step = 8;
}
if (step == 8 && remaining == 0) {
return done(mqtt.pubRec(packetFlags, packetId));
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new MqttPubRecDecoder(mqtt, packetFlags, packetId, remaining, step);
}
static Decoder<MqttPubRec> decode(InputBuffer input, MqttDecoder mqtt) {
return decode(input, mqtt, 0, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubRecEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class MqttPubRecEncoder extends Encoder<Object, MqttPubRec> {
final MqttEncoder mqtt;
final MqttPubRec packet;
final int length;
final int remaining;
final int step;
MqttPubRecEncoder(MqttEncoder mqtt, MqttPubRec packet, int length, int remaining, int step) {
this.mqtt = mqtt;
this.packet = packet;
this.length = length;
this.remaining = remaining;
this.step = step;
}
MqttPubRecEncoder(MqttEncoder mqtt, MqttPubRec packet) {
this(mqtt, packet, 0, 0, 1);
}
@Override
public Encoder<Object, MqttPubRec> pull(OutputBuffer<?> output) {
return encode(output, this.mqtt, this.packet, this.length, this.remaining, this.step);
}
static Encoder<Object, MqttPubRec> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPubRec packet, int length, int remaining, int step) {
if (step == 1 && output.isCont()) {
length = packet.bodySize(mqtt);
remaining = length;
output = output.write(packet.packetType() << 4 | packet.packetFlags & 0x0f);
step = 2;
}
while (step >= 2 && step <= 5 && output.isCont()) {
int b = length & 0x7f;
length = length >>> 7;
if (length > 0) {
b |= 0x80;
}
output = output.write(b);
if (length == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long: " + remaining));
}
}
if (step == 6 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId >>> 8);
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId);
remaining -= 1;
step = 8;
}
if (step == 8 && remaining == 0) {
return done(packet);
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttPubRecEncoder(mqtt, packet, length, remaining, step);
}
static Encoder<Object, MqttPubRec> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPubRec packet) {
return encode(output, mqtt, packet, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubRel.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.util.Murmur3;
public final class MqttPubRel extends MqttPacket<Object> implements Debug {
final int packetFlags;
final int packetId;
MqttPubRel(int packetFlags, int packetId) {
this.packetFlags = packetFlags;
this.packetId = packetId;
}
@Override
public int packetType() {
return 6;
}
@Override
public int packetFlags() {
return this.packetFlags;
}
public MqttPubRel packetFlags(int packetFlags) {
return new MqttPubRel(packetFlags, this.packetId);
}
public int packetId() {
return packetId;
}
public MqttPubRel packetId(int packetId) {
return new MqttPubRel(this.packetFlags, packetId);
}
@Override
int bodySize(MqttEncoder mqtt) {
return 2;
}
@Override
public Encoder<?, MqttPubRel> mqttEncoder(MqttEncoder mqtt) {
return mqtt.pubRelEncoder(this);
}
@Override
public Encoder<?, MqttPubRel> encodeMqtt(OutputBuffer<?> output, MqttEncoder mqtt) {
return mqtt.encodePubRel(this, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttPubRel) {
final MqttPubRel that = (MqttPubRel) other;
return this.packetFlags == that.packetFlags && this.packetId == that.packetId;
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttPubRel.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.packetFlags), this.packetId));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttPubRel").write('.').write("from").write('(')
.debug(this.packetId).write(')');
if (this.packetFlags != 2) {
output = output.write('.').write("packetFlags").write('(').debug(this.packetFlags).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static MqttPubRel from(int packetFlags, int packetId) {
return new MqttPubRel(packetFlags, packetId);
}
public static MqttPubRel from(int packetId) {
return new MqttPubRel(2, packetId);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubRelDecoder.java | // 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.mqtt;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class MqttPubRelDecoder extends Decoder<MqttPubRel> {
final MqttDecoder mqtt;
final int packetFlags;
final int packetId;
final int remaining;
final int step;
MqttPubRelDecoder(MqttDecoder mqtt, int packetFlags, int packetId, int remaining, int step) {
this.mqtt = mqtt;
this.packetFlags = packetFlags;
this.packetId = packetId;
this.remaining = remaining;
this.step = step;
}
MqttPubRelDecoder(MqttDecoder mqtt) {
this(mqtt, 0, 0, 0, 1);
}
@Override
public Decoder<MqttPubRel> feed(InputBuffer input) {
return decode(input, this.mqtt, this.packetFlags, this.packetId, this.remaining, this.step);
}
static Decoder<MqttPubRel> decode(InputBuffer input, MqttDecoder mqtt, int packetFlags,
int packetId, int remaining, int step) {
if (step == 1 && input.isCont()) {
packetFlags = input.head() & 0x0f;
input = input.step();
step = 2;
}
while (step >= 2 && step <= 5 && input.isCont()) {
final int b = input.head();
input = input.step();
remaining |= (b & 0x7f) << (7 * (step - 2));
if ((b & 0x80) == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long"));
}
}
if (step == 6 && remaining > 0 && input.isCont()) {
packetId = input.head() << 8;
input = input.step();
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && input.isCont()) {
packetId |= input.head();
input = input.step();
remaining -= 1;
step = 8;
}
if (step == 8 && remaining == 0) {
return done(mqtt.pubRel(packetFlags, packetId));
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new MqttPubRelDecoder(mqtt, packetFlags, packetId, remaining, step);
}
static Decoder<MqttPubRel> decode(InputBuffer input, MqttDecoder mqtt) {
return decode(input, mqtt, 0, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPubRelEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class MqttPubRelEncoder extends Encoder<Object, MqttPubRel> {
final MqttEncoder mqtt;
final MqttPubRel packet;
final int length;
final int remaining;
final int step;
MqttPubRelEncoder(MqttEncoder mqtt, MqttPubRel packet, int length, int remaining, int step) {
this.mqtt = mqtt;
this.packet = packet;
this.length = length;
this.remaining = remaining;
this.step = step;
}
MqttPubRelEncoder(MqttEncoder mqtt, MqttPubRel packet) {
this(mqtt, packet, 0, 0, 1);
}
@Override
public Encoder<Object, MqttPubRel> pull(OutputBuffer<?> output) {
return encode(output, this.mqtt, this.packet, this.length, this.remaining, this.step);
}
static Encoder<Object, MqttPubRel> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPubRel packet, int length, int remaining, int step) {
if (step == 1 && output.isCont()) {
length = packet.bodySize(mqtt);
remaining = length;
output = output.write(packet.packetType() << 4 | packet.packetFlags & 0x0f);
step = 2;
}
while (step >= 2 && step <= 5 && output.isCont()) {
int b = length & 0x7f;
length = length >>> 7;
if (length > 0) {
b |= 0x80;
}
output = output.write(b);
if (length == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long: " + remaining));
}
}
if (step == 6 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId >>> 8);
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId);
remaining -= 1;
step = 8;
}
if (step == 8 && remaining == 0) {
return done(packet);
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttPubRelEncoder(mqtt, packet, length, remaining, step);
}
static Encoder<Object, MqttPubRel> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPubRel packet) {
return encode(output, mqtt, packet, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPublish.java | // 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.mqtt;
import java.nio.ByteBuffer;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.util.Murmur3;
public final class MqttPublish<T> extends MqttPacket<T> implements Debug {
final int packetFlags;
final String topicName;
final int packetId;
final MqttEntity<T> payload;
MqttPublish(int packetFlags, String topicName, int packetId, MqttEntity<T> payload) {
this.packetFlags = packetFlags;
this.topicName = topicName;
this.packetId = packetId;
this.payload = payload;
}
@Override
public int packetType() {
return 3;
}
@Override
public int packetFlags() {
return this.packetFlags;
}
public boolean retain() {
return (this.packetFlags & RETAIN_FLAG) != 0;
}
public MqttPublish<T> retain(boolean retain) {
final int packetFlags = retain ? this.packetFlags | RETAIN_FLAG : this.packetFlags & ~RETAIN_FLAG;
return new MqttPublish<T>(packetFlags, this.topicName, this.packetId, this.payload);
}
public MqttQoS qos() {
return MqttQoS.from((this.packetFlags & QOS_MASK) >>> QOS_SHIFT);
}
public MqttPublish<T> qos(MqttQoS qos) {
final int packetFlags = this.packetFlags & ~QOS_MASK | (qos.code << QOS_SHIFT) & QOS_MASK;
return new MqttPublish<T>(packetFlags, this.topicName, this.packetId, this.payload);
}
public boolean dup() {
return (this.packetFlags & DUP_FLAG) != 0;
}
public MqttPublish<T> dup(boolean dup) {
final int packetFlags = dup ? this.packetFlags | DUP_FLAG : this.packetFlags & ~DUP_FLAG;
return new MqttPublish<T>(packetFlags, this.topicName, this.packetId, this.payload);
}
public String topicName() {
return this.topicName;
}
public MqttPublish<T> topicName(String topicName) {
return new MqttPublish<T>(this.packetFlags, topicName, this.packetId, this.payload);
}
public boolean hasPacketId() {
return ((this.packetFlags & QOS_MASK) >>> QOS_SHIFT) != 0;
}
public int packetId() {
return this.packetId;
}
public MqttPublish<T> packetId(int packetId) {
return new MqttPublish<T>(this.packetFlags, this.topicName, packetId, this.payload);
}
public MqttEntity<T> payload() {
return this.payload;
}
public <U> MqttPublish<U> payload(MqttEntity<U> payload) {
return new MqttPublish<U>(this.packetFlags, this.topicName, this.packetId, payload);
}
public <U> MqttPublish<U> payload(Encoder<?, ?> content, int length) {
return new MqttPublish<U>(packetFlags, topicName, packetId, MqttPayload.<U>from(content, length));
}
public <U> MqttPublish<U> payload(ByteBuffer data) {
return new MqttPublish<U>(packetFlags, topicName, packetId, MqttPayload.<U>from(data));
}
public MqttPublish<String> payload(String content) {
return new MqttPublish<String>(packetFlags, topicName, packetId, MqttPayload.from(content));
}
@Override
int bodySize(MqttEncoder mqtt) {
int size = mqtt.sizeOfString(this.topicName);
if (hasPacketId()) {
size += 2;
}
size += payload.mqttSize();
return size;
}
@Override
public Encoder<?, MqttPublish<T>> mqttEncoder(MqttEncoder mqtt) {
return mqtt.publishEncoder(this);
}
@Override
public Encoder<?, MqttPublish<T>> encodeMqtt(OutputBuffer<?> output, MqttEncoder mqtt) {
return mqtt.encodePublish(this, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttPublish) {
final MqttPublish<?> that = (MqttPublish<?>) other;
return this.packetFlags == that.packetFlags && this.topicName.equals(that.topicName)
&& this.packetId == that.packetId && this.payload.equals(that.payload);
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttPublish.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed,
this.packetFlags), this.topicName.hashCode()), this.packetId), this.payload.hashCode()));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttPublish").write('.').write("from").write('(')
.debug(this.topicName).write(')');
if (this.packetFlags != 0) {
output = output.write('.').write("packetFlags").write('(').debug(this.packetFlags).write(')');
}
if (retain()) {
output = output.write('.').write("retain").write('(').write("true").write(')');
}
if (qos().code != 0) {
output = output.write('.').write("qos").write('(').debug(qos()).write(')');
}
if (dup()) {
output = output.write('.').write("dup").write('(').write("true").write(')');
}
if (hasPacketId()) {
output = output.write('.').write("packetId").write('(').debug(this.packetId).write(')');
}
if (payload.isDefined()) {
output = output.write('.').write("payload").write('(').debug(this.payload).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
static final int RETAIN_FLAG = 0x01;
static final int QOS_MASK = 0x06;
static final int QOS_SHIFT = 1;
static final int DUP_FLAG = 0x08;
private static int hashSeed;
public static <T> MqttPublish<T> from(int packetFlags, String topicName,
int packetId, MqttEntity<T> payload) {
return new MqttPublish<T>(packetFlags, topicName, packetId, payload);
}
public static <T> MqttPublish<T> from(String topicName, int packetId, MqttEntity<T> payload) {
return new MqttPublish<T>(0, topicName, packetId, payload);
}
public static <T> MqttPublish<T> from(String topicName, MqttEntity<T> payload) {
return new MqttPublish<T>(0, topicName, 0, payload);
}
public static MqttPublish<Object> from(String topicName) {
return new MqttPublish<Object>(0, topicName, 0, MqttEntity.empty());
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPublishDecoder.java | // 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.mqtt;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class MqttPublishDecoder<T> extends Decoder<MqttPublish<T>> {
final MqttDecoder mqtt;
final Decoder<T> payload;
final int packetFlags;
final Decoder<String> topicName;
final int packetId;
final int remaining;
final int step;
MqttPublishDecoder(MqttDecoder mqtt, Decoder<T> payload, int packetFlags,
Decoder<String> topicName, int packetId, int remaining, int step) {
this.mqtt = mqtt;
this.payload = payload;
this.packetFlags = packetFlags;
this.topicName = topicName;
this.packetId = packetId;
this.remaining = remaining;
this.step = step;
}
MqttPublishDecoder(MqttDecoder mqtt, Decoder<T> payload) {
this(mqtt, payload, 0, null, 0, 0, 1);
}
@Override
public Decoder<MqttPublish<T>> feed(InputBuffer input) {
return decode(input, this.mqtt, this.payload, this.packetFlags,
this.topicName, this.packetId, this.remaining, this.step);
}
static <T> Decoder<MqttPublish<T>> decode(InputBuffer input, MqttDecoder mqtt, Decoder<T> payload,
int packetFlags, Decoder<String> topicName,
int packetId, int remaining, int step) {
if (step == 1 && input.isCont()) {
packetFlags = input.head() & 0x0f;
input = input.step();
step = 2;
}
while (step >= 2 && step <= 5 && input.isCont()) {
final int b = input.head();
input = input.step();
remaining |= (b & 0x7f) << (7 * (step - 2));
if ((b & 0x80) == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long"));
}
}
if (step == 6) {
final int inputStart = input.index();
final int inputLimit = input.limit();
final int inputRemaining = inputLimit - inputStart;
if (remaining < inputRemaining) {
input = input.limit(inputStart + remaining);
}
final boolean inputPart = input.isPart();
input = input.isPart(remaining > inputRemaining);
if (topicName == null) {
topicName = mqtt.decodeString(input);
} else {
topicName = topicName.feed(input);
}
input = input.limit(inputLimit).isPart(inputPart);
remaining -= input.index() - inputStart;
if (topicName.isDone()) {
if (((packetFlags & MqttPublish.QOS_MASK) >>> MqttPublish.QOS_SHIFT) != 0) {
step = 7;
} else {
step = 9;
}
} else if (topicName.isError()) {
return topicName.asError();
}
}
if (step == 7 && remaining > 0 && input.isCont()) {
packetId = input.head() << 8;
input = input.step();
remaining -= 1;
step = 8;
}
if (step == 8 && remaining > 0 && input.isCont()) {
packetId |= input.head();
input = input.step();
remaining -= 1;
step = 9;
}
if (step == 9) {
final int inputStart = input.index();
final int inputLimit = input.limit();
final int inputRemaining = inputLimit - inputStart;
if (remaining < inputRemaining) {
input = input.limit(inputStart + remaining);
}
final boolean inputPart = input.isPart();
input = input.isPart(remaining > inputRemaining);
payload = payload.feed(input);
input = input.limit(inputLimit).isPart(inputPart);
remaining -= input.index() - inputStart;
if (payload.isDone()) {
step = 10;
} else if (payload.isError()) {
return payload.asError();
}
}
if (step == 10 && remaining == 0) {
return done(mqtt.publish(packetFlags, topicName.bind(), packetId,
MqttValue.from(payload.bind())));
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new MqttPublishDecoder<T>(mqtt, payload, packetFlags, topicName, packetId, remaining, step);
}
static <T> Decoder<MqttPublish<T>> decode(InputBuffer input, MqttDecoder mqtt,
Decoder<T> payload) {
return decode(input, mqtt, payload, 0, null, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttPublishEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class MqttPublishEncoder<T> extends Encoder<Object, MqttPublish<T>> {
final MqttEncoder mqtt;
final MqttPublish<T> packet;
final Encoder<?, ?> part;
final int length;
final int remaining;
final int step;
MqttPublishEncoder(MqttEncoder mqtt, MqttPublish<T> packet,
Encoder<?, ?> part, int length, int remaining, int step) {
this.mqtt = mqtt;
this.packet = packet;
this.part = part;
this.length = length;
this.remaining = remaining;
this.step = step;
}
MqttPublishEncoder(MqttEncoder mqtt, MqttPublish<T> packet) {
this(mqtt, packet, null, 0, 0, 1);
}
@Override
public Encoder<Object, MqttPublish<T>> pull(OutputBuffer<?> output) {
return encode(output, this.mqtt, this.packet, this.part, this.length, this.remaining, this.step);
}
static <T> Encoder<Object, MqttPublish<T>> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPublish<T> packet, Encoder<?, ?> part,
int length, int remaining, int step) {
if (step == 1 && output.isCont()) {
length = packet.bodySize(mqtt);
remaining = length;
output = output.write(packet.packetType() << 4 | packet.packetFlags & 0x0f);
step = 2;
}
while (step >= 2 && step <= 5 && output.isCont()) {
int b = length & 0x7f;
length = length >>> 7;
if (length > 0) {
b |= 0x80;
}
output = output.write(b);
if (length == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long: " + remaining));
}
}
if (step == 6) {
final int outputStart = output.index();
final int outputLimit = output.limit();
final int outputRemaining = outputLimit - outputStart;
if (remaining < outputRemaining) {
output = output.limit(outputStart + remaining);
}
final boolean outputPart = output.isPart();
output = output.isPart(remaining > outputRemaining);
if (part == null) {
part = mqtt.encodeString(packet.topicName, output);
} else {
part = part.pull(output);
}
output = output.limit(outputLimit).isPart(outputPart);
remaining -= output.index() - outputStart;
if (part.isDone()) {
part = null;
if (packet.hasPacketId()) {
step = 7;
} else {
step = 9;
}
} else if (part.isError()) {
return part.asError();
}
}
if (step == 7 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId >>> 8);
remaining -= 1;
step = 8;
}
if (step == 8 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId);
remaining -= 1;
step = 9;
}
if (step == 9) {
final int outputStart = output.index();
final int outputLimit = output.limit();
final int outputRemaining = outputLimit - outputStart;
if (remaining < outputRemaining) {
output = output.limit(outputStart + remaining);
}
final boolean outputPart = output.isPart();
output = output.isPart(remaining > outputRemaining);
if (part == null) {
part = packet.payload.encodeMqtt(output);
} else {
part = part.pull(output);
}
output = output.limit(outputLimit).isPart(outputPart);
remaining -= output.index() - outputStart;
if (part.isDone()) {
part = null;
step = 10;
} else if (part.isError()) {
return part.asError();
}
}
if (step == 10 && remaining == 0) {
return done(packet);
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttPublishEncoder<T>(mqtt, packet, part, length, remaining, step);
}
static <T> Encoder<Object, MqttPublish<T>> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttPublish<T> packet) {
return encode(output, mqtt, packet, null, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttQoS.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Output;
public enum MqttQoS implements Debug {
AT_MOST_ONCE(0),
AT_LEAST_ONCE(1),
EXACTLY_ONCE(2);
public final int code;
MqttQoS(int code) {
this.code = code;
}
public boolean isAtMostOnce() {
return this.code == 0;
}
public boolean isAtLeastOnce() {
return this.code == 1;
}
public boolean isExactlyOnce() {
return this.code == 2;
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttQoS").write('.').write(name());
}
public static MqttQoS from(int code) {
switch (code) {
case 0: return AT_MOST_ONCE;
case 1: return AT_LEAST_ONCE;
case 2: return EXACTLY_ONCE;
default: throw new IllegalArgumentException(Integer.toString(code));
}
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttStringDecoder.java | // 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.mqtt;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
import swim.codec.Utf8;
final class MqttStringDecoder extends Decoder<String> {
final Decoder<String> decoder;
final int remaining;
final int step;
MqttStringDecoder(Decoder<String> decoder, int remaining, int step) {
this.decoder = decoder;
this.remaining = remaining;
this.step = step;
}
MqttStringDecoder() {
this(null, 0, 1);
}
@Override
public Decoder<String> feed(InputBuffer input) {
return decode(input, this.decoder, this.remaining, this.step);
}
static Decoder<String> decode(InputBuffer input, Decoder<String> decoder, int remaining, int step) {
if (step == 1 && input.isCont()) {
remaining = input.head() << 8;
input = input.step();
step = 2;
}
if (step == 2 && input.isCont()) {
remaining |= input.head();
input = input.step();
step = 3;
}
if (step == 3) {
final int inputStart = input.index();
final int inputLimit = input.limit();
final int inputRemaining = inputLimit - inputStart;
if (remaining < inputRemaining) {
input = input.limit(inputStart + remaining);
}
final boolean inputPart = input.isPart();
input = input.isPart(remaining > inputRemaining);
if (decoder == null) {
decoder = Utf8.parseString(input);
} else {
decoder = decoder.feed(input);
}
input = input.limit(inputLimit).isPart(inputPart);
remaining -= input.index() - inputStart;
if (decoder.isDone()) {
return done(decoder.bind());
} else if (decoder.isError()) {
return decoder.asError();
}
}
if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new MqttStringDecoder(decoder, remaining, step);
}
static Decoder<String> decode(InputBuffer input) {
return decode(input, null, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttStringEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
import swim.codec.Utf8;
final class MqttStringEncoder extends Encoder<String, String> {
final String string;
final Encoder<?, ?> encoder;
final int length;
final int step;
MqttStringEncoder(String string, Encoder<?, ?> encoder, int length, int step) {
this.string = string;
this.encoder = encoder;
this.length = length;
this.step = step;
}
MqttStringEncoder(String string) {
this(string, null, 0, 1);
}
@Override
public Encoder<String, String> feed(String string) {
return new MqttStringEncoder(string, null, 0, 1);
}
@Override
public Encoder<String, String> pull(OutputBuffer<?> output) {
return encode(output, this.string, this.encoder, this.length, this.step);
}
static int sizeOf(String string) {
return 2 + Utf8.sizeOf(string);
}
static Encoder<String, String> encode(OutputBuffer<?> output, String string,
Encoder<?, ?> encoder, int length, int step) {
if (step == 1 && output.isCont()) {
length = Utf8.sizeOf(string);
if (length > 65535) {
return error(new MqttException("string too long (" + length + " bytes)"));
}
output = output.write(length >>> 8);
step = 2;
}
if (step == 2 && output.isCont()) {
output = output.write(length);
step = 3;
}
if (step == 3) {
if (encoder == null) {
encoder = Utf8.writeString(string, output);
} else {
encoder = encoder.pull(output);
}
if (encoder.isDone()) {
return done(string);
} else if (encoder.isError()) {
return encoder.asError();
}
}
if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttStringEncoder(string, encoder, length, step);
}
static Encoder<String, String> encode(OutputBuffer<?> output, String string) {
return encode(output, string, null, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttSubAck.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.collections.FingerTrieSeq;
import swim.util.Murmur3;
public final class MqttSubAck extends MqttPacket<Object> implements Debug {
final int packetFlags;
final int packetId;
final FingerTrieSeq<MqttSubStatus> subscriptions;
MqttSubAck(int packetFlags, int packetId, FingerTrieSeq<MqttSubStatus> subscriptions) {
this.packetFlags = packetFlags;
this.packetId = packetId;
this.subscriptions = subscriptions;
}
@Override
public int packetType() {
return 9;
}
@Override
public int packetFlags() {
return this.packetFlags;
}
public MqttSubAck packetFlags(int packetFlags) {
return new MqttSubAck(packetFlags, this.packetId, this.subscriptions);
}
public int packetId() {
return this.packetId;
}
public MqttSubAck packetId(int packetId) {
return new MqttSubAck(this.packetFlags, packetId, this.subscriptions);
}
public FingerTrieSeq<MqttSubStatus> subscriptions() {
return this.subscriptions;
}
public MqttSubAck subscriptions(FingerTrieSeq<MqttSubStatus> subscriptions) {
return new MqttSubAck(this.packetFlags, this.packetId, subscriptions);
}
public MqttSubAck subscriptions(MqttSubStatus... subscriptions) {
return new MqttSubAck(this.packetFlags, this.packetId, FingerTrieSeq.of(subscriptions));
}
public MqttSubAck subscription(MqttSubStatus subscription) {
return new MqttSubAck(this.packetFlags, this.packetId, this.subscriptions.appended(subscription));
}
@Override
int bodySize(MqttEncoder mqtt) {
return 2 + this.subscriptions.size();
}
@Override
public Encoder<?, MqttSubAck> mqttEncoder(MqttEncoder mqtt) {
return mqtt.subAckEncoder(this);
}
@Override
public Encoder<?, MqttSubAck> encodeMqtt(OutputBuffer<?> output, MqttEncoder mqtt) {
return mqtt.encodeSubAck(this, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttSubAck) {
final MqttSubAck that = (MqttSubAck) other;
return this.packetFlags == that.packetFlags && this.packetId == that.packetId
&& this.subscriptions.equals(that.subscriptions);
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttSubAck.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed,
this.packetFlags), this.packetId), this.subscriptions.hashCode()));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttSubAck").write('.').write("from").write('(')
.debug(this.packetId).write(')');
if (this.packetFlags != 0) {
output = output.write('.').write("packetFlags").write('(').debug(this.packetFlags).write(')');
}
for (int i = 0, n = subscriptions.size(); i < n; i += 1) {
output = output.write('.').write("subscription").write('(').debug(this.subscriptions.get(i)).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static MqttSubAck from(int packetFlags, int packetId,
FingerTrieSeq<MqttSubStatus> subscriptions) {
return new MqttSubAck(packetFlags, packetId, subscriptions);
}
public static MqttSubAck from(int packetId, FingerTrieSeq<MqttSubStatus> subscriptions) {
return new MqttSubAck(0, packetId, subscriptions);
}
public static MqttSubAck from(int packetId, MqttSubStatus... subscriptions) {
return new MqttSubAck(0, packetId, FingerTrieSeq.of(subscriptions));
}
public static MqttSubAck from(int packetId) {
return new MqttSubAck(0, packetId, FingerTrieSeq.<MqttSubStatus>empty());
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttSubAckDecoder.java | // 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.mqtt;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
import swim.collections.FingerTrieSeq;
final class MqttSubAckDecoder extends Decoder<MqttSubAck> {
final MqttDecoder mqtt;
final int packetFlags;
final int packetId;
final FingerTrieSeq<MqttSubStatus> subscriptions;
final int remaining;
final int step;
MqttSubAckDecoder(MqttDecoder mqtt, int packetFlags, int packetId,
FingerTrieSeq<MqttSubStatus> subscriptions, int remaining, int step) {
this.mqtt = mqtt;
this.packetFlags = packetFlags;
this.packetId = packetId;
this.subscriptions = subscriptions;
this.remaining = remaining;
this.step = step;
}
MqttSubAckDecoder(MqttDecoder mqtt) {
this(mqtt, 0, 0, FingerTrieSeq.<MqttSubStatus>empty(), 0, 1);
}
@Override
public Decoder<MqttSubAck> feed(InputBuffer input) {
return decode(input, this.mqtt, this.packetFlags, this.packetId,
this.subscriptions, this.remaining, this.step);
}
static Decoder<MqttSubAck> decode(InputBuffer input,
MqttDecoder mqtt, int packetFlags, int packetId,
FingerTrieSeq<MqttSubStatus> subscriptions,
int remaining, int step) {
if (step == 1 && input.isCont()) {
packetFlags = input.head() & 0x0f;
input = input.step();
step = 2;
}
while (step >= 2 && step <= 5 && input.isCont()) {
final int b = input.head();
input = input.step();
remaining |= (b & 0x7f) << (7 * (step - 2));
if ((b & 0x80) == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long"));
}
}
if (step == 6 && remaining > 0 && input.isCont()) {
packetId = input.head() << 8;
input = input.step();
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && input.isCont()) {
packetId |= input.head();
input = input.step();
remaining -= 1;
if (remaining > 0) {
step = 8;
} else {
step = 9;
}
}
while (step == 8 && remaining > 0 && input.isCont()) {
final int code = input.head();
input = input.step();
remaining -= 1;
subscriptions = subscriptions.appended(mqtt.subStatus(code));
if (remaining == 0) {
step = 9;
break;
}
}
if (step == 9 && remaining == 0) {
return done(mqtt.subAck(packetFlags, packetId, subscriptions));
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new MqttSubAckDecoder(mqtt, packetFlags, packetId, subscriptions, remaining, step);
}
static Decoder<MqttSubAck> decode(InputBuffer input, MqttDecoder mqtt) {
return decode(input, mqtt, 0, 0, FingerTrieSeq.<MqttSubStatus>empty(), 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttSubAckEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class MqttSubAckEncoder extends Encoder<Object, MqttSubAck> {
final MqttEncoder mqtt;
final MqttSubAck packet;
final int length;
final int remaining;
final int step;
MqttSubAckEncoder(MqttEncoder mqtt, MqttSubAck packet, int length, int remaining, int step) {
this.mqtt = mqtt;
this.packet = packet;
this.length = length;
this.remaining = remaining;
this.step = step;
}
MqttSubAckEncoder(MqttEncoder mqtt, MqttSubAck packet) {
this(mqtt, packet, 0, 0, 1);
}
@Override
public Encoder<Object, MqttSubAck> pull(OutputBuffer<?> output) {
return encode(output, this.mqtt, this.packet, this.length, this.remaining, this.step);
}
static Encoder<Object, MqttSubAck> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttSubAck packet, int length, int remaining, int step) {
if (step == 1 && output.isCont()) {
length = packet.bodySize(mqtt);
remaining = length;
output = output.write(packet.packetType() << 4 | packet.packetFlags & 0x0f);
step = 2;
}
while (step >= 2 && step <= 5 && output.isCont()) {
int b = length & 0x7f;
length = length >>> 7;
if (length > 0) {
b |= 0x80;
}
output = output.write(b);
if (length == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long: " + remaining));
}
}
if (step == 6 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId >>> 8);
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId);
remaining -= 1;
step = 8;
}
while (step >= 8 && step < 8 + packet.subscriptions.size() && output.isCont()) {
output = output.write(packet.subscriptions.get(step - 8).code);
remaining -= 1;
step += 1;
}
if (step == 8 + packet.subscriptions.size() && remaining == 0) {
return done(packet);
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttSubAckEncoder(mqtt, packet, length, remaining, step);
}
static Encoder<Object, MqttSubAck> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttSubAck packet) {
return encode(output, mqtt, packet, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttSubStatus.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.util.Murmur3;
public final class MqttSubStatus implements Debug {
public final int code;
MqttSubStatus(int code) {
this.code = code;
}
public boolean isSuccess() {
return this.code != 0x80;
}
public boolean isAtMostOnce() {
return this.code == 0x00;
}
public boolean isAtLeastOnce() {
return this.code == 0x01;
}
public boolean isExactlyOnce() {
return this.code == 0x02;
}
public boolean isFailure() {
return this.code == 0x80;
}
public MqttQoS maxQoS() {
return MqttQoS.from(this.code & MAX_QOS_MASK);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttSubStatus) {
final MqttSubStatus that = (MqttSubStatus) other;
return this.code == that.code;
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttSubStatus.class);
}
return Murmur3.mash(Murmur3.mix(hashSeed, this.code));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttSubStatus").write('.');
switch (code) {
case 0x00: output.write("AT_MOST_ONCE"); break;
case 0x01: output.write("AT_LEAST_ONCE"); break;
case 0x02: output.write("EXACTLY_ONCE"); break;
case 0x80: output.write("FAILURE"); break;
default: output.write("from").write('(').debug(this.code).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
static final int MAX_QOS_MASK = 0x3;
private static int hashSeed;
public static final MqttSubStatus AT_MOST_ONCE = new MqttSubStatus(0x00);
public static final MqttSubStatus AT_LEAST_ONCE = new MqttSubStatus(0x01);
public static final MqttSubStatus EXACTLY_ONCE = new MqttSubStatus(0x02);
public static final MqttSubStatus FAILURE = new MqttSubStatus(0x80);
public static MqttSubStatus from(int code) {
switch (code) {
case 0: return AT_MOST_ONCE;
case 1: return AT_LEAST_ONCE;
case 2: return EXACTLY_ONCE;
case 3: return FAILURE;
default: return new MqttSubStatus(code);
}
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttSubscribe.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.collections.FingerTrieSeq;
import swim.util.Murmur3;
public final class MqttSubscribe extends MqttPacket<Object> implements Debug {
final int packetFlags;
final int packetId;
final FingerTrieSeq<MqttSubscription> subscriptions;
MqttSubscribe(int packetFlags, int packetId, FingerTrieSeq<MqttSubscription> subscriptions) {
this.packetFlags = packetFlags;
this.packetId = packetId;
this.subscriptions = subscriptions;
}
@Override
public int packetType() {
return 8;
}
@Override
public int packetFlags() {
return this.packetFlags;
}
public MqttSubscribe packetFlags(int packetFlags) {
return new MqttSubscribe(packetFlags, this.packetId, this.subscriptions);
}
public int packetId() {
return this.packetId;
}
public MqttSubscribe packetId(int packetId) {
return new MqttSubscribe(this.packetFlags, packetId, this.subscriptions);
}
public FingerTrieSeq<MqttSubscription> subscriptions() {
return this.subscriptions;
}
public MqttSubscribe subscriptions(FingerTrieSeq<MqttSubscription> subscriptions) {
return new MqttSubscribe(this.packetFlags, this.packetId, subscriptions);
}
public MqttSubscribe subscriptions(MqttSubscription... subscriptions) {
return new MqttSubscribe(this.packetFlags, this.packetId, FingerTrieSeq.of(subscriptions));
}
public MqttSubscribe subscription(MqttSubscription subscription) {
return new MqttSubscribe(this.packetFlags, this.packetId, this.subscriptions.appended(subscription));
}
public MqttSubscribe subscription(String topicName, MqttQoS qos) {
return subscription(MqttSubscription.from(topicName, qos));
}
public MqttSubscribe subscription(String topicName) {
return subscription(MqttSubscription.from(topicName));
}
@Override
int bodySize(MqttEncoder mqtt) {
int size = 2;
for (int i = 0, n = this.subscriptions.size(); i < n; i += 1) {
size += this.subscriptions.get(i).mqttSize(mqtt);
}
return size;
}
@Override
public Encoder<?, MqttSubscribe> mqttEncoder(MqttEncoder mqtt) {
return mqtt.subscribeEncoder(this);
}
@Override
public Encoder<?, MqttSubscribe> encodeMqtt(OutputBuffer<?> output, MqttEncoder mqtt) {
return mqtt.encodeSubscribe(this, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttSubscribe) {
final MqttSubscribe that = (MqttSubscribe) other;
return this.packetFlags == that.packetFlags && this.packetId == that.packetId
&& this.subscriptions.equals(that.subscriptions);
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttSubscribe.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed,
this.packetFlags), this.packetId), this.subscriptions.hashCode()));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttSubscribe").write('.').write("from").write('(')
.debug(this.packetId).write(')');
if (this.packetFlags != 2) {
output = output.write('.').write("packetFlags").write('(').debug(this.packetFlags).write(')');
}
for (int i = 0, n = subscriptions.size(); i < n; i += 1) {
final MqttSubscription subscription = subscriptions.get(i);
output = output.write('.').write("subscription").write('(').debug(subscription.topicName);
if ((subscription.flags & MqttSubscription.QOS_MASK) != 0) {
output = output.write(", ").debug(subscription.qos());
}
output = output.write(')');
}
}
private static int hashSeed;
@Override
public String toString() {
return Format.debug(this);
}
public static MqttSubscribe from(int packetFlags, int packetId,
FingerTrieSeq<MqttSubscription> subscriptions) {
return new MqttSubscribe(packetFlags, packetId, subscriptions);
}
public static MqttSubscribe from(int packetId, FingerTrieSeq<MqttSubscription> subscriptions) {
return new MqttSubscribe(2, packetId, subscriptions);
}
public static MqttSubscribe from(int packetId, MqttSubscription... subscriptions) {
return new MqttSubscribe(2, packetId, FingerTrieSeq.of(subscriptions));
}
public static MqttSubscribe from(int packetId) {
return new MqttSubscribe(2, packetId, FingerTrieSeq.<MqttSubscription>empty());
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttSubscribeDecoder.java | // 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.mqtt;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
import swim.collections.FingerTrieSeq;
final class MqttSubscribeDecoder extends Decoder<MqttSubscribe> {
final MqttDecoder mqtt;
final int packetFlags;
final int packetId;
final FingerTrieSeq<MqttSubscription> subscriptions;
final Decoder<MqttSubscription> subscription;
final int remaining;
final int step;
MqttSubscribeDecoder(MqttDecoder mqtt, int packetFlags, int packetId,
FingerTrieSeq<MqttSubscription> subscriptions,
Decoder<MqttSubscription> subscription,
int remaining, int step) {
this.mqtt = mqtt;
this.packetFlags = packetFlags;
this.remaining = remaining;
this.packetId = packetId;
this.subscriptions = subscriptions;
this.subscription = subscription;
this.step = step;
}
MqttSubscribeDecoder(MqttDecoder mqtt) {
this(mqtt, 0, 0, FingerTrieSeq.<MqttSubscription>empty(), null, 0, 1);
}
@Override
public Decoder<MqttSubscribe> feed(InputBuffer input) {
return decode(input, this.mqtt, this.packetFlags, this.packetId,
this.subscriptions, this.subscription, this.remaining, this.step);
}
static Decoder<MqttSubscribe> decode(InputBuffer input, MqttDecoder mqtt,
int packetFlags, int packetId,
FingerTrieSeq<MqttSubscription> subscriptions,
Decoder<MqttSubscription> subscription,
int remaining, int step) {
if (step == 1 && input.isCont()) {
packetFlags = input.head() & 0x0f;
input = input.step();
step = 2;
}
while (step >= 2 && step <= 5 && input.isCont()) {
final int b = input.head();
input = input.step();
remaining |= (b & 0x7f) << (7 * (step - 2));
if ((b & 0x80) == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long"));
}
}
if (step == 6 && remaining > 0 && input.isCont()) {
packetId = input.head() << 8;
input = input.step();
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && input.isCont()) {
packetId |= input.head();
input = input.step();
remaining -= 1;
if (remaining > 0) {
step = 8;
} else {
step = 9;
}
}
while (step == 8 && remaining > 0 && input.isCont()) {
final int inputStart = input.index();
final int inputLimit = input.limit();
final int inputRemaining = inputLimit - inputStart;
if (remaining < inputRemaining) {
input = input.limit(inputStart + remaining);
}
final boolean inputPart = input.isPart();
input = input.isPart(remaining > inputRemaining);
if (subscription == null) {
subscription = mqtt.decodeSubscription(input);
} else {
subscription = subscription.feed(input);
}
input = input.limit(inputLimit).isPart(inputPart);
remaining -= input.index() - inputStart;
if (subscription.isDone()) {
subscriptions = subscriptions.appended(subscription.bind());
subscription = null;
if (remaining == 0) {
step = 9;
break;
}
} else if (subscription.isError()) {
return subscription.asError();
}
}
if (step == 9 && remaining == 0) {
return done(mqtt.subscribe(packetFlags, packetId, subscriptions));
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new MqttSubscribeDecoder(mqtt, packetFlags, packetId, subscriptions,
subscription, remaining, step);
}
static Decoder<MqttSubscribe> decode(InputBuffer input, MqttDecoder mqtt) {
return decode(input, mqtt, 0, 0, FingerTrieSeq.<MqttSubscription>empty(), null, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttSubscribeEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class MqttSubscribeEncoder extends Encoder<Object, MqttSubscribe> {
final MqttEncoder mqtt;
final MqttSubscribe packet;
final Encoder<?, ?> part;
final int length;
final int remaining;
final int step;
MqttSubscribeEncoder(MqttEncoder mqtt, MqttSubscribe packet, Encoder<?, ?> part,
int length, int remaining, int step) {
this.mqtt = mqtt;
this.packet = packet;
this.part = part;
this.length = length;
this.remaining = remaining;
this.step = step;
}
MqttSubscribeEncoder(MqttEncoder mqtt, MqttSubscribe packet) {
this(mqtt, packet, null, 0, 0, 1);
}
@Override
public Encoder<Object, MqttSubscribe> pull(OutputBuffer<?> output) {
return encode(output, this.mqtt, this.packet, this.part, this.length,
this.remaining, this.step);
}
static Encoder<Object, MqttSubscribe> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttSubscribe packet, Encoder<?, ?> part,
int length, int remaining, int step) {
if (step == 1 && output.isCont()) {
length = packet.bodySize(mqtt);
remaining = length;
output = output.write(packet.packetType() << 4 | packet.packetFlags & 0x0f);
step = 2;
}
while (step >= 2 && step <= 5 && output.isCont()) {
int b = length & 0x7F;
length = length >>> 7;
if (length > 0) {
b |= 0x80;
}
output = output.write(b);
if (length == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long: " + remaining));
}
}
if (step == 6 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId >>> 8);
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId);
remaining -= 1;
step = 8;
}
while (step >= 8 && step < 8 + packet.subscriptions.size() && output.isCont()) {
final int outputStart = output.index();
final int outputLimit = output.limit();
final int outputRemaining = outputLimit - outputStart;
if (remaining < outputRemaining) {
output = output.limit(outputStart + remaining);
}
final boolean outputPart = output.isPart();
output = output.isPart(remaining > outputRemaining);
if (part == null) {
part = packet.subscriptions.get(step - 8).encodeMqtt(output, mqtt);
} else {
part = part.pull(output);
}
output = output.limit(outputLimit).isPart(outputPart);
remaining -= output.index() - outputStart;
if (part.isDone()) {
part = null;
step += 1;
} else if (part.isError()) {
return part.asError();
}
}
if (step == 8 + packet.subscriptions.size() && remaining == 0) {
return done(packet);
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttSubscribeEncoder(mqtt, packet, part, length, remaining, step);
}
static Encoder<Object, MqttSubscribe> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttSubscribe packet) {
return encode(output, mqtt, packet, null, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttSubscription.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.util.Murmur3;
public final class MqttSubscription extends MqttPart implements Debug {
final String topicName;
final int flags;
MqttSubscription(String topicName, int flags) {
this.topicName = topicName;
this.flags = flags;
}
public String topicName() {
return this.topicName;
}
public MqttSubscription topicName(String topicName) {
return new MqttSubscription(topicName, this.flags);
}
public int flags() {
return this.flags;
}
public MqttQoS qos() {
return MqttQoS.from(this.flags & QOS_MASK);
}
public MqttSubscription qos(MqttQoS qos) {
final int flags = this.flags & ~QOS_MASK | qos.code;
return new MqttSubscription(this.topicName, flags);
}
public int mqttSize(MqttEncoder mqtt) {
return mqtt.sizeOfSubscription(this);
}
@Override
public Encoder<?, MqttSubscription> mqttEncoder(MqttEncoder mqtt) {
return mqtt.subscriptionEncoder(this);
}
@Override
public Encoder<?, MqttSubscription> encodeMqtt(OutputBuffer<?> output, MqttEncoder mqtt) {
return mqtt.encodeSubscription(this, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttSubscription) {
final MqttSubscription that = (MqttSubscription) other;
return this.topicName.equals(that.topicName) && this.flags == that.flags;
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttSubscription.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.topicName.hashCode()), this.flags));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttSubscription").write('.').write("from").write('(').debug(this.topicName);
if ((this.flags & QOS_MASK) != 0) {
output = output.write(", ").debug(qos());
}
output = output.write(')');
}
@Override
public String toString() {
return Format.debug(this);
}
static final int QOS_MASK = 0x03;
private static int hashSeed;
public static MqttSubscription from(String topicName, int flags) {
return new MqttSubscription(topicName, flags);
}
public static MqttSubscription from(String topicName, MqttQoS qos) {
return new MqttSubscription(topicName, qos.code);
}
public static MqttSubscription from(String topicName) {
return new MqttSubscription(topicName, 0);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttSubscriptionDecoder.java | // 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.mqtt;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class MqttSubscriptionDecoder extends Decoder<MqttSubscription> {
final MqttDecoder mqtt;
final Decoder<String> topicName;
final int step;
MqttSubscriptionDecoder(MqttDecoder mqtt, Decoder<String> topicName, int step) {
this.mqtt = mqtt;
this.topicName = topicName;
this.step = step;
}
MqttSubscriptionDecoder(MqttDecoder mqtt) {
this(mqtt, null, 1);
}
@Override
public Decoder<MqttSubscription> feed(InputBuffer input) {
return decode(input, this.mqtt, this.topicName, this.step);
}
static Decoder<MqttSubscription> decode(InputBuffer input, MqttDecoder mqtt,
Decoder<String> topicName, int step) {
if (step == 1) {
if (topicName == null) {
topicName = mqtt.decodeString(input);
} else {
topicName = topicName.feed(input);
}
if (topicName.isDone()) {
step = 2;
} else if (topicName.isError()) {
return topicName.asError();
}
}
if (step == 2 && input.isCont()) {
final int flags = input.head();
input = input.step();
return done(mqtt.subscription(topicName.bind(), flags));
}
if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new MqttSubscriptionDecoder(mqtt, topicName, step);
}
static Decoder<MqttSubscription> decode(InputBuffer input, MqttDecoder mqtt) {
return decode(input, mqtt, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttSubscriptionEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class MqttSubscriptionEncoder extends Encoder<MqttSubscription, MqttSubscription> {
final MqttEncoder mqtt;
final MqttSubscription subscription;
final Encoder<?, ?> part;
final int step;
MqttSubscriptionEncoder(MqttEncoder mqtt, MqttSubscription subscription,
Encoder<?, ?> part, int step) {
this.mqtt = mqtt;
this.subscription = subscription;
this.part = part;
this.step = step;
}
MqttSubscriptionEncoder(MqttEncoder mqtt, MqttSubscription subscription) {
this(mqtt, subscription, null, 1);
}
@Override
public Encoder<MqttSubscription, MqttSubscription> feed(MqttSubscription subscription) {
return new MqttSubscriptionEncoder(this.mqtt, subscription, null, 1);
}
@Override
public Encoder<MqttSubscription, MqttSubscription> pull(OutputBuffer<?> output) {
return encode(output, this.mqtt, this.subscription, this.part, this.step);
}
static int sizeOf(MqttEncoder mqtt, MqttSubscription subscription) {
return mqtt.sizeOfString(subscription.topicName) + 1;
}
static Encoder<MqttSubscription, MqttSubscription> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttSubscription subscription,
Encoder<?, ?> part, int step) {
if (step == 1) {
if (part == null) {
part = mqtt.encodeString(subscription.topicName, output);
} else {
part = part.pull(output);
}
if (part.isDone()) {
part = null;
step = 2;
} else if (part.isError()) {
return part.asError();
}
}
if (step == 2 && output.isCont()) {
output = output.write(subscription.flags);
return done(subscription);
}
if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttSubscriptionEncoder(mqtt, subscription, part, step);
}
static Encoder<MqttSubscription, MqttSubscription> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttSubscription subscription) {
return encode(output, mqtt, subscription, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttUnsubAck.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.util.Murmur3;
public final class MqttUnsubAck extends MqttPacket<Object> implements Debug {
final int packetFlags;
final int packetId;
MqttUnsubAck(int packetFlags, int packetId) {
this.packetFlags = packetFlags;
this.packetId = packetId;
}
@Override
public int packetType() {
return 11;
}
@Override
public int packetFlags() {
return this.packetFlags;
}
public MqttUnsubAck packetFlags(int packetFlags) {
return new MqttUnsubAck(packetFlags, this.packetId);
}
public int packetId() {
return this.packetId;
}
public MqttUnsubAck packetId(int packetId) {
return new MqttUnsubAck(this.packetFlags, packetId);
}
@Override
int bodySize(MqttEncoder mqtt) {
return 2;
}
@Override
public Encoder<?, MqttUnsubAck> mqttEncoder(MqttEncoder mqtt) {
return mqtt.unsubAckEncoder(this);
}
@Override
public Encoder<?, MqttUnsubAck> encodeMqtt(OutputBuffer<?> output, MqttEncoder mqtt) {
return mqtt.encodeUnsubAck(this, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttUnsubAck) {
final MqttUnsubAck that = (MqttUnsubAck) other;
return this.packetFlags == that.packetFlags && this.packetId == that.packetId;
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttUnsubAck.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.packetFlags), this.packetId));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttUnsubAck").write('.').write("from").write('(')
.debug(this.packetId).write(')');
if (this.packetFlags != 0) {
output = output.write('.').write("packetFlags").write('(').debug(this.packetFlags).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static MqttUnsubAck from(int packetFlags, int packetId) {
return new MqttUnsubAck(packetFlags, packetId);
}
public static MqttUnsubAck from(int packetId) {
return new MqttUnsubAck(0, packetId);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttUnsubAckDecoder.java | // 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.mqtt;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class MqttUnsubAckDecoder extends Decoder<MqttUnsubAck> {
final MqttDecoder mqtt;
final int packetFlags;
final int packetId;
final int remaining;
final int step;
MqttUnsubAckDecoder(MqttDecoder mqtt, int packetFlags, int packetId, int remaining, int step) {
this.mqtt = mqtt;
this.packetFlags = packetFlags;
this.packetId = packetId;
this.remaining = remaining;
this.step = step;
}
MqttUnsubAckDecoder(MqttDecoder mqtt) {
this(mqtt, 0, 0, 0, 1);
}
@Override
public Decoder<MqttUnsubAck> feed(InputBuffer input) {
return decode(input, this.mqtt, this.packetFlags, this.packetId, this.remaining, this.step);
}
static Decoder<MqttUnsubAck> decode(InputBuffer input, MqttDecoder mqtt, int packetFlags,
int packetId, int remaining, int step) {
if (step == 1 && input.isCont()) {
packetFlags = input.head() & 0x0f;
input = input.step();
step = 2;
}
while (step >= 2 && step <= 5 && input.isCont()) {
final int b = input.head();
input = input.step();
remaining |= (b & 0x7f) << (7 * (step - 2));
if ((b & 0x80) == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long"));
}
}
if (step == 6 && remaining > 0 && input.isCont()) {
packetId = input.head() << 8;
input = input.step();
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && input.isCont()) {
packetId |= input.head();
input = input.step();
remaining -= 1;
step = 8;
}
if (step == 8 && remaining == 0) {
return done(mqtt.unsubAck(packetFlags, packetId));
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new MqttUnsubAckDecoder(mqtt, packetFlags, packetId, remaining, step);
}
static Decoder<MqttUnsubAck> decode(InputBuffer input, MqttDecoder mqtt) {
return decode(input, mqtt, 0, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttUnsubAckEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class MqttUnsubAckEncoder extends Encoder<Object, MqttUnsubAck> {
final MqttEncoder mqtt;
final MqttUnsubAck packet;
final int length;
final int remaining;
final int step;
MqttUnsubAckEncoder(MqttEncoder mqtt, MqttUnsubAck packet, int length, int remaining, int step) {
this.mqtt = mqtt;
this.packet = packet;
this.length = length;
this.remaining = remaining;
this.step = step;
}
MqttUnsubAckEncoder(MqttEncoder mqtt, MqttUnsubAck packet) {
this(mqtt, packet, 0, 0, 1);
}
@Override
public Encoder<Object, MqttUnsubAck> pull(OutputBuffer<?> output) {
return encode(output, this.mqtt, this.packet, this.length, this.remaining, this.step);
}
static Encoder<Object, MqttUnsubAck> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttUnsubAck packet, int length, int remaining, int step) {
if (step == 1 && output.isCont()) {
length = packet.bodySize(mqtt);
remaining = length;
output = output.write(packet.packetType() << 4 | packet.packetFlags & 0x0f);
step = 2;
}
while (step >= 2 && step <= 5 && output.isCont()) {
int b = length & 0x7f;
length = length >>> 7;
if (length > 0) {
b |= 0x80;
}
output = output.write(b);
if (length == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long: " + remaining));
}
}
if (step == 6 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId >>> 8);
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId);
remaining -= 1;
step = 8;
}
if (step == 8 && remaining == 0) {
return done(packet);
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttUnsubAckEncoder(mqtt, packet, length, remaining, step);
}
static Encoder<Object, MqttUnsubAck> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttUnsubAck packet) {
return encode(output, mqtt, packet, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttUnsubscribe.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.collections.FingerTrieSeq;
import swim.util.Murmur3;
public final class MqttUnsubscribe extends MqttPacket<Object> implements Debug {
final int packetFlags;
final int packetId;
final FingerTrieSeq<String> topicNames;
MqttUnsubscribe(int packetFlags, int packetId, FingerTrieSeq<String> topicNames) {
this.packetFlags = packetFlags;
this.packetId = packetId;
this.topicNames = topicNames;
}
@Override
public int packetType() {
return 10;
}
@Override
public int packetFlags() {
return this.packetFlags;
}
public MqttUnsubscribe packetFlags(int packetFlags) {
return new MqttUnsubscribe(packetFlags, this.packetId, this.topicNames);
}
public int packetId() {
return this.packetId;
}
public MqttUnsubscribe packetId(int packetId) {
return new MqttUnsubscribe(this.packetFlags, packetId, this.topicNames);
}
public FingerTrieSeq<String> topicNames() {
return this.topicNames;
}
public MqttUnsubscribe topicNames(FingerTrieSeq<String> topicNames) {
return new MqttUnsubscribe(this.packetFlags, this.packetId, topicNames);
}
public MqttUnsubscribe topicNames(String... topicNames) {
return new MqttUnsubscribe(this.packetFlags, this.packetId, FingerTrieSeq.of(topicNames));
}
public MqttUnsubscribe topicName(String topicName) {
return new MqttUnsubscribe(this.packetFlags, this.packetId, this.topicNames.appended(topicName));
}
@Override
int bodySize(MqttEncoder mqtt) {
int size = 2;
for (int i = 0, n = this.topicNames.size(); i < n; i += 1) {
size += mqtt.sizeOfString(this.topicNames.get(i));
}
return size;
}
@Override
public Encoder<?, MqttUnsubscribe> mqttEncoder(MqttEncoder mqtt) {
return mqtt.unsubscribeEncoder(this);
}
@Override
public Encoder<?, MqttUnsubscribe> encodeMqtt(OutputBuffer<?> output, MqttEncoder mqtt) {
return mqtt.encodeUnsubscribe(this, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttUnsubscribe) {
final MqttUnsubscribe that = (MqttUnsubscribe) other;
return this.packetFlags == that.packetFlags && this.packetId == that.packetId
&& this.topicNames.equals(that.topicNames);
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttUnsubscribe.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed,
this.packetFlags), this.packetId), this.topicNames.hashCode()));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttUnsubscribe").write('.').write("from").write('(')
.debug(this.packetId).write(')');
if (this.packetFlags != 2) {
output = output.write('.').write("packetFlags").write('(').debug(this.packetFlags).write(')');
}
for (int i = 0, n = this.topicNames.size(); i < n; i += 1) {
output = output.write('.').write("topicName").write('(').debug(this.topicNames.get(i)).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static MqttUnsubscribe from(int packetFlags, int packetId, FingerTrieSeq<String> topicNames) {
return new MqttUnsubscribe(packetFlags, packetId, topicNames);
}
public static MqttUnsubscribe from(int packetId, FingerTrieSeq<String> topicNames) {
return new MqttUnsubscribe(2, packetId, topicNames);
}
public static MqttUnsubscribe from(int packetId, String... topicNames) {
return new MqttUnsubscribe(2, packetId, FingerTrieSeq.of(topicNames));
}
public static MqttUnsubscribe from(int packetId) {
return new MqttUnsubscribe(2, packetId, FingerTrieSeq.<String>empty());
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttUnsubscribeDecoder.java | // 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.mqtt;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
import swim.collections.FingerTrieSeq;
final class MqttUnsubscribeDecoder extends Decoder<MqttUnsubscribe> {
final MqttDecoder mqtt;
final int packetFlags;
final int packetId;
final FingerTrieSeq<String> topicNames;
final Decoder<String> topicName;
final int remaining;
final int step;
MqttUnsubscribeDecoder(MqttDecoder mqtt, int packetFlags, int packetId,
FingerTrieSeq<String> topicNames, Decoder<String> topicName,
int remaining, int step) {
this.mqtt = mqtt;
this.packetFlags = packetFlags;
this.packetId = packetId;
this.topicNames = topicNames;
this.topicName = topicName;
this.remaining = remaining;
this.step = step;
}
MqttUnsubscribeDecoder(MqttDecoder mqtt) {
this(mqtt, 0, 0, FingerTrieSeq.<String>empty(), null, 0, 1);
}
@Override
public Decoder<MqttUnsubscribe> feed(InputBuffer input) {
return decode(input, this.mqtt, this.packetFlags, this.packetId,
this.topicNames, this.topicName, this.remaining, this.step);
}
static Decoder<MqttUnsubscribe> decode(InputBuffer input, MqttDecoder mqtt, int packetFlags,
int packetId, FingerTrieSeq<String> topicNames,
Decoder<String> topicName, int remaining, int step) {
if (step == 1 && input.isCont()) {
packetFlags = input.head() & 0x0f;
input = input.step();
step = 2;
}
while (step >= 2 && step <= 5 && input.isCont()) {
final int b = input.head();
input = input.step();
remaining |= (b & 0x7f) << (7 * (step - 2));
if ((b & 0x80) == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long"));
}
}
if (step == 6 && remaining > 0 && input.isCont()) {
packetId = input.head() << 8;
input = input.step();
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && input.isCont()) {
packetId |= input.head();
input = input.step();
remaining -= 1;
if (remaining > 0) {
step = 8;
} else {
step = 9;
}
}
while (step == 8 && remaining > 0 && input.isCont()) {
final int inputStart = input.index();
final int inputLimit = input.limit();
final int inputRemaining = inputLimit - inputStart;
if (remaining < inputRemaining) {
input = input.limit(inputStart + remaining);
}
final boolean inputPart = input.isPart();
input = input.isPart(remaining > inputRemaining);
if (topicName == null) {
topicName = mqtt.decodeString(input);
} else {
topicName = topicName.feed(input);
}
input = input.limit(inputLimit);
remaining -= input.index() - inputStart;
if (topicName.isDone()) {
topicNames = topicNames.appended(topicName.bind());
topicName = null;
if (remaining == 0) {
step = 9;
break;
}
} else if (topicName.isError()) {
return topicName.asError();
}
}
if (step == 9 && remaining == 0) {
return done(mqtt.unsubscribe(packetFlags, packetId, topicNames));
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new MqttUnsubscribeDecoder(mqtt, packetFlags, packetId, topicNames,
topicName, remaining, step);
}
static Decoder<MqttUnsubscribe> decode(InputBuffer input, MqttDecoder mqtt) {
return decode(input, mqtt, 0, 0, FingerTrieSeq.<String>empty(), null, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttUnsubscribeEncoder.java | // 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.mqtt;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class MqttUnsubscribeEncoder extends Encoder<Object, MqttUnsubscribe> {
final MqttEncoder mqtt;
final MqttUnsubscribe packet;
final Encoder<?, ?> part;
final int length;
final int remaining;
final int step;
MqttUnsubscribeEncoder(MqttEncoder mqtt, MqttUnsubscribe packet, Encoder<?, ?> part,
int length, int remaining, int step) {
this.mqtt = mqtt;
this.packet = packet;
this.part = part;
this.length = length;
this.remaining = remaining;
this.step = step;
}
MqttUnsubscribeEncoder(MqttEncoder mqtt, MqttUnsubscribe packet) {
this(mqtt, packet, null, 0, 0, 1);
}
@Override
public Encoder<Object, MqttUnsubscribe> pull(OutputBuffer<?> output) {
return encode(output, this.mqtt, this.packet, this.part, this.length,
this.remaining, this.step);
}
static Encoder<Object, MqttUnsubscribe> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttUnsubscribe packet, Encoder<?, ?> part,
int length, int remaining, int step) {
if (step == 1 && output.isCont()) {
length = packet.bodySize(mqtt);
remaining = length;
output = output.write(packet.packetType() << 4 | packet.packetFlags & 0x0f);
step = 2;
}
while (step >= 2 && step <= 5 && output.isCont()) {
int b = length & 0x7f;
length = length >>> 7;
if (length > 0) {
b |= 0x80;
}
output = output.write(b);
if (length == 0) {
step = 6;
break;
} else if (step < 5) {
step += 1;
} else {
return error(new MqttException("packet length too long: " + remaining));
}
}
if (step == 6 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId >>> 8);
remaining -= 1;
step = 7;
}
if (step == 7 && remaining > 0 && output.isCont()) {
output = output.write(packet.packetId);
remaining -= 1;
step = 8;
}
while (step >= 8 && step < 8 + packet.topicNames.size() && output.isCont()) {
final int outputStart = output.index();
final int outputLimit = output.limit();
final int outputRemaining = outputLimit - outputStart;
if (remaining < outputRemaining) {
output = output.limit(outputStart + remaining);
}
final boolean outputPart = output.isPart();
output = output.isPart(remaining > outputRemaining);
if (part == null) {
final String topicName = packet.topicNames.get(step - 8);
part = mqtt.encodeString(topicName, output);
} else {
part = part.pull(output);
}
output = output.limit(outputLimit).isPart(outputPart);
remaining -= output.index() - outputStart;
if (part.isDone()) {
part = null;
step += 1;
} else if (part.isError()) {
return part.asError();
}
}
if (step == 8 + packet.topicNames.size() && remaining == 0) {
return done(packet);
}
if (remaining < 0) {
return error(new MqttException("packet length too short"));
} else if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new MqttUnsubscribeEncoder(mqtt, packet, part, length, remaining, step);
}
static Encoder<Object, MqttUnsubscribe> encode(OutputBuffer<?> output, MqttEncoder mqtt,
MqttUnsubscribe packet) {
return encode(output, mqtt, packet, null, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/MqttValue.java | // 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.mqtt;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.util.Murmur3;
public final class MqttValue<T> extends MqttEntity<T> implements Debug {
final T value;
MqttValue(T value) {
this.value = value;
}
@Override
public boolean isDefined() {
return true;
}
@Override
public T get() {
return this.value;
}
@Override
public int mqttSize() {
return -1;
}
@Override
public Encoder<?, ?> mqttEncoder(MqttEncoder mqtt) {
throw new UnsupportedOperationException();
}
@Override
public Encoder<?, ?> encodeMqtt(OutputBuffer<?> output, MqttEncoder mqtt) {
throw new UnsupportedOperationException();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof MqttValue<?>) {
final MqttValue<?> that = (MqttValue<?>) other;
return (this.value == null ? that.value == null : this.value.equals(that.value));
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(MqttValue.class);
}
return Murmur3.mash(Murmur3.mix(hashSeed, Murmur3.hash(this.value)));
}
@Override
public void debug(Output<?> output) {
output = output.write("MqttValue").write('.');
if (this.value != null) {
output = output.write("from").write('(').debug(this.value).write(')');
} else {
output = output.write("empty").write('(').write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
private static MqttValue<Object> empty;
@SuppressWarnings("unchecked")
public static <T> MqttValue<T> empty() {
if (empty == null) {
empty = new MqttValue<Object>(null);
}
return (MqttValue<T>) empty;
}
@SuppressWarnings("unchecked")
public static <T> MqttValue<T> from(T value) {
if (value == null) {
return empty();
} else {
return new MqttValue<T>(value);
}
}
}
|
0 | java-sources/ai/swim/swim-mqtt/3.10.0/swim | java-sources/ai/swim/swim-mqtt/3.10.0/swim/mqtt/package-info.java | // 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.
/**
* MQTT wire protocol model, decoders, and encoders.
*/
package swim.mqtt;
|
0 | java-sources/ai/swim/swim-observable | java-sources/ai/swim/swim-observable/3.10.0/module-info.java | // 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.
/**
* Observable collection interfaces.
*/
module swim.observable {
requires transitive swim.util;
requires transitive swim.collections;
requires transitive swim.spatial;
requires transitive swim.concurrent;
exports swim.observable;
exports swim.observable.function;
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/Observable.java | // 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.observable;
public interface Observable<O> {
Observable<O> observe(O observer);
Observable<O> unobserve(O observer);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/ObservableIterableMap.java | // 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.observable;
import swim.util.IterableMap;
public interface ObservableIterableMap<K, V> extends ObservableMap<K, V>, IterableMap<K, V> {
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/ObservableList.java | // 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.observable;
import java.util.List;
import swim.observable.function.DidClear;
import swim.observable.function.DidDrop;
import swim.observable.function.DidMoveIndex;
import swim.observable.function.DidRemoveIndex;
import swim.observable.function.DidTake;
import swim.observable.function.DidUpdateIndex;
import swim.observable.function.WillClear;
import swim.observable.function.WillDrop;
import swim.observable.function.WillMoveIndex;
import swim.observable.function.WillRemoveIndex;
import swim.observable.function.WillTake;
import swim.observable.function.WillUpdateIndex;
public interface ObservableList<V> extends Observable<Object>, List<V> {
void drop(int lower);
void take(int upper);
void move(int fromIndex, int toIndex);
@Override
ObservableList<V> observe(Object observer);
@Override
ObservableList<V> unobserve(Object observer);
ObservableList<V> willUpdate(WillUpdateIndex<V> willUpdate);
ObservableList<V> didUpdate(DidUpdateIndex<V> didUpdate);
ObservableList<V> willMove(WillMoveIndex<V> willMove);
ObservableList<V> didMove(DidMoveIndex<V> didMove);
ObservableList<V> willRemove(WillRemoveIndex willRemove);
ObservableList<V> didRemove(DidRemoveIndex<V> didRemove);
ObservableList<V> willDrop(WillDrop willDrop);
ObservableList<V> didDrop(DidDrop didDrop);
ObservableList<V> willTake(WillTake willTake);
ObservableList<V> didTake(DidTake didTake);
ObservableList<V> willClear(WillClear willClear);
ObservableList<V> didClear(DidClear didClear);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/ObservableMap.java | // 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.observable;
import java.util.Map;
import swim.observable.function.DidClear;
import swim.observable.function.DidRemoveKey;
import swim.observable.function.DidUpdateKey;
import swim.observable.function.WillClear;
import swim.observable.function.WillRemoveKey;
import swim.observable.function.WillUpdateKey;
public interface ObservableMap<K, V> extends Observable<Object>, Map<K, V> {
@Override
ObservableMap<K, V> observe(Object observer);
@Override
ObservableMap<K, V> unobserve(Object observer);
ObservableMap<K, V> willUpdate(WillUpdateKey<K, V> willUpdate);
ObservableMap<K, V> didUpdate(DidUpdateKey<K, V> didUpdate);
ObservableMap<K, V> willRemove(WillRemoveKey<K> willRemove);
ObservableMap<K, V> didRemove(DidRemoveKey<K, V> didRemove);
ObservableMap<K, V> willClear(WillClear willClear);
ObservableMap<K, V> didClear(DidClear didClear);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/ObservableOrderedMap.java | // 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.observable;
import swim.util.OrderedMap;
public interface ObservableOrderedMap<K, V> extends ObservableIterableMap<K, V>, ObservableSortedMap<K, V>, OrderedMap<K, V> {
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/ObservableSortedMap.java | // 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.observable;
import java.util.SortedMap;
import swim.observable.function.DidDrop;
import swim.observable.function.DidTake;
import swim.observable.function.WillDrop;
import swim.observable.function.WillTake;
public interface ObservableSortedMap<K, V> extends ObservableMap<K, V>, SortedMap<K, V> {
void drop(int lower);
void take(int upper);
@Override
ObservableSortedMap<K, V> observe(Object observer);
@Override
ObservableSortedMap<K, V> unobserve(Object observer);
ObservableSortedMap<K, V> willDrop(WillDrop willDrop);
ObservableSortedMap<K, V> didDrop(DidDrop didDrop);
ObservableSortedMap<K, V> willTake(WillTake willTake);
ObservableSortedMap<K, V> didTake(DidTake didTake);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/ObservableSpatialMap.java | // 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.observable;
import swim.observable.function.DidClear;
import swim.observable.function.DidMoveShape;
import swim.observable.function.DidRemoveShape;
import swim.observable.function.DidUpdateShape;
import swim.observable.function.WillClear;
import swim.observable.function.WillMoveShape;
import swim.observable.function.WillRemoveShape;
import swim.observable.function.WillUpdateShape;
import swim.spatial.SpatialMap;
public interface ObservableSpatialMap<K, S, V> extends Observable<Object>, SpatialMap<K, S, V> {
@Override
ObservableSpatialMap<K, S, V> observe(Object observer);
@Override
ObservableSpatialMap<K, S, V> unobserve(Object observer);
ObservableSpatialMap<K, S, V> willUpdate(WillUpdateShape<K, S, V> willUpdate);
ObservableSpatialMap<K, S, V> didUpdate(DidUpdateShape<K, S, V> didUpdate);
ObservableSpatialMap<K, S, V> willMove(WillMoveShape<K, S, V> willMove);
ObservableSpatialMap<K, S, V> didMove(DidMoveShape<K, S, V> didMove);
ObservableSpatialMap<K, S, V> willRemove(WillRemoveShape<K, S> willRemove);
ObservableSpatialMap<K, S, V> didRemove(DidRemoveShape<K, S, V> didRemove);
ObservableSpatialMap<K, S, V> willClear(WillClear willClear);
ObservableSpatialMap<K, S, V> didClear(DidClear didClear);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/ObservableValue.java | // 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.observable;
import swim.observable.function.DidSet;
import swim.observable.function.WillSet;
public interface ObservableValue<V> extends Observable<Object> {
V get();
V set(V newValue);
@Override
ObservableValue<V> observe(Object observer);
@Override
ObservableValue<V> unobserve(Object observer);
ObservableValue<V> willSet(WillSet<V> willSet);
ObservableValue<V> didSet(DidSet<V> didSet);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/package-info.java | // 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.
/**
* Observable collection interfaces.
*/
package swim.observable;
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidClear.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidClear extends Preemptive {
void didClear();
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidDrop.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidDrop extends Preemptive {
void didDrop(int lower);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidMoveIndex.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidMoveIndex<V> extends Preemptive {
void didMove(int fromIndex, int toIndex, V value);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidMoveShape.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidMoveShape<K, S, V> extends Preemptive {
void didMove(K key, S newShape, V newValue, S oldShape, V oldValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidRemoveIndex.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidRemoveIndex<V> extends Preemptive {
void didRemove(int index, V oldValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidRemoveKey.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidRemoveKey<K, V> extends Preemptive {
void didRemove(K key, V oldValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidRemoveShape.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidRemoveShape<K, S, V> extends Preemptive {
void didRemove(K key, S shape, V oldValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidSet.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidSet<V> extends Preemptive {
void didSet(V newValue, V oldValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidTake.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidTake extends Preemptive {
void didTake(int upper);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidUpdateIndex.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidUpdateIndex<V> extends Preemptive {
void didUpdate(int index, V newValue, V oldValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidUpdateKey.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidUpdateKey<K, V> extends Preemptive {
void didUpdate(K key, V newValue, V oldValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/DidUpdateShape.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface DidUpdateShape<K, S, V> extends Preemptive {
void didUpdate(K key, S shape, V newValue, V oldValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillClear.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillClear extends Preemptive {
void willClear();
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillDrop.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillDrop extends Preemptive {
void willDrop(int lower);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillMoveIndex.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillMoveIndex<V> extends Preemptive {
void willMove(int fromIndex, int toIndex, V value);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillMoveShape.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillMoveShape<K, S, V> extends Preemptive {
V willMove(K key, S newShape, V newValue, S oldShape);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillRemoveIndex.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillRemoveIndex extends Preemptive {
void willRemove(int index);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillRemoveKey.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillRemoveKey<K> extends Preemptive {
void willRemove(K key);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillRemoveShape.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillRemoveShape<K, S> extends Preemptive {
void willRemove(K key, S shape);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillSet.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillSet<V> extends Preemptive {
V willSet(V newValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillTake.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillTake extends Preemptive {
void willTake(int upper);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillUpdateIndex.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillUpdateIndex<V> extends Preemptive {
V willUpdate(int index, V newValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillUpdateKey.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillUpdateKey<K, V> extends Preemptive {
V willUpdate(K key, V newValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/WillUpdateShape.java | // 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.observable.function;
import swim.concurrent.Preemptive;
@FunctionalInterface
public interface WillUpdateShape<K, S, V> extends Preemptive {
V willUpdate(K key, S shape, V newValue);
}
|
0 | java-sources/ai/swim/swim-observable/3.10.0/swim/observable | java-sources/ai/swim/swim-observable/3.10.0/swim/observable/function/package-info.java | // 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.
/**
* Observable collection callback function interfaces.
*/
package swim.observable.function;
|
0 | java-sources/ai/swim/swim-protobuf | java-sources/ai/swim/swim-protobuf/3.10.0/module-info.java | // 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.
/**
* Protocol Buffers (protobuf) codec.
*/
module swim.protobuf {
requires swim.util;
requires transitive swim.codec;
requires transitive swim.structure;
exports swim.protobuf;
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/FieldDecoder.java | // 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.protobuf;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class FieldDecoder<I, V> extends Decoder<I> {
final ProtobufDecoder<I, V> protobuf;
final Decoder<V> payloadDecoder;
final Decoder<V> valueDecoder;
final long tag;
final int tagShift;
final int step;
FieldDecoder(ProtobufDecoder<I, V> protobuf, Decoder<V> payloadDecoder,
Decoder<V> valueDecoder, long tag, int tagShift, int step) {
this.protobuf = protobuf;
this.payloadDecoder = payloadDecoder;
this.tag = tag;
this.tagShift = tagShift;
this.valueDecoder = valueDecoder;
this.step = step;
}
@Override
public Decoder<I> feed(InputBuffer input) {
return decode(input, this.protobuf, this.payloadDecoder, this.valueDecoder,
this.tag, this.tagShift, this.step);
}
static <I, V> Decoder<I> decode(InputBuffer input, ProtobufDecoder<I, V> protobuf,
Decoder<V> payloadDecoder, Decoder<V> valueDecoder,
long tag, int tagShift, int step) {
if (step == 1) {
while (input.isCont()) {
final int b = input.head();
if (tagShift < 64) {
input = input.step();
tag |= (long) (b & 0x7f) << tagShift;
} else {
return error(new DecoderException("varint overflow"));
}
if ((b & 0x80) == 0) {
step = 2;
break;
}
tagShift += 7;
}
}
if (step == 2) {
if (valueDecoder == null) {
final WireType wireType = WireType.apply((int) tag & 0x7);
valueDecoder = protobuf.decodeValue(wireType, payloadDecoder, input);
} else {
valueDecoder = valueDecoder.feed(input);
}
if (valueDecoder.isDone()) {
return done(protobuf.field(tag >>> 3, valueDecoder.bind()));
} else if (valueDecoder.isError()) {
return valueDecoder.asError();
}
}
if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new FieldDecoder<I, V>(protobuf, payloadDecoder, valueDecoder, tag, tagShift, step);
}
static <I, V> Decoder<I> decode(InputBuffer input, ProtobufDecoder<I, V> protobuf,
Decoder<V> payloadDecoder) {
return decode(input, protobuf, payloadDecoder, null, 0L, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/Fixed32Decoder.java | // 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.protobuf;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class Fixed32Decoder<V> extends Decoder<V> {
final ProtobufDecoder<?, V> protobuf;
final int value;
final int shift;
Fixed32Decoder(ProtobufDecoder<?, V> protobuf, int value, int shift) {
this.protobuf = protobuf;
this.value = value;
this.shift = shift;
}
@Override
public Decoder<V> feed(InputBuffer input) {
return decode(input, this.protobuf, this.value, this.shift);
}
static <V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<?, V> protobuf,
int value, int shift) {
while (input.isCont()) {
value |= input.head() << shift;
input = input.step();
if (shift != 0) {
shift -= 8;
} else {
return done(protobuf.fixed(value));
}
}
if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new Fixed32Decoder<V>(protobuf, value, shift);
}
static <V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<?, V> protobuf) {
return decode(input, protobuf, 0, 24);
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/Fixed64Decoder.java | // 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.protobuf;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class Fixed64Decoder<V> extends Decoder<V> {
final ProtobufDecoder<?, V> protobuf;
final long value;
final int shift;
Fixed64Decoder(ProtobufDecoder<?, V> protobuf, long value, int shift) {
this.protobuf = protobuf;
this.value = value;
this.shift = shift;
}
@Override
public Decoder<V> feed(InputBuffer input) {
return decode(input, this.protobuf, this.value, this.shift);
}
static <V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<?, V> protobuf,
long value, int shift) {
while (input.isCont()) {
value |= (long) input.head() << shift;
input = input.step();
if (shift != 0) {
shift -= 8;
} else {
return done(protobuf.fixed(value));
}
}
if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new Fixed64Decoder<V>(protobuf, value, shift);
}
static <V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<?, V> protobuf) {
return decode(input, protobuf, 0L, 56);
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/MessageDecoder.java | // 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.protobuf;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
import swim.util.Builder;
final class MessageDecoder<I, V> extends Decoder<V> {
final ProtobufDecoder<I, V> protobuf;
final Decoder<V> payloadDecoder;
final Decoder<I> fieldDecoder;
final Builder<I, V> builder;
MessageDecoder(ProtobufDecoder<I, V> protobuf, Decoder<V> payloadDecoder,
Decoder<I> fieldDecoder, Builder<I, V> builder) {
this.protobuf = protobuf;
this.payloadDecoder = payloadDecoder;
this.fieldDecoder = fieldDecoder;
this.builder = builder;
}
@Override
public Decoder<V> feed(InputBuffer input) {
return decode(input, this.protobuf, this.payloadDecoder, this.fieldDecoder, this.builder);
}
static <I, V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<I, V> protobuf,
Decoder<V> payloadDecoder, Decoder<I> fieldDecoder,
Builder<I, V> builder) {
while (input.isCont()) {
if (fieldDecoder == null) {
fieldDecoder = protobuf.decodeField(payloadDecoder, input);
} else {
fieldDecoder = fieldDecoder.feed(input);
}
if (fieldDecoder.isDone()) {
if (builder == null) {
builder = protobuf.messageBuilder();
}
builder.add(fieldDecoder.bind());
fieldDecoder = null;
} else if (fieldDecoder.isError()) {
return fieldDecoder.asError();
}
}
if (input.isDone()) {
if (fieldDecoder == null) {
if (builder == null) {
builder = protobuf.messageBuilder();
}
return done(builder.bind());
} else {
return error(new DecoderException("incomplete"));
}
} else if (input.isError()) {
return error(input.trap());
}
return new MessageDecoder<I, V>(protobuf, payloadDecoder, fieldDecoder, builder);
}
static <I, V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<I, V> protobuf,
Decoder<V> payloadDecoder) {
return decode(input, protobuf, payloadDecoder, null, null);
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/PackedDecoder.java | // 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.protobuf;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
import swim.util.Builder;
final class PackedDecoder<I, V> extends Decoder<V> {
final ProtobufDecoder<I, V> protobuf;
final WireType wireType;
final Decoder<V> valueDecoder;
final Builder<I, V> builder;
PackedDecoder(ProtobufDecoder<I, V> protobuf, WireType wireType,
Decoder<V> valueDecoder, Builder<I, V> builder) {
this.protobuf = protobuf;
this.wireType = wireType;
this.valueDecoder = valueDecoder;
this.builder = builder;
}
@Override
public Decoder<V> feed(InputBuffer input) {
return decode(input, this.protobuf, this.wireType, this.valueDecoder, this.builder);
}
static <I, V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<I, V> protobuf,
WireType wireType, Decoder<V> valueDecoder, Builder<I, V> builder) {
while (input.isCont()) {
if (valueDecoder == null) {
valueDecoder = protobuf.decodeValue(wireType, input);
} else {
valueDecoder = valueDecoder.feed(input);
}
if (valueDecoder.isDone()) {
if (builder == null) {
builder = protobuf.messageBuilder();
}
builder.add(protobuf.item(valueDecoder.bind()));
valueDecoder = null;
} else if (valueDecoder.isError()) {
return valueDecoder.asError();
}
}
if (input.isDone()) {
if (valueDecoder == null) {
if (builder == null) {
builder = protobuf.messageBuilder();
}
return done(builder.bind());
} else {
return error(new DecoderException("incomplete"));
}
}
return new PackedDecoder<I, V>(protobuf, wireType, valueDecoder, builder);
}
static <I, V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<I, V> protobuf,
WireType wireType) {
return decode(input, protobuf, wireType, null, null);
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/PayloadDecoder.java | // 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.protobuf;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class PayloadDecoder<V> extends Decoder<V> {
final ProtobufDecoder<?, V> protobuf;
final Decoder<V> messageDecoder;
final Decoder<V> textDecoder;
final Decoder<V> dataDecoder;
final int consumed;
PayloadDecoder(ProtobufDecoder<?, V> protobuf, Decoder<V> messageDecoder,
Decoder<V> textDecoder, Decoder<V> dataDecoder, int consumed) {
this.protobuf = protobuf;
this.messageDecoder = messageDecoder;
this.textDecoder = textDecoder;
this.dataDecoder = dataDecoder;
this.consumed = consumed;
}
PayloadDecoder(ProtobufDecoder<?, V> protobuf) {
this(protobuf, null, null, null, 0);
}
@Override
public Decoder<V> feed(InputBuffer input) {
return decode(input, this.protobuf, this.messageDecoder, this.textDecoder,
this.dataDecoder, this.consumed);
}
static <V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<?, V> protobuf,
Decoder<V> messageDecoder, Decoder<V> textDecoder,
Decoder<V> dataDecoder, int consumed) {
final int inputStart = input.index();
final int inputLimit = input.limit();
final int inputRemaining = inputLimit - inputStart;
int inputConsumed = 0;
if (messageDecoder == null) {
messageDecoder = protobuf.decodeMessage(input);
} else if (messageDecoder.isCont()) {
messageDecoder = messageDecoder.feed(input);
}
if (input.isDone() && messageDecoder.isDone()) {
return messageDecoder;
}
inputConsumed = Math.max(inputConsumed, input.index() - inputStart);
if (consumed + inputConsumed < DETECTION_WINDOW) {
input = input.index(inputStart).limit(inputLimit);
if (textDecoder == null) {
textDecoder = protobuf.decodeText(input);
} else if (textDecoder.isCont()) {
textDecoder = textDecoder.feed(input);
}
if (input.isDone() && textDecoder.isDone()) {
return textDecoder;
}
inputConsumed = Math.max(inputConsumed, input.index() - inputStart);
} else {
textDecoder = DETECTION_FAILED.asError();
}
if (consumed + inputConsumed < DETECTION_WINDOW) {
input = input.index(inputStart).limit(inputLimit);
if (dataDecoder == null) {
dataDecoder = protobuf.decodeData(input);
} else if (dataDecoder.isCont()) {
dataDecoder = dataDecoder.feed(input);
}
if (input.isDone() && dataDecoder.isDone()) {
return dataDecoder;
}
inputConsumed = Math.max(inputConsumed, input.index() - inputStart);
} else {
dataDecoder = DETECTION_FAILED.asError();
}
if (textDecoder.isError() && dataDecoder.isError()) {
return messageDecoder;
} else if (messageDecoder.isError() && dataDecoder.isError()) {
return textDecoder;
} else if (messageDecoder.isError() && textDecoder.isError()) {
return dataDecoder;
}
if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
consumed += inputConsumed;
return new PayloadDecoder<V>(protobuf, messageDecoder, textDecoder, dataDecoder, consumed);
}
static <V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<?, V> protobuf) {
return decode(input, protobuf, null, null, null, 0);
}
static final int DETECTION_WINDOW;
static final Decoder<Object> DETECTION_FAILED;
static {
int detectionWindow;
try {
detectionWindow = Integer.parseInt(System.getProperty("swim.protobuf.payload.detection.window"));
} catch (NumberFormatException e) {
detectionWindow = 128;
}
DETECTION_WINDOW = detectionWindow;
DETECTION_FAILED = error(new DecoderException("detection failed"));
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/Protobuf.java | // 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.protobuf;
import swim.structure.Item;
import swim.structure.Value;
/**
* Factory for constructing Protocol Buffer decoders and encoders.
*/
public final class Protobuf {
private Protobuf() {
// stub
}
private static ProtobufDecoder<Item, Value> structureDecoder;
//private static ProtobufEncoder<Item, Value> structureEncoder;
public static ProtobufDecoder<Item, Value> structureDecoder() {
if (structureDecoder == null) {
structureDecoder = new ProtobufStructureDecoder();
}
return structureDecoder;
}
//public static ProtobufEncoder<Item, Value> structureEncoder() {
// if (structureEncoder == null) {
// structureEncoder = new ProtobufStructureEncoder();
// }
// return structureEncoder;
//}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/ProtobufDecoder.java | // 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.protobuf;
import swim.codec.Binary;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
import swim.codec.Output;
import swim.codec.Utf8;
import swim.codec.UtfErrorMode;
import swim.util.Builder;
public abstract class ProtobufDecoder<I, V> {
public abstract I item(V value);
public abstract V value(I item);
public abstract I field(long key, V value);
public abstract V uint(long value);
public abstract V sint(long value);
public abstract V fixed(int value);
public abstract V fixed(long value);
public abstract Builder<I, V> messageBuilder();
public abstract Output<V> dataOutput();
public abstract Output<V> textOutput();
public Decoder<V> decodeValue(WireType wireType, Decoder<V> payloadDecoder, InputBuffer input) {
switch (wireType.code) {
case 0: return decodeVarint(input);
case 1: return decodeFixed64(input);
case 2: return decodeSized(payloadDecoder, input);
case 5: return decodeFixed32(input);
default: return Decoder.error(new DecoderException("unsupported wire type: " + wireType.name()));
}
}
public Decoder<V> decodeValue(WireType wireType, InputBuffer input) {
switch (wireType.code) {
case 0: return decodeVarint(input);
case 1: return decodeFixed64(input);
case 2: return decodeSized(payloadDecoder(), input);
case 5: return decodeFixed32(input);
default: return Decoder.error(new DecoderException("unsupported wire type: " + wireType.name()));
}
}
public Decoder<V> decodeVarint(InputBuffer input) {
return VarintDecoder.decode(input, this);
}
public Decoder<V> decodeSignedVarint(InputBuffer input) {
return VarintDecoder.decodeSigned(input, this);
}
public Decoder<V> decodeFixed64(InputBuffer input) {
return Fixed64Decoder.decode(input, this);
}
public Decoder<V> decodeSized(Decoder<V> payloadDecoder, InputBuffer input) {
return SizedDecoder.decode(input, payloadDecoder);
}
public Decoder<V> decodeSized(InputBuffer input) {
return decodeSized(payloadDecoder(), input);
}
public Decoder<V> decodeFixed32(InputBuffer input) {
return Fixed32Decoder.decode(input, this);
}
public Decoder<I> decodeField(Decoder<V> payloadDecoder, InputBuffer input) {
return FieldDecoder.decode(input, this, payloadDecoder);
}
public Decoder<V> decodeMessage(Decoder<V> payloadDecoder, InputBuffer input) {
return MessageDecoder.decode(input, this, payloadDecoder);
}
public Decoder<V> decodeMessage(InputBuffer input) {
return decodeMessage(payloadDecoder(), input);
}
public Decoder<V> decodePacked(WireType wireType, InputBuffer input) {
return PackedDecoder.decode(input, this, wireType);
}
public Decoder<V> decodeText(InputBuffer input) {
return Utf8.decodeOutput(textOutput(), input, UtfErrorMode.fatalNonZero());
}
public Decoder<V> decodeData(InputBuffer input) {
return Binary.parseOutput(dataOutput(), input);
}
public Decoder<V> decodePayload(InputBuffer input) {
return PayloadDecoder.decode(input, this);
}
public Decoder<V> payloadDecoder() {
return new PayloadDecoder<V>(this);
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/ProtobufStructureDecoder.java | // 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.protobuf;
import swim.codec.Output;
import swim.structure.Data;
import swim.structure.Item;
import swim.structure.Num;
import swim.structure.Record;
import swim.structure.Slot;
import swim.structure.Text;
import swim.structure.Value;
import swim.util.Builder;
public class ProtobufStructureDecoder extends ProtobufDecoder<Item, Value> {
@Override
public Item item(Value value) {
return value;
}
@Override
public Value value(Item item) {
return item.toValue();
}
@Override
public Item field(long key, Value value) {
return Slot.of((int) key == key ? Num.from((int) key) : Num.from(key), value);
}
@Override
public Value uint(long value) {
if ((int) value == value) {
return Num.from((int) value);
} else {
return Num.from(value);
}
}
@Override
public Value sint(long value) {
if ((int) value == value) {
return Num.from((int) value);
} else {
return Num.from(value);
}
}
@Override
public Value fixed(int value) {
return Num.from(Float.intBitsToFloat(value));
}
@Override
public Value fixed(long value) {
return Num.from(Double.longBitsToDouble(value));
}
@SuppressWarnings("unchecked")
@Override
public Builder<Item, Value> messageBuilder() {
return (Builder<Item, Value>) (Builder<?, ?>) Record.create();
}
@SuppressWarnings("unchecked")
@Override
public Output<Value> dataOutput() {
return (Output<Value>) (Output<?>) Data.output();
}
@SuppressWarnings("unchecked")
@Override
public Output<Value> textOutput() {
return (Output<Value>) (Output<?>) Text.output();
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/SizedDecoder.java | // 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.protobuf;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class SizedDecoder<V> extends Decoder<V> {
final Decoder<V> payloadDecoder;
final long length;
final int lengthShift;
final int step;
SizedDecoder(Decoder<V> payloadDecoder, long length, int lengthShift, int step) {
this.payloadDecoder = payloadDecoder;
this.length = length;
this.lengthShift = lengthShift;
this.step = step;
}
@Override
public Decoder<V> feed(InputBuffer input) {
return decode(input, this.payloadDecoder, this.length, this.lengthShift, this.step);
}
static <V> Decoder<V> decode(InputBuffer input, Decoder<V> payloadDecoder,
long length, int lengthShift, int step) {
if (step == 1) {
while (input.isCont()) {
final int b = input.head();
if (lengthShift < 64) {
input = input.step();
length |= (long) (b & 0x7f) << lengthShift;
} else {
return error(new DecoderException("varint overflow"));
}
if ((b & 0x80) == 0) {
step = 2;
break;
}
lengthShift += 7;
}
}
if (step == 2) {
final int inputStart = input.index();
final int inputLimit = input.limit();
final int inputRemaining = inputLimit - inputStart;
final boolean inputPart = input.isPart();
if (length < inputRemaining) {
input.limit(inputStart + (int) length);
}
if (length <= inputRemaining) {
input = input.isPart(false);
}
payloadDecoder = payloadDecoder.feed(input);
input = input.limit(inputLimit).isPart(inputPart);
length -= input.index() - inputStart;
if (payloadDecoder.isDone()) {
if (length == 0L) {
return payloadDecoder;
} else {
return error(new DecoderException("unconsumed input"));
}
} else if (payloadDecoder.isError()) {
return payloadDecoder.asError();
}
}
if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new SizedDecoder<V>(payloadDecoder, length, lengthShift, step);
}
static <V> Decoder<V> decode(InputBuffer input, Decoder<V> payloadDecoder) {
return decode(input, payloadDecoder, 0L, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/VarintDecoder.java | // 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.protobuf;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
final class VarintDecoder<V> extends Decoder<V> {
final ProtobufDecoder<?, V> protobuf;
final boolean signed;
final long value;
final int shift;
VarintDecoder(ProtobufDecoder<?, V> protobuf, boolean signed, long value, int shift) {
this.protobuf = protobuf;
this.value = value;
this.shift = shift;
this.signed = signed;
}
@Override
public Decoder<V> feed(InputBuffer input) {
return decode(input, this.protobuf, this.signed, this.value, this.shift);
}
static <V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<?, V> protobuf,
boolean signed, long value, int shift) {
while (input.isCont()) {
final int b = input.head();
if (shift < 64) {
input = input.step();
value |= (long) (b & 0x7f) << shift;
} else {
return error(new DecoderException("varint overflow"));
}
if ((b & 0x80) == 0) {
if (signed) {
value = (value >>> 1) ^ (value << 63 >> 63);
return done(protobuf.sint(value));
} else {
return done(protobuf.uint(value));
}
}
shift += 7;
}
if (input.isDone()) {
return error(new DecoderException("incomplete"));
} else if (input.isError()) {
return error(input.trap());
}
return new VarintDecoder<V>(protobuf, signed, value, shift);
}
static <V> Decoder<V> decode(InputBuffer input, ProtobufDecoder<?, V> protobuf) {
return decode(input, protobuf, false, 0L, 0);
}
static <V> Decoder<V> decodeSigned(InputBuffer input, ProtobufDecoder<?, V> protobuf) {
return decode(input, protobuf, true, 0L, 0);
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/VarintEncoder.java | // 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.protobuf;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class VarintEncoder extends Encoder<Number, Object> {
final long value;
VarintEncoder(long value) {
this.value = value;
}
VarintEncoder() {
this(0L);
}
@Override
public Encoder<Number, Object> feed(Number input) {
return new VarintEncoder(input.longValue());
}
@Override
public Encoder<Number, Object> pull(OutputBuffer<?> output) {
return encode(output, this.value);
}
static int sizeOf(long value) {
return (63 - Long.numberOfLeadingZeros(value)) / 7 + 1;
}
static Encoder<Number, Object> encode(OutputBuffer<?> output, long value) {
while (output.isCont()) {
if ((value >>> 7) == 0L) {
output = output.write((int) value & 0x7f);
return done();
} else {
output = output.write(0x80 | ((int) value & 0x7f));
value >>>= 7;
}
}
if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new VarintEncoder(value);
}
static Encoder<Number, Object> encodeSigned(OutputBuffer<?> output, long value) {
value = (value << 1) ^ (value >> 63);
return encode(output, value);
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/WireType.java | // 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.protobuf;
public enum WireType {
VARINT(0),
FIXED64(1),
SIZED(2),
START_GROUP(3),
END_GROUP(4),
FIXED32(5),
RESERVED6(6),
RESERVED7(7);
public final int code;
WireType(int code) {
this.code = code;
}
public boolean isVarint() {
return code == 0;
}
public boolean isFixed64() {
return code == 1;
}
public boolean isSized() {
return code == 2;
}
public boolean isStartGroup() {
return code == 3;
}
public boolean isEndGroup() {
return code == 4;
}
public boolean isFixed32() {
return code == 5;
}
public boolean isReserved() {
return code == 6 || code == 7;
}
@Override
public String toString() {
return new StringBuilder("WireType").append('.').append(super.toString()).toString();
}
public static WireType apply(int code) {
switch (code) {
case 0: return VARINT;
case 1: return FIXED64;
case 2: return SIZED;
case 3: return START_GROUP;
case 4: return END_GROUP;
case 5: return FIXED32;
case 6: return RESERVED6;
case 7: return RESERVED7;
default: throw new IllegalArgumentException(Integer.toString(code));
}
}
}
|
0 | java-sources/ai/swim/swim-protobuf/3.10.0/swim | java-sources/ai/swim/swim-protobuf/3.10.0/swim/protobuf/package-info.java | // 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.
/**
* Protocol Buffers (protobuf) codec.
*/
package swim.protobuf;
|
0 | java-sources/ai/swim/swim-recon | java-sources/ai/swim/swim-recon/3.10.0/module-info.java | // 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.
/**
* Record Notation (Recon) codec.
*/
module swim.recon {
requires swim.util;
requires transitive swim.codec;
requires transitive swim.structure;
exports swim.recon;
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/AdditiveOperatorParser.java | // 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.recon;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
import swim.util.Builder;
final class AdditiveOperatorParser<I, V> extends Parser<V> {
final ReconParser<I, V> recon;
final Builder<I, V> builder;
final Parser<V> lhsParser;
final String operator;
final Parser<V> rhsParser;
final int step;
AdditiveOperatorParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> lhsParser,
String operator, Parser<V> rhsParser, int step) {
this.recon = recon;
this.builder = builder;
this.lhsParser = lhsParser;
this.operator = operator;
this.rhsParser = rhsParser;
this.step = step;
}
@Override
public Parser<V> feed(Input input) {
return parse(input, this.recon, this.builder, this.lhsParser, this.operator,
this.rhsParser, this.step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder,
Parser<V> lhsParser, String operator, Parser<V> rhsParser, int step) {
int c = 0;
do {
if (step == 1) {
if (lhsParser == null) {
lhsParser = recon.parseMultiplicativeOperator(input, builder);
}
while (lhsParser.isCont() && !input.isEmpty()) {
lhsParser = lhsParser.feed(input);
}
if (lhsParser.isDone()) {
step = 2;
} else if (lhsParser.isError()) {
return lhsParser.asError();
}
}
if (step == 2) {
while (input.isCont()) {
c = input.head();
if (Recon.isSpace(c)) {
input = input.step();
} else {
break;
}
}
if (input.isCont()) {
if (c == '+') {
input = input.step();
operator = "+";
step = 3;
} else if (c == '-') {
input = input.step();
operator = "-";
step = 3;
} else {
return lhsParser;
}
} else if (input.isDone()) {
return lhsParser;
}
}
if (step == 3) {
if (rhsParser == null) {
rhsParser = recon.parseMultiplicativeOperator(input, builder);
}
while (rhsParser.isCont() && !input.isEmpty()) {
rhsParser = rhsParser.feed(input);
}
if (rhsParser.isDone()) {
final V lhs = lhsParser.bind();
final V rhs = rhsParser.bind();
if ("+".equals(operator)) {
lhsParser = done(recon.plus(lhs, rhs));
} else if ("-".equals(operator)) {
lhsParser = done(recon.minus(lhs, rhs));
} else {
return error(Diagnostic.message(operator, input));
}
rhsParser = null;
operator = null;
step = 2;
continue;
} else if (rhsParser.isError()) {
return rhsParser.asError();
}
}
break;
} while (true);
if (input.isError()) {
return error(input.trap());
}
return new AdditiveOperatorParser<I, V>(recon, builder, lhsParser, operator, rhsParser, step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) {
return parse(input, recon, builder, null, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/AndOperatorParser.java | // 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.recon;
import swim.codec.Input;
import swim.codec.Parser;
import swim.util.Builder;
final class AndOperatorParser<I, V> extends Parser<V> {
final ReconParser<I, V> recon;
final Builder<I, V> builder;
final Parser<V> lhsParser;
final Parser<V> rhsParser;
final int step;
AndOperatorParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> lhsParser,
Parser<V> rhsParser, int step) {
this.recon = recon;
this.builder = builder;
this.lhsParser = lhsParser;
this.rhsParser = rhsParser;
this.step = step;
}
@Override
public Parser<V> feed(Input input) {
return parse(input, this.recon, this.builder, this.lhsParser, this.rhsParser, this.step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder,
Parser<V> lhsParser, Parser<V> rhsParser, int step) {
int c = 0;
do {
if (step == 1) {
if (lhsParser == null) {
lhsParser = recon.parseBitwiseOrOperator(input, builder);
}
while (lhsParser.isCont() && !input.isEmpty()) {
lhsParser = lhsParser.feed(input);
}
if (lhsParser.isDone()) {
step = 2;
} else if (lhsParser.isError()) {
return lhsParser.asError();
}
}
if (step == 2) {
if (input.isCont()) {
c = input.head();
if (c == '&') {
// first '&' consumed by BitwiseAndOperatorParser
input = input.step();
step = 3;
} else {
return lhsParser;
}
} else if (input.isDone()) {
return lhsParser;
}
}
if (step == 3) {
if (rhsParser == null) {
rhsParser = recon.parseBitwiseOrOperator(input, builder);
}
while (rhsParser.isCont() && !input.isEmpty()) {
rhsParser = rhsParser.feed(input);
}
if (rhsParser.isDone()) {
final V lhs = lhsParser.bind();
final V rhs = rhsParser.bind();
lhsParser = done(recon.and(lhs, rhs));
rhsParser = null;
step = 2;
continue;
} else if (rhsParser.isError()) {
return rhsParser.asError();
}
}
break;
} while (true);
if (input.isError()) {
return error(input.trap());
}
return new AndOperatorParser<I, V>(recon, builder, lhsParser, rhsParser, step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) {
return parse(input, recon, builder, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/AttrExpressionParser.java | // 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.recon;
import swim.codec.Input;
import swim.codec.Parser;
import swim.util.Builder;
final class AttrExpressionParser<I, V> extends Parser<V> {
final ReconParser<I, V> recon;
final Builder<I, V> builder;
final Parser<I> fieldParser;
final Parser<V> valueParser;
final int step;
AttrExpressionParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<I> fieldParser,
Parser<V> valueParser, int step) {
this.recon = recon;
this.builder = builder;
this.fieldParser = fieldParser;
this.valueParser = valueParser;
this.step = step;
}
@Override
public Parser<V> feed(Input input) {
return parse(input, this.recon, this.builder, this.fieldParser, this.valueParser, this.step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder,
Parser<I> fieldParser, Parser<V> valueParser, int step) {
int c = 0;
do {
if (step == 1) {
while (input.isCont()) {
c = input.head();
if (Recon.isSpace(c)) {
input = input.step();
} else {
break;
}
}
if (input.isCont()) {
if (c == '@') {
step = 2;
} else if (c == '{' || c == '[') {
if (builder == null) {
builder = recon.recordBuilder();
}
step = 5;
} else if (c == '(') {
step = 4;
} else if (c == '!' || c == '"' || c == '$' || c == '%'
|| c == '\'' || c == '+' || c == '-'
|| c >= '0' && c <= '9' || c == '~'
|| Recon.isIdentStartChar(c)) {
step = 3;
} else if (builder == null) {
return done(recon.extant());
} else {
return done(builder.bind());
}
} else if (input.isDone()) {
if (builder == null) {
return done(recon.extant());
} else {
return done(builder.bind());
}
}
}
if (step == 2) {
if (fieldParser == null) {
fieldParser = recon.parseAttr(input);
}
while (fieldParser.isCont() && !input.isEmpty()) {
fieldParser = fieldParser.feed(input);
}
if (fieldParser.isDone()) {
if (builder == null) {
builder = recon.recordBuilder();
}
builder.add(fieldParser.bind());
fieldParser = null;
step = 1;
continue;
} else if (fieldParser.isError()) {
return fieldParser.asError();
}
}
if (step == 3) {
if (valueParser == null) {
valueParser = recon.parseAdditiveOperator(input, null);
}
while (valueParser.isCont() && !input.isEmpty()) {
valueParser = valueParser.feed(input);
}
if (valueParser.isDone()) {
if (builder == null) {
builder = recon.valueBuilder();
}
builder.add(recon.item(valueParser.bind()));
valueParser = null;
step = 6;
} else if (valueParser.isError()) {
return valueParser.asError();
}
}
if (step == 4) {
if (valueParser == null) {
valueParser = recon.parseAdditiveOperator(input, builder);
}
while (valueParser.isCont() && !input.isEmpty()) {
valueParser = valueParser.feed(input);
}
if (valueParser.isDone()) {
if (builder == null) {
builder = recon.valueBuilder();
builder.add(recon.item(valueParser.bind()));
}
valueParser = null;
step = 6;
} else if (valueParser.isError()) {
return valueParser.asError();
}
}
if (step == 5) {
if (valueParser == null) {
valueParser = recon.parseAdditiveOperator(input, builder);
}
while (valueParser.isCont() && !input.isEmpty()) {
valueParser = valueParser.feed(input);
}
if (valueParser.isDone()) {
valueParser = null;
step = 6;
} else if (valueParser.isError()) {
return valueParser.asError();
}
}
if (step == 6) {
while (input.isCont()) {
c = input.head();
if (Recon.isSpace(c)) {
input = input.step();
} else {
break;
}
}
if (input.isCont()) {
if (c == '@') {
step = 1;
continue;
} else {
return done(builder.bind());
}
} else if (input.isDone()) {
return done(builder.bind());
}
}
break;
} while (true);
if (input.isError()) {
return error(input.trap());
}
return new AttrExpressionParser<I, V>(recon, builder, fieldParser, valueParser, step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) {
return parse(input, recon, builder, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/AttrParser.java | // 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.recon;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
final class AttrParser<I, V> extends Parser<I> {
final ReconParser<I, V> recon;
final Parser<V> keyParser;
final Parser<V> valueParser;
final int step;
AttrParser(ReconParser<I, V> recon, Parser<V> keyParser, Parser<V> valueParser, int step) {
this.recon = recon;
this.keyParser = keyParser;
this.valueParser = valueParser;
this.step = step;
}
@Override
public Parser<I> feed(Input input) {
return parse(input, this.recon, this.keyParser, this.valueParser, this.step);
}
static <I, V> Parser<I> parse(Input input, ReconParser<I, V> recon, Parser<V> keyParser,
Parser<V> valueParser, int step) {
int c = 0;
if (step == 1) {
if (input.isCont()) {
c = input.head();
if (c == '@') {
input = input.step();
step = 2;
} else {
return error(Diagnostic.expected('@', input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected('@', input));
}
}
if (step == 2) {
if (keyParser == null) {
if (input.isCont()) {
c = input.head();
if (c == '"' || c == '\'') {
keyParser = recon.parseString(input);
} else if (Recon.isIdentStartChar(c)) {
keyParser = recon.parseIdent(input);
} else {
return error(Diagnostic.expected("attribute name", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("attribute name", input));
}
} else {
keyParser = keyParser.feed(input);
}
if (keyParser != null) {
if (keyParser.isDone()) {
step = 3;
} else if (keyParser.isError()) {
return keyParser.asError();
}
}
}
if (step == 3) {
if (input.isCont() && input.head() == '(') {
input = input.step();
step = 4;
} else if (!input.isEmpty()) {
return done(recon.attr(keyParser.bind()));
}
}
if (step == 4) {
while (input.isCont()) {
c = input.head();
if (Recon.isWhitespace(c)) {
input = input.step();
} else {
break;
}
}
if (input.isCont()) {
if (c == ')') {
input = input.step();
return done(recon.attr(keyParser.bind()));
} else {
step = 5;
}
} else if (input.isDone()) {
return error(Diagnostic.expected(')', input));
}
}
if (step == 5) {
if (valueParser == null) {
valueParser = recon.parseBlock(input);
}
while (valueParser.isCont() && !input.isEmpty()) {
valueParser = valueParser.feed(input);
}
if (valueParser.isDone()) {
step = 6;
} else if (valueParser.isError()) {
return valueParser.asError();
}
}
if (step == 6) {
while (input.isCont()) {
c = input.head();
if (Recon.isWhitespace(c)) {
input = input.step();
} else {
break;
}
}
if (input.isCont()) {
if (c == ')') {
input = input.step();
return done(recon.attr(keyParser.bind(), valueParser.bind()));
} else {
return error(Diagnostic.expected(')', input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected(')', input));
}
}
if (input.isError()) {
return error(input.trap());
}
return new AttrParser<I, V>(recon, keyParser, valueParser, step);
}
static <I, V> Parser<I> parse(Input input, ReconParser<I, V> recon) {
return parse(input, recon, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/AttrWriter.java | // 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.recon;
import swim.codec.Output;
import swim.codec.Writer;
import swim.codec.WriterException;
final class AttrWriter<I, V> extends Writer<Object, Object> {
final ReconWriter<I, V> recon;
final V key;
final V value;
final Writer<?, ?> part;
final int step;
AttrWriter(ReconWriter<I, V> recon, V key, V value, Writer<?, ?> part, int step) {
this.recon = recon;
this.key = key;
this.value = value;
this.part = part;
this.step = step;
}
@Override
public Writer<Object, Object> pull(Output<?> output) {
return write(output, this.recon, this.key, this.value, this.part, this.step);
}
static <I, V> int sizeOf(ReconWriter<I, V> recon, V key, V value) {
int size = 0;
size += 1; // '@'
size += recon.sizeOfValue(key);
if (!recon.isExtant(recon.item(value))) {
size += 1; // '(';
size += recon.sizeOfBlockValue(value);
size += 1; // ')';
}
return size;
}
static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon,
V key, V value, Writer<?, ?> part, int step) {
if (step == 1 && output.isCont()) {
output = output.write('@');
step = 2;
}
if (step == 2) {
if (part == null) {
part = recon.writeValue(key, output);
} else {
part = part.pull(output);
}
if (part.isDone()) {
part = null;
if (recon.isExtant(recon.item(value))) {
return done();
} else {
step = 3;
}
} else if (part.isError()) {
return part.asError();
}
}
if (step == 3 && output.isCont()) {
output = output.write('(');
step = 4;
}
if (step == 4) {
if (part == null) {
part = recon.writeBlockValue(value, output);
} else {
part = part.pull(output);
}
if (part.isDone()) {
part = null;
step = 5;
} else if (part.isError()) {
return part.asError();
}
}
if (step == 5 && output.isCont()) {
output = output.write(')');
return done();
}
if (output.isDone()) {
return error(new WriterException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new AttrWriter<I, V>(recon, key, value, part, step);
}
static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon,
V key, V value) {
return write(output, recon, key, value, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/BitwiseAndOperatorParser.java | // 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.recon;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
import swim.util.Builder;
final class BitwiseAndOperatorParser<I, V> extends Parser<V> {
final ReconParser<I, V> recon;
final Builder<I, V> builder;
final Parser<V> lhsParser;
final Parser<V> rhsParser;
final int step;
BitwiseAndOperatorParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> lhsParser,
Parser<V> rhsParser, int step) {
this.recon = recon;
this.builder = builder;
this.lhsParser = lhsParser;
this.rhsParser = rhsParser;
this.step = step;
}
@Override
public Parser<V> feed(Input input) {
return parse(input, this.recon, this.builder, this.lhsParser, this.rhsParser, this.step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder,
Parser<V> lhsParser, Parser<V> rhsParser, int step) {
int c = 0;
do {
if (step == 1) {
if (lhsParser == null) {
lhsParser = recon.parseComparisonOperator(input, builder);
}
while (lhsParser.isCont() && !input.isEmpty()) {
lhsParser = lhsParser.feed(input);
}
if (lhsParser.isDone()) {
step = 2;
} else if (lhsParser.isError()) {
return lhsParser.asError();
}
}
if (step == 2) {
while (input.isCont()) {
c = input.head();
if (Recon.isSpace(c)) {
input = input.step();
} else {
break;
}
}
if (input.isCont()) {
if (c == '&') {
input = input.step();
step = 3;
} else {
return lhsParser;
}
} else if (input.isDone()) {
return lhsParser;
}
}
if (step == 3) {
if (input.isCont()) {
c = input.head();
if (c == '&') {
return lhsParser;
} else {
step = 4;
}
} else if (input.isDone()) {
return error(Diagnostic.unexpected(input));
}
}
if (step == 4) {
if (rhsParser == null) {
rhsParser = recon.parseComparisonOperator(input, builder);
}
while (rhsParser.isCont() && !input.isEmpty()) {
rhsParser = rhsParser.feed(input);
}
if (rhsParser.isDone()) {
final V lhs = lhsParser.bind();
final V rhs = rhsParser.bind();
lhsParser = done(recon.bitwiseAnd(lhs, rhs));
rhsParser = null;
step = 2;
continue;
} else if (rhsParser.isError()) {
return rhsParser.asError();
}
}
break;
} while (true);
if (input.isError()) {
return error(input.trap());
}
return new BitwiseAndOperatorParser<I, V>(recon, builder, lhsParser, rhsParser, step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) {
return parse(input, recon, builder, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/BitwiseOrOperatorParser.java | // 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.recon;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
import swim.util.Builder;
final class BitwiseOrOperatorParser<I, V> extends Parser<V> {
final ReconParser<I, V> recon;
final Builder<I, V> builder;
final Parser<V> lhsParser;
final Parser<V> rhsParser;
final int step;
BitwiseOrOperatorParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> lhsParser,
Parser<V> rhsParser, int step) {
this.recon = recon;
this.builder = builder;
this.lhsParser = lhsParser;
this.rhsParser = rhsParser;
this.step = step;
}
@Override
public Parser<V> feed(Input input) {
return parse(input, this.recon, this.builder, this.lhsParser, this.rhsParser, this.step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder,
Parser<V> lhsParser, Parser<V> rhsParser, int step) {
int c = 0;
do {
if (step == 1) {
if (lhsParser == null) {
lhsParser = recon.parseBitwiseXorOperator(input, builder);
}
while (lhsParser.isCont() && !input.isEmpty()) {
lhsParser = lhsParser.feed(input);
}
if (lhsParser.isDone()) {
step = 2;
} else if (lhsParser.isError()) {
return lhsParser.asError();
}
}
if (step == 2) {
while (input.isCont()) {
c = input.head();
if (Recon.isSpace(c)) {
input = input.step();
} else {
break;
}
}
if (input.isCont()) {
if (c == '|') {
input = input.step();
step = 3;
} else {
return lhsParser;
}
} else if (input.isDone()) {
return lhsParser;
}
}
if (step == 3) {
if (input.isCont()) {
c = input.head();
if (c == '|') {
return lhsParser;
} else {
step = 4;
}
} else if (input.isDone()) {
return error(Diagnostic.unexpected(input));
}
}
if (step == 4) {
if (rhsParser == null) {
rhsParser = recon.parseBitwiseXorOperator(input, builder);
}
while (rhsParser.isCont() && !input.isEmpty()) {
rhsParser = rhsParser.feed(input);
}
if (rhsParser.isDone()) {
final V lhs = lhsParser.bind();
final V rhs = rhsParser.bind();
lhsParser = done(recon.bitwiseOr(lhs, rhs));
rhsParser = null;
step = 2;
continue;
} else if (rhsParser.isError()) {
return rhsParser.asError();
}
}
break;
} while (true);
if (input.isError()) {
return error(input.trap());
}
return new BitwiseOrOperatorParser<I, V>(recon, builder, lhsParser, rhsParser, step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) {
return parse(input, recon, builder, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/BitwiseXorOperatorParser.java | // 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.recon;
import swim.codec.Input;
import swim.codec.Parser;
import swim.util.Builder;
final class BitwiseXorOperatorParser<I, V> extends Parser<V> {
final ReconParser<I, V> recon;
final Builder<I, V> builder;
final Parser<V> lhsParser;
final Parser<V> rhsParser;
final int step;
BitwiseXorOperatorParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> lhsParser,
Parser<V> rhsParser, int step) {
this.recon = recon;
this.builder = builder;
this.lhsParser = lhsParser;
this.rhsParser = rhsParser;
this.step = step;
}
@Override
public Parser<V> feed(Input input) {
return parse(input, this.recon, this.builder, this.lhsParser, this.rhsParser, this.step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder,
Parser<V> lhsParser, Parser<V> rhsParser, int step) {
int c = 0;
do {
if (step == 1) {
if (lhsParser == null) {
lhsParser = recon.parseBitwiseAndOperator(input, builder);
}
while (lhsParser.isCont() && !input.isEmpty()) {
lhsParser = lhsParser.feed(input);
}
if (lhsParser.isDone()) {
step = 2;
} else if (lhsParser.isError()) {
return lhsParser.asError();
}
}
if (step == 2) {
while (input.isCont()) {
c = input.head();
if (Recon.isSpace(c)) {
input = input.step();
} else {
break;
}
}
if (input.isCont()) {
if (c == '^') {
input = input.step();
step = 3;
} else {
return lhsParser;
}
} else if (input.isDone()) {
return lhsParser;
}
}
if (step == 3) {
if (rhsParser == null) {
rhsParser = recon.parseBitwiseAndOperator(input, builder);
}
while (rhsParser.isCont() && !input.isEmpty()) {
rhsParser = rhsParser.feed(input);
}
if (rhsParser.isDone()) {
final V lhs = lhsParser.bind();
final V rhs = rhsParser.bind();
lhsParser = done(recon.bitwiseXor(lhs, rhs));
rhsParser = null;
step = 2;
continue;
} else if (rhsParser.isError()) {
return rhsParser.asError();
}
}
break;
} while (true);
if (input.isError()) {
return error(input.trap());
}
return new BitwiseXorOperatorParser<I, V>(recon, builder, lhsParser, rhsParser, step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) {
return parse(input, recon, builder, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/BlockItemParser.java | // 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.recon;
import swim.codec.Input;
import swim.codec.Parser;
import swim.util.Builder;
final class BlockItemParser<I, V> extends Parser<V> {
final ReconParser<I, V> recon;
final Builder<I, V> builder;
final Parser<I> fieldParser;
final Parser<V> valueParser;
final int step;
BlockItemParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<I> fieldParser,
Parser<V> valueParser, int step) {
this.recon = recon;
this.builder = builder;
this.fieldParser = fieldParser;
this.valueParser = valueParser;
this.step = step;
}
@Override
public Parser<V> feed(Input input) {
return parse(input, this.recon, this.builder, this.fieldParser, this.valueParser, this.step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder,
Parser<I> fieldParser, Parser<V> valueParser, int step) {
int c = 0;
do {
if (step == 1) {
if (input.isCont()) {
c = input.head();
if (c == '@') {
fieldParser = recon.parseAttr(input);
step = 2;
} else if (c == '{') {
if (builder == null) {
builder = recon.recordBuilder();
}
valueParser = recon.parseRecord(input, builder);
step = 5;
} else if (c == '[') {
if (builder == null) {
builder = recon.recordBuilder();
}
valueParser = recon.parseMarkup(input, builder);
step = 5;
} else if (Recon.isIdentStartChar(c)) {
valueParser = recon.parseIdent(input);
step = 4;
} else if (c == '"' || c == '\'') {
valueParser = recon.parseString(input);
step = 4;
} else if (c == '-' || c >= '0' && c <= '9') {
valueParser = recon.parseNumber(input);
step = 4;
} else if (c == '%') {
valueParser = recon.parseData(input);
step = 4;
} else if (c == '$') {
valueParser = recon.parseSelector(input);
step = 4;
} else if (builder == null) {
return done(recon.extant());
} else {
return done(builder.bind());
}
} else if (input.isDone()) {
if (builder == null) {
return done(recon.extant());
} else {
return done(builder.bind());
}
}
}
if (step == 2) {
while (fieldParser.isCont() && !input.isEmpty()) {
fieldParser = fieldParser.feed(input);
}
if (fieldParser.isDone()) {
if (builder == null) {
builder = recon.valueBuilder();
}
builder.add(fieldParser.bind());
fieldParser = null;
step = 3;
} else if (fieldParser.isError()) {
return fieldParser.asError();
}
}
if (step == 3) {
while (input.isCont() && Recon.isSpace(input.head())) {
input = input.step();
}
if (input.isCont()) {
step = 1;
continue;
} else if (input.isDone()) {
return done(builder.bind());
}
}
if (step == 4) {
while (valueParser.isCont() && !input.isEmpty()) {
valueParser = valueParser.feed(input);
}
if (valueParser.isDone()) {
if (builder == null) {
builder = recon.valueBuilder();
}
builder.add(recon.item(valueParser.bind()));
valueParser = null;
step = 6;
} else if (valueParser.isError()) {
return valueParser;
}
}
if (step == 5) {
while (valueParser.isCont() && !input.isEmpty()) {
valueParser = valueParser.feed(input);
}
if (valueParser.isDone()) {
valueParser = null;
step = 6;
} else if (valueParser.isError()) {
return valueParser;
}
}
if (step == 6) {
while (input.isCont() && Recon.isSpace(input.head())) {
input = input.step();
}
if (input.isCont()) {
if (input.head() == '@') {
step = 1;
} else {
return done(builder.bind());
}
} else if (input.isDone()) {
return done(builder.bind());
}
}
break;
} while (true);
if (input.isError()) {
return error(input.trap());
}
return new BlockItemParser<I, V>(recon, builder, fieldParser, valueParser, step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon) {
return parse(input, recon, null, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/BlockParser.java | // 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.recon;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
import swim.util.Builder;
final class BlockParser<I, V> extends Parser<V> {
final ReconParser<I, V> recon;
final Builder<I, V> builder;
final Parser<V> keyParser;
final Parser<V> valueParser;
final int step;
BlockParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> keyParser,
Parser<V> valueParser, int step) {
this.recon = recon;
this.builder = builder;
this.keyParser = keyParser;
this.valueParser = valueParser;
this.step = step;
}
BlockParser(ReconParser<I, V> recon) {
this(recon, null, null, null, 1);
}
@Override
public Parser<V> feed(Input input) {
return parse(input, this.recon, this.builder, this.keyParser, this.valueParser, this.step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder,
Parser<V> keyParser, Parser<V> valueParser, int step) {
int c = 0;
block: do {
if (step == 1) {
while (input.isCont()) {
c = input.head();
if (Recon.isWhitespace(c)) {
input = input.step();
} else {
break;
}
}
if (input.isCont()) {
if (c == '!' || c == '"' || c == '$' || c == '%'
|| c == '\'' || c == '(' || c == '+' || c == '-'
|| c >= '0' && c <= '9' || c == '@'
|| c == '[' || c == '{' || c == '~'
|| Recon.isIdentStartChar(c)) {
if (builder == null) {
builder = recon.valueBuilder();
}
step = 2;
} else if (c == '#') {
input = input.step();
step = 7;
} else {
return error(Diagnostic.expected("block", input));
}
} else if (input.isError()) {
return error(input.trap());
} else if (input.isDone()) {
if (builder != null) {
return done(builder.bind());
} else {
return done(recon.absent());
}
}
}
if (step == 2) {
if (keyParser == null) {
keyParser = recon.parseBlockExpression(input);
}
while (keyParser.isCont() && !input.isEmpty()) {
keyParser = keyParser.feed(input);
}
if (keyParser.isDone()) {
step = 3;
} else if (keyParser.isError()) {
return keyParser;
}
}
if (step == 3) {
while (input.isCont()) {
c = input.head();
if (Recon.isSpace(c)) {
input = input.step();
} else {
break;
}
}
if (input.isCont()) {
if (c == ':') {
input = input.step();
step = 4;
} else {
builder.add(recon.item(keyParser.bind()));
keyParser = null;
step = 6;
}
} else if (input.isDone()) {
builder.add(recon.item(keyParser.bind()));
return done(builder.bind());
}
}
if (step == 4) {
while (input.isCont() && Recon.isSpace(input.head())) {
input = input.step();
}
if (input.isCont()) {
step = 5;
} else if (input.isDone()) {
builder.add(recon.slot(keyParser.bind()));
return done(builder.bind());
}
}
if (step == 5) {
if (valueParser == null) {
valueParser = recon.parseBlockExpression(input);
}
while (valueParser.isCont() && !input.isEmpty()) {
valueParser = valueParser.feed(input);
}
if (valueParser.isDone()) {
builder.add(recon.slot(keyParser.bind(), valueParser.bind()));
keyParser = null;
valueParser = null;
step = 6;
} else if (valueParser.isError()) {
return valueParser;
}
}
if (step == 6) {
while (input.isCont()) {
c = input.head();
if (Recon.isSpace(c)) {
input = input.step();
} else {
break;
}
}
if (input.isCont()) {
if (c == ',' || c == ';' || Recon.isNewline(c)) {
input = input.step();
step = 1;
continue;
} else if (c == '#') {
input = input.step();
step = 7;
} else {
return done(builder.bind());
}
} else if (input.isDone()) {
return done(builder.bind());
}
}
if (step == 7) {
while (input.isCont()) {
c = input.head();
if (!Recon.isNewline(c)) {
input = input.step();
} else {
step = 1;
continue block;
}
}
if (input.isDone()) {
step = 1;
continue;
}
}
break;
} while (true);
if (input.isError()) {
return error(input.trap());
}
return new BlockParser<I, V>(recon, builder, keyParser, valueParser, step);
}
static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon) {
return parse(input, recon, null, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/BlockWriter.java | // 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.recon;
import java.util.Iterator;
import swim.codec.Output;
import swim.codec.Writer;
import swim.codec.WriterException;
final class BlockWriter<I, V> extends Writer<Object, Object> {
final ReconWriter<I, V> recon;
final Iterator<I> items;
final boolean inBlock;
final boolean inMarkup;
final boolean inBraces;
final boolean inBrackets;
final boolean first;
final boolean markupSafe;
final I item;
final I next;
final Writer<?, ?> part;
final int step;
BlockWriter(ReconWriter<I, V> recon, Iterator<I> items, boolean inBlock, boolean inMarkup,
boolean inBraces, boolean inBrackets, boolean first, boolean markupSafe,
I item, I next, Writer<?, ?> part, int step) {
this.recon = recon;
this.items = items;
this.inBlock = inBlock;
this.inMarkup = inMarkup;
this.inBraces = inBraces;
this.inBrackets = inBrackets;
this.first = first;
this.markupSafe = markupSafe;
this.item = item;
this.next = next;
this.part = part;
this.step = step;
}
@Override
public Writer<Object, Object> pull(Output<?> output) {
return write(output, this.recon, this.items, this.inBlock, this.inMarkup,
this.inBraces, this.inBrackets, this.first, this.markupSafe,
this.item, this.next, this.part, this.step);
}
static <I, V> int sizeOf(ReconWriter<I, V> recon, Iterator<I> items,
boolean inBlock, boolean inMarkup) {
int size = 0;
boolean inBraces = false;
boolean inBrackets = false;
boolean first = true;
boolean markupSafe = true;
I next = null;
while (next != null || items.hasNext()) {
final I item;
if (next == null) {
item = items.next();
} else {
item = next;
next = null;
}
if (items.hasNext()) {
next = items.next();
}
if (recon.isExpression(item)) {
markupSafe = false;
}
if (inBrackets && recon.isAttr(item)) {
if (inBraces) {
size += 1; // '}'
inBraces = false;
}
size += 1; // ']'
inBrackets = false;
}
if (recon.isAttr(item)) {
if (inBraces) {
size += 1; // '}'
inBraces = false;
} else if (inBrackets) { // FIXME: case already covered?
size += 1; // ']'
inBrackets = false;
}
size += recon.sizeOfItem(item);
first = false;
} else if (inBrackets && recon.isText(item)) {
if (inBraces) {
size += 1; // '}'
inBraces = false;
}
size += recon.sizeOfMarkupText(item);
} else if (inBraces) {
if (!first) {
size += 1; // ','
} else {
first = false;
}
size += sizeOfBlockItem(recon, item);
} else if (inBrackets) {
if (recon.isRecord(item) && recon.isMarkupSafe(recon.items(item))) {
size += recon.sizeOfBlock(recon.items(item), false, true);
if (next != null && recon.isText(next)) {
size += recon.sizeOfMarkupText(next);
next = null;
} else if (next != null && !recon.isAttr(next)) {
size += 1; // '{'
inBraces = true;
first = true;
} else {
size += 1; // ']'
inBrackets = false;
}
} else {
size += 1; // '{'
size += recon.sizeOfItem(item);
inBraces = true;
first = false;
}
} else if (markupSafe && recon.isText(item) && next != null && !recon.isField(next)
&& !recon.isText(next) && !recon.isBool(next)) {
size += 1; // '['
size += recon.sizeOfMarkupText(item);
inBrackets = true;
} else if (inBlock && !inBraces) {
if (!first) {
size += 1; // ','
} else {
first = false;
}
size += sizeOfBlockItem(recon, item);
} else if (inMarkup && recon.isText(item) && next == null) {
size += 1; // '['
size += recon.sizeOfMarkupText(item);
size += 1; // ']'
} else if (!inMarkup && recon.isValue(item) && !recon.isRecord(item)
&& (!first && next == null || next != null && recon.isAttr(next))) {
if (!first && (recon.isText(item) && recon.isIdent(item)
|| recon.isNum(item) || recon.isBool(item))) {
size += 1; // ' '
}
size += recon.sizeOfItem(item);
} else {
size += 1; // '{'
size += recon.sizeOfItem(item);
inBraces = true;
first = false;
}
}
if (inBraces) {
size += 1; // '}'
}
if (inBrackets) {
size += 1; // ']'
}
return size;
}
static <I, V> int sizeOfBlockItem(ReconWriter<I, V> recon, I item) {
int size = 0;
if (recon.isField(item)) {
size += recon.sizeOfSlot(recon.key(item), recon.value(item));
} else {
size += recon.sizeOfItem(item);
}
return size;
}
static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, Iterator<I> items,
boolean inBlock, boolean inMarkup, boolean inBraces,
boolean inBrackets, boolean first, boolean markupSafe,
I item, I next, Writer<?, ?> part, int step) {
do {
if (step == 1) {
if (next == null && !items.hasNext()) {
step = 10;
break;
} else {
if (next == null) {
item = items.next();
} else {
item = next;
next = null;
}
if (items.hasNext()) {
next = items.next();
}
if (recon.isExpression(item)) {
markupSafe = false;
}
step = 2;
}
}
if (step == 2 && output.isCont()) {
if (inBrackets && recon.isAttr(item)) {
if (inBraces) {
output = output.write('}');
inBraces = false;
}
step = 3;
} else {
step = 4;
}
}
if (step == 3 && output.isCont()) {
output = output.write(']');
inBrackets = false;
step = 4;
}
if (step == 4 && output.isCont()) {
if (recon.isAttr(item)) {
if (inBraces) {
output = output.write('}');
inBraces = false;
} else if (inBrackets) {
output = output.write(']');
inBrackets = false;
}
part = recon.writeItem(item, output);
first = false;
step = 7;
} else if (inBrackets && recon.isText(item)) {
if (inBraces) {
output = output.write('}');
inBraces = false;
}
part = recon.writeMarkupText(item, output);
step = 7;
} else if (inBraces) {
if (!first) {
output = output.write(',');
} else {
first = false;
}
part = writeItem(output, recon, item);
step = 7;
} else if (inBrackets) {
if (recon.isRecord(item) && recon.isMarkupSafe(recon.items(item))) {
part = recon.writeBlock(recon.items(item), output, false, true);
step = 5;
} else {
output = output.write('{');
part = recon.writeItem(item, output);
inBraces = true;
first = false;
step = 7;
}
} else if (markupSafe && recon.isText(item) && next != null && !recon.isField(next)
&& !recon.isText(next) && !recon.isBool(next)) {
output = output.write('[');
part = recon.writeMarkupText(item, output);
inBrackets = true;
step = 7;
} else if (inBlock && !inBraces) {
if (!first) {
output = output.write(',');
} else {
first = false;
}
part = writeItem(output, recon, item);
step = 7;
} else if (inMarkup && recon.isText(item) && next == null) {
output = output.write('[');
part = recon.writeMarkupText(item, output);
step = 8;
} else if (!inMarkup && recon.isValue(item) && !recon.isRecord(item)
&& (!first && next == null || next != null && recon.isAttr(next))) {
if (!first && (recon.isText(item) && recon.isIdent(item)
|| recon.isNum(item) || recon.isBool(item))) {
output = output.write(' ');
}
part = recon.writeItem(item, output);
step = 7;
} else {
output = output.write('{');
part = recon.writeItem(item, output);
inBraces = true;
first = false;
step = 7;
}
}
if (step == 5) {
part = part.pull(output);
if (part.isDone()) {
part = null;
step = 6;
} else if (part.isError()) {
return part.asError();
}
}
if (step == 6 && output.isCont()) {
if (next != null && recon.isText(next)) {
part = recon.writeMarkupText(next, output);
next = null;
step = 7;
} else if (next != null && !recon.isAttr(next)) {
output = output.write('{');
inBraces = true;
first = true;
step = 1;
continue;
} else {
output = output.write(']');
inBrackets = false;
step = 1;
continue;
}
}
if (step == 7) {
part = part.pull(output);
if (part.isDone()) {
part = null;
step = 1;
continue;
} else if (part.isError()) {
return part.asError();
}
}
if (step == 8) {
part = part.pull(output);
if (part.isDone()) {
part = null;
step = 9;
} else if (part.isError()) {
return part.asError();
}
}
if (step == 9 && output.isCont()) {
output = output.write(']');
step = 1;
continue;
}
break;
} while (true);
if (step == 10) {
if (inBraces) {
if (output.isCont()) {
output = output.write('}');
step = 11;
}
} else {
step = 11;
}
}
if (step == 11) {
if (inBrackets) {
if (output.isCont()) {
output = output.write(']');
return done();
}
} else {
return done();
}
}
if (output.isDone()) {
return error(new WriterException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new BlockWriter<I, V>(recon, items, inBlock, inMarkup, inBraces, inBrackets,
first, markupSafe, item, next, part, step);
}
static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon,
Iterator<I> items, boolean inBlock, boolean inMarkup) {
return write(output, recon, items, inBlock, inMarkup, false, false, true, true, null, null, null, 1);
}
static <I, V> Writer<?, ?> writeItem(Output<?> output, ReconWriter<I, V> recon, I item) {
if (recon.isField(item)) {
return recon.writeSlot(recon.key(item), recon.value(item), output);
} else {
return recon.writeItem(item, output);
}
}
}
|
0 | java-sources/ai/swim/swim-recon/3.10.0/swim | java-sources/ai/swim/swim-recon/3.10.0/swim/recon/ChildrenSelectorWriter.java | // 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.recon;
import swim.codec.Output;
import swim.codec.Writer;
import swim.codec.WriterException;
final class ChildrenSelectorWriter<I, V> extends Writer<Object, Object> {
final ReconWriter<I, V> recon;
final V then;
final int step;
ChildrenSelectorWriter(ReconWriter<I, V> recon, V then, int step) {
this.recon = recon;
this.then = then;
this.step = step;
}
@Override
public Writer<Object, Object> pull(Output<?> output) {
return write(output, this.recon, this.then, this.step);
}
static <I, V> int sizeOf(ReconWriter<I, V> recon, V then) {
int size = 2; // ('$' | '.') '*'
size += recon.sizeOfThen(then);
return size;
}
@SuppressWarnings("unchecked")
static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon,
V then, int step) {
if (step == 1 && output.isCont()) {
output = output.write('$');
step = 3;
} else if (step == 2 && output.isCont()) {
output = output.write('.');
step = 3;
}
if (step == 3 && output.isCont()) {
output = output.write('*');
return (Writer<Object, Object>) recon.writeThen(then, output);
}
if (output.isDone()) {
return error(new WriterException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new ChildrenSelectorWriter<I, V>(recon, then, step);
}
static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V then) {
return write(output, recon, then, 1);
}
static <I, V> Writer<Object, Object> writeThen(Output<?> output, ReconWriter<I, V> recon, V then) {
return write(output, recon, then, 2);
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.