├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── ci └── install-jdk.sh ├── pom.xml ├── pre-commit.sh └── src ├── main ├── java │ └── com │ │ └── datastax │ │ ├── dse │ │ └── protocol │ │ │ └── internal │ │ │ ├── DseProtocolConstants.java │ │ │ ├── DseProtocolV1ClientCodecs.java │ │ │ ├── DseProtocolV1ServerCodecs.java │ │ │ ├── DseProtocolV2ClientCodecs.java │ │ │ ├── DseProtocolV2ServerCodecs.java │ │ │ ├── ProtocolV4ClientCodecsForDse.java │ │ │ ├── request │ │ │ ├── DseBatchCodec.java │ │ │ ├── DseExecuteCodec.java │ │ │ ├── DsePrepareCodec.java │ │ │ ├── DseQueryCodec.java │ │ │ ├── DseQueryCodecV4.java │ │ │ ├── RawBytesQuery.java │ │ │ ├── Revise.java │ │ │ └── query │ │ │ │ ├── ContinuousPagingOptions.java │ │ │ │ ├── DseQueryOptions.java │ │ │ │ └── DseQueryOptionsCodec.java │ │ │ └── response │ │ │ └── result │ │ │ ├── DsePreparedSubCodec.java │ │ │ ├── DseRowsMetadata.java │ │ │ └── DseRowsSubCodec.java │ │ └── oss │ │ └── protocol │ │ └── internal │ │ ├── Compressor.java │ │ ├── CrcMismatchException.java │ │ ├── Frame.java │ │ ├── FrameCodec.java │ │ ├── Message.java │ │ ├── NoopCompressor.java │ │ ├── PrimitiveCodec.java │ │ ├── PrimitiveSizes.java │ │ ├── ProtocolConstants.java │ │ ├── ProtocolErrors.java │ │ ├── ProtocolV3ClientCodecs.java │ │ ├── ProtocolV3ServerCodecs.java │ │ ├── ProtocolV4ClientCodecs.java │ │ ├── ProtocolV4ServerCodecs.java │ │ ├── ProtocolV5ClientCodecs.java │ │ ├── ProtocolV5ServerCodecs.java │ │ ├── ProtocolV6ClientCodecs.java │ │ ├── ProtocolV6ServerCodecs.java │ │ ├── Segment.java │ │ ├── SegmentBuilder.java │ │ ├── SegmentCodec.java │ │ ├── request │ │ ├── AuthResponse.java │ │ ├── Batch.java │ │ ├── Execute.java │ │ ├── Options.java │ │ ├── Prepare.java │ │ ├── Query.java │ │ ├── Register.java │ │ ├── Startup.java │ │ └── query │ │ │ ├── QueryOptions.java │ │ │ └── Values.java │ │ ├── response │ │ ├── AuthChallenge.java │ │ ├── AuthSuccess.java │ │ ├── Authenticate.java │ │ ├── Error.java │ │ ├── Event.java │ │ ├── Ready.java │ │ ├── Result.java │ │ ├── Supported.java │ │ ├── error │ │ │ ├── AlreadyExists.java │ │ │ ├── CASWriteUnknown.java │ │ │ ├── FunctionFailure.java │ │ │ ├── ReadFailure.java │ │ │ ├── ReadTimeout.java │ │ │ ├── Unavailable.java │ │ │ ├── Unprepared.java │ │ │ ├── WriteFailure.java │ │ │ └── WriteTimeout.java │ │ ├── event │ │ │ ├── SchemaChangeEvent.java │ │ │ ├── StatusChangeEvent.java │ │ │ └── TopologyChangeEvent.java │ │ └── result │ │ │ ├── ColumnSpec.java │ │ │ ├── DefaultRows.java │ │ │ ├── Prepared.java │ │ │ ├── RawType.java │ │ │ ├── Rows.java │ │ │ ├── RowsMetadata.java │ │ │ ├── SchemaChange.java │ │ │ ├── SetKeyspace.java │ │ │ └── Void.java │ │ └── util │ │ ├── Bytes.java │ │ ├── Crc.java │ │ ├── Flags.java │ │ ├── IntIntMap.java │ │ ├── IntMap.java │ │ └── collection │ │ ├── NullAllowingImmutableList.java │ │ ├── NullAllowingImmutableMap.java │ │ └── NullAllowingImmutableSet.java └── resources │ ├── dse_protocol_v1.spec │ ├── dse_protocol_v2.spec │ ├── native_protocol_v3.spec │ ├── native_protocol_v4.spec │ ├── native_protocol_v5.spec │ └── native_protocol_v6.spec └── test └── java └── com └── datastax ├── dse └── protocol │ └── internal │ ├── DseTestDataProviders.java │ ├── request │ ├── DseBatchTest.java │ ├── DseExecuteTest.java │ ├── DsePrepareTest.java │ ├── DseQueryTest.java │ ├── RawBytesQueryTest.java │ ├── ReviseTest.java │ └── query │ │ └── DseQueryOptionsBuilder.java │ └── response │ ├── DseErrorTest.java │ └── result │ ├── DsePreparedTest.java │ └── DseRowsTest.java └── oss └── protocol └── internal ├── Assertions.java ├── FrameCodecTestBase.java ├── MessageTestBase.java ├── PrimitiveCodecTest.java ├── PrimitiveSizesTest.java ├── RequestFrameCodecTest.java ├── ResponseFrameCodecTest.java ├── RowsAssert.java ├── RowsMetadataAssert.java ├── SegmentBuilderTest.java ├── SegmentCodecHeaderTest.java ├── SegmentCodecTest.java ├── TestDataProviders.java ├── binary ├── MockBinaryString.java ├── MockCompressor.java └── MockPrimitiveCodec.java ├── request ├── AuthResponseTest.java ├── BatchTest.java ├── ExecuteTest.java ├── OptionsTest.java ├── PrepareTest.java ├── QueryTest.java ├── RegisterTest.java ├── StartupTest.java └── query │ ├── QueryOptionsBuilder.java │ └── QueryOptionsBuilderBase.java ├── response ├── AuthChallengeTest.java ├── AuthSuccessTest.java ├── AuthenticateTest.java ├── ErrorTest.java ├── ReadyTest.java ├── SupportedTest.java ├── event │ ├── SchemaChangeEventTest.java │ ├── StatusChangeEventTest.java │ └── TopologyChangeEventTest.java └── result │ ├── PreparedTest.java │ ├── RowsMetadataTest.java │ ├── RowsTest.java │ ├── SchemaChangeTest.java │ ├── SetKeyspaceTest.java │ └── VoidTest.java └── util ├── IntIntMapTest.java ├── IntMapTest.java ├── SerializationHelper.java └── collection ├── NullAllowingImmutableListTest.java ├── NullAllowingImmutableMapTest.java └── NullAllowingImmutableSetTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .settings 3 | .classpath 4 | .project 5 | .DS_Store 6 | 7 | /.idea 8 | *.iml 9 | 10 | .java-version 11 | 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | # see https://sormuras.github.io/blog/2018-03-20-jdk-matrix.html 4 | matrix: 5 | include: 6 | # 8 7 | - env: JDK='OpenJDK 8' 8 | jdk: openjdk8 9 | # 11 10 | - env: JDK='OpenJDK 11' 11 | install: . $TRAVIS_BUILD_DIR/ci/install-jdk.sh -F 11 -L GPL 12 | script: mvn test -B -Dmaven.main.skip=true -Dmaven.test.skip=true 13 | cache: 14 | directories: 15 | - $HOME/.m2 16 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing guidelines 2 | 3 | ## Design goals 4 | 5 | * no runtime dependencies 6 | * extensibility: it is possible to add new message codecs, new subcodecs for result kinds, errors 7 | and even a whole new protocol version 8 | 9 | ## Code formatting 10 | 11 | We follow the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html). See 12 | https://github.com/google/google-java-format for IDE plugins. The rules are not configurable. 13 | 14 | The build will fail if the code is not formatted. To format all files from the command line, run: 15 | 16 | ``` 17 | mvn fmt:format 18 | ``` 19 | 20 | Some aspects are not covered by the formatter: 21 | 22 | * braces must be used with `if`, `else`, `for`, `do` and `while` statements, even when the body is 23 | empty or contains only a single statement. 24 | * XML files: indent with two spaces and wrap to respect the column limit of 100 characters. 25 | 26 | Also, if your IDE sorts import statements automatically, make sure it follows the same order as the 27 | formatter: all static imports in ASCII sort order, followed by a blank line, followed by all regular 28 | imports in ASCII sort order. 29 | 30 | ## Coding style 31 | 32 | Avoid static imports, with those exceptions: 33 | * `ProtocolConstants.Version` constants (`V3`, `V4`, etc). 34 | * AssertJ's `assertThat` / `fail` in unit tests. 35 | 36 | Tests: 37 | * test methods names use lower snake case, generally start with "should" and clearly indicate the 38 | purpose of the test, for example: `should_fail_if_key_already_exists`. If you have trouble coming 39 | up with a simple name, it might be a sign that your method does too much and should be split. 40 | * we use AssertJ (`assertThat`). Don't use TestNG's assertions (`assertEquals`, `assertNull`, etc). 41 | * don't try to generify at all cost: a bit of duplication is acceptable, if that helps keep the 42 | tests simple to understand (a newcomer should be able to understand how to fix a failing test 43 | without having to read too much code). 44 | * given the simplicity of this project, it's unlikely that we'll ever need integration tests: don't 45 | start any external process from the test, the whole suite should run in a couple of seconds. 46 | 47 | ## License headers 48 | 49 | The build will fail if some license headers are missing. To update all files from the command line, 50 | run: 51 | 52 | ``` 53 | mvn license:format 54 | ``` 55 | 56 | ## Pre-commit hook (highly recommended) 57 | 58 | Ensure `pre-commit.sh` is executable, then run: 59 | 60 | ``` 61 | ln -s ../../pre-commit.sh .git/hooks/pre-commit 62 | ``` 63 | 64 | This will only allow commits if the tests pass. It is also a good reminder to keep the test suite 65 | short. 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Native protocol layer compatible with Apache Cassandra® 2 | 3 | A set of Java types representing the frames and messages of the Apache Cassandra® native protocol, 4 | with the associated serialization and deserialization logic (this is a third-party implementation, 5 | not related to the Apache Cassandra project). It is used by [Datastax 6 | Java driver 4](https://github.com/datastax/java-driver/tree/4.x) and 7 | [Simulacron](https://github.com/datastax/simulacron). 8 | 9 | Native protocol versions 3 and above are supported. 10 | 11 | ## Usage 12 | 13 | The code is agnostic about the underlying binary representation: start by implementing a 14 | `PrimitiveCodec` for your target type `B` (which could be `ByteBuffer`, Netty's `ByteBuf`, 15 | `byte[]`, etc.) 16 | 17 | You may also implement a `Compressor` (it can be `Compressor.none()` if you're not going to 18 | compress frames). 19 | 20 | Finally, build a `FrameCodec` that will allow you to encode and decode frames. 21 | `Frame.defaultClient` and `Frame.defaultServer` give you the default sets of codecs for the 22 | protocol versions that are currently supported; alternatively, you can use the constructor 23 | to register an arbitrary set of codecs. 24 | 25 | `Frame`, `Message`, and `Message` subclasses are immutable, but for efficiency they don't make 26 | defensive copies of their fields. If these fields are mutable (for example collections), they 27 | shouldn't be modified after creating a message instance. 28 | 29 | The code makes very few assumptions about how the messages will be used. Data is often represented 30 | in the most simple way. For example, `ProtocolConstants` uses simple constants to represent the 31 | protocol codes; client code can (and probably should) wrap them in more type-safe structures (such 32 | as enums) before exposing them to higher-level layers. 33 | 34 | Well-formed inputs are expected; if you pass an inconsistent `Frame` (ex: protocol v3 with a custom 35 | payload), an `IllegalArgumentException` will be thrown. 36 | 37 | ## Versioning 38 | 39 | We follow [semantic versioning](http://semver.org/). In addition, the minor (second) number matches 40 | the highest *stable* protocol version supported. The next beta version might also be partially 41 | supported. Examples: 42 | * 1.4.0: supports up to protocol v4, and possibly some features of v5 beta. 43 | * 1.4.1: bugfixes and/or new v5 beta features. 44 | * 1.5.0: v5 stable. 45 | 46 | All the types in this project are considered low-level and intended for framework developers, not 47 | end users. We'll try to preserve binary compatibility (in particular for `Frame` and `Message` 48 | implementations), but we reserve the right to introduce breaking changes at any time. 49 | 50 | ## License 51 | 52 | Copyright 2017, DataStax 53 | 54 | Licensed under the Apache License, Version 2.0 (the "License"); 55 | you may not use this file except in compliance with the License. 56 | You may obtain a copy of the License at 57 | 58 | http://www.apache.org/licenses/LICENSE-2.0 59 | 60 | Unless required by applicable law or agreed to in writing, software 61 | distributed under the License is distributed on an "AS IS" BASIS, 62 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 63 | See the License for the specific language governing permissions and 64 | limitations under the License. 65 | 66 | ---- 67 | 68 | DataStax is a registered trademark of DataStax, Inc. and its subsidiaries in the United States 69 | and/or other countries. 70 | 71 | Apache Cassandra, Apache, Tomcat, Lucene, Solr, Hadoop, Spark, TinkerPop, and Cassandra are 72 | trademarks of the [Apache Software Foundation](http://www.apache.org/) or its subsidiaries in 73 | Canada, the United States and/or other countries. 74 | -------------------------------------------------------------------------------- /pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | STASH_NAME="pre-commit-$(date +%s)" 4 | git stash save --keep-index $STASH_NAME 5 | 6 | mvn clean test 7 | RESULT=$? 8 | 9 | STASHES=$(git stash list) 10 | if [[ $STASHES == *$STASH_NAME* ]]; then 11 | git stash pop 12 | fi 13 | 14 | [ $RESULT -ne 0 ] && exit 1 15 | exit 0 16 | -------------------------------------------------------------------------------- /src/main/java/com/datastax/dse/protocol/internal/DseProtocolConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright DataStax, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.datastax.dse.protocol.internal; 17 | 18 | import com.datastax.oss.protocol.internal.ProtocolConstants; 19 | 20 | /** See {@link ProtocolConstants}, this only lists the additional DSE ones. */ 21 | public class DseProtocolConstants { 22 | 23 | public static class Version { 24 | public static final int DSE_V1 = 65; 25 | public static final int DSE_V2 = 66; 26 | public static final int MIN = DSE_V1; 27 | public static final int MAX = DSE_V2; 28 | /** If no beta version is currently supported, this will be negative. */ 29 | public static final int BETA = -1; 30 | } 31 | 32 | public static class Opcode { 33 | public static final int REVISE_REQUEST = 0xff; 34 | } 35 | 36 | public static class QueryFlag { 37 | public static final int PAGE_SIZE_BYTES = 0x40000000; 38 | public static final int CONTINUOUS_PAGING = 0x80000000; 39 | } 40 | 41 | public static class RowsFlag { 42 | public static final int CONTINUOUS_PAGING = 0x40000000; 43 | public static final int LAST_CONTINUOUS_PAGE = 0x80000000; 44 | } 45 | 46 | public static class RevisionType { 47 | public static final int CANCEL_CONTINUOUS_PAGING = 0x00000001; 48 | public static final int MORE_CONTINUOUS_PAGES = 0x00000002; 49 | } 50 | 51 | public static class ErrorCode { 52 | public static final int CLIENT_WRITE_FAILURE = 0x8000; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/datastax/dse/protocol/internal/ProtocolV4ClientCodecsForDse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright DataStax, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.datastax.dse.protocol.internal; 17 | 18 | import com.datastax.dse.protocol.internal.request.DseQueryCodecV4; 19 | import com.datastax.dse.protocol.internal.request.RawBytesQuery; 20 | import com.datastax.oss.protocol.internal.FrameCodec; 21 | import com.datastax.oss.protocol.internal.ProtocolConstants; 22 | import com.datastax.oss.protocol.internal.request.AuthResponse; 23 | import com.datastax.oss.protocol.internal.request.Batch; 24 | import com.datastax.oss.protocol.internal.request.Execute; 25 | import com.datastax.oss.protocol.internal.request.Options; 26 | import com.datastax.oss.protocol.internal.request.Prepare; 27 | import com.datastax.oss.protocol.internal.request.Register; 28 | import com.datastax.oss.protocol.internal.request.Startup; 29 | import com.datastax.oss.protocol.internal.response.AuthChallenge; 30 | import com.datastax.oss.protocol.internal.response.AuthSuccess; 31 | import com.datastax.oss.protocol.internal.response.Authenticate; 32 | import com.datastax.oss.protocol.internal.response.Error; 33 | import com.datastax.oss.protocol.internal.response.Event; 34 | import com.datastax.oss.protocol.internal.response.Ready; 35 | import com.datastax.oss.protocol.internal.response.Result; 36 | import com.datastax.oss.protocol.internal.response.Supported; 37 | 38 | /** 39 | * DSE 5.0 still uses an OSS protocol version (V4), but we need to support {@link RawBytesQuery} for 40 | * fluent graph statements. 41 | * 42 | * @see DseQueryCodecV4 43 | */ 44 | public class ProtocolV4ClientCodecsForDse implements FrameCodec.CodecGroup { 45 | @Override 46 | public void registerCodecs(Registry registry) { 47 | registry 48 | .addEncoder(new AuthResponse.Codec(ProtocolConstants.Version.V4)) 49 | .addEncoder(new Batch.Codec(ProtocolConstants.Version.V4)) 50 | .addEncoder(new Execute.Codec(ProtocolConstants.Version.V4)) 51 | .addEncoder(new Options.Codec(ProtocolConstants.Version.V4)) 52 | .addEncoder(new Prepare.Codec(ProtocolConstants.Version.V4)) 53 | .addEncoder(new DseQueryCodecV4(ProtocolConstants.Version.V4)) 54 | .addEncoder(new Register.Codec(ProtocolConstants.Version.V4)) 55 | .addEncoder(new Startup.Codec(ProtocolConstants.Version.V4)); 56 | 57 | registry 58 | .addDecoder(new AuthChallenge.Codec(ProtocolConstants.Version.V4)) 59 | .addDecoder(new Authenticate.Codec(ProtocolConstants.Version.V4)) 60 | .addDecoder(new AuthSuccess.Codec(ProtocolConstants.Version.V4)) 61 | .addDecoder(new Error.Codec(ProtocolConstants.Version.V4)) 62 | .addDecoder(new Event.Codec(ProtocolConstants.Version.V4)) 63 | .addDecoder(new Ready.Codec(ProtocolConstants.Version.V4)) 64 | .addDecoder(new Result.Codec(ProtocolConstants.Version.V4)) 65 | .addDecoder(new Supported.Codec(ProtocolConstants.Version.V4)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/datastax/dse/protocol/internal/request/DseExecuteCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright DataStax, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.datastax.dse.protocol.internal.request; 17 | 18 | import static com.datastax.dse.protocol.internal.DseProtocolConstants.Version.DSE_V2; 19 | 20 | import com.datastax.dse.protocol.internal.DseProtocolConstants; 21 | import com.datastax.dse.protocol.internal.request.query.DseQueryOptionsCodec; 22 | import com.datastax.oss.protocol.internal.Message; 23 | import com.datastax.oss.protocol.internal.PrimitiveCodec; 24 | import com.datastax.oss.protocol.internal.PrimitiveSizes; 25 | import com.datastax.oss.protocol.internal.ProtocolConstants; 26 | import com.datastax.oss.protocol.internal.request.Execute; 27 | import com.datastax.oss.protocol.internal.request.query.QueryOptions; 28 | 29 | public class DseExecuteCodec extends Message.Codec { 30 | 31 | private final QueryOptions.Codec optionsCodec; 32 | 33 | public DseExecuteCodec(int protocolVersion) { 34 | super(ProtocolConstants.Opcode.EXECUTE, protocolVersion); 35 | assert protocolVersion >= DseProtocolConstants.Version.DSE_V1; 36 | this.optionsCodec = new DseQueryOptionsCodec(protocolVersion); 37 | } 38 | 39 | @Override 40 | public void encode(B dest, Message message, PrimitiveCodec encoder) { 41 | Execute execute = (Execute) message; 42 | encoder.writeShortBytes(execute.queryId, dest); 43 | if (protocolVersion >= DSE_V2) { 44 | encoder.writeShortBytes(execute.resultMetadataId, dest); 45 | } 46 | optionsCodec.encode(dest, execute.options, encoder); 47 | } 48 | 49 | @Override 50 | public int encodedSize(Message message) { 51 | Execute execute = (Execute) message; 52 | int size = PrimitiveSizes.sizeOfShortBytes(execute.queryId); 53 | if (protocolVersion >= DSE_V2) { 54 | assert execute.resultMetadataId != null; 55 | size += PrimitiveSizes.sizeOfShortBytes(execute.resultMetadataId); 56 | } 57 | size += optionsCodec.encodedSize(execute.options); 58 | return size; 59 | } 60 | 61 | @Override 62 | public Message decode(B source, PrimitiveCodec decoder) { 63 | byte[] queryId = decoder.readShortBytes(source); 64 | byte[] resultMetadataId = (protocolVersion >= DSE_V2) ? decoder.readShortBytes(source) : null; 65 | QueryOptions options = optionsCodec.decode(source, decoder); 66 | return new Execute(queryId, resultMetadataId, options); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/datastax/dse/protocol/internal/request/DsePrepareCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright DataStax, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.datastax.dse.protocol.internal.request; 17 | 18 | import static com.datastax.dse.protocol.internal.DseProtocolConstants.Version.DSE_V1; 19 | import static com.datastax.dse.protocol.internal.DseProtocolConstants.Version.DSE_V2; 20 | 21 | import com.datastax.oss.protocol.internal.Message; 22 | import com.datastax.oss.protocol.internal.PrimitiveCodec; 23 | import com.datastax.oss.protocol.internal.PrimitiveSizes; 24 | import com.datastax.oss.protocol.internal.ProtocolConstants; 25 | import com.datastax.oss.protocol.internal.request.Prepare; 26 | 27 | public class DsePrepareCodec extends Message.Codec { 28 | 29 | public DsePrepareCodec(int protocolVersion) { 30 | super(ProtocolConstants.Opcode.PREPARE, protocolVersion); 31 | assert protocolVersion >= DSE_V1; 32 | } 33 | 34 | @Override 35 | public void encode(B dest, Message message, PrimitiveCodec encoder) { 36 | Prepare prepare = (Prepare) message; 37 | encoder.writeLongString(prepare.cqlQuery, dest); 38 | if (protocolVersion >= DSE_V2) { 39 | // There is only one PREPARE flag for now, so hard-code for simplicity: 40 | encoder.writeInt((prepare.keyspace == null) ? 0x00 : 0x01, dest); 41 | if (prepare.keyspace != null) { 42 | encoder.writeString(prepare.keyspace, dest); 43 | } 44 | } 45 | } 46 | 47 | @Override 48 | public int encodedSize(Message message) { 49 | Prepare prepare = (Prepare) message; 50 | int size = PrimitiveSizes.sizeOfLongString(prepare.cqlQuery); 51 | if (protocolVersion >= DSE_V2) { 52 | size += PrimitiveSizes.INT; // flags 53 | if (prepare.keyspace != null) { 54 | size += PrimitiveSizes.sizeOfString(prepare.keyspace); 55 | } 56 | } 57 | return size; 58 | } 59 | 60 | @Override 61 | public Message decode(B source, PrimitiveCodec decoder) { 62 | String cqlQuery = decoder.readLongString(source); 63 | String keyspace = null; 64 | if (protocolVersion >= DSE_V2) { 65 | int flags = decoder.readInt(source); 66 | if ((flags & 0x01) == 0x01) { 67 | keyspace = decoder.readString(source); 68 | } 69 | } 70 | return new Prepare(cqlQuery, keyspace); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/datastax/dse/protocol/internal/request/DseQueryCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright DataStax, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.datastax.dse.protocol.internal.request; 17 | 18 | import static com.datastax.dse.protocol.internal.DseProtocolConstants.Version.DSE_V1; 19 | 20 | import com.datastax.dse.protocol.internal.request.query.DseQueryOptions; 21 | import com.datastax.dse.protocol.internal.request.query.DseQueryOptionsCodec; 22 | import com.datastax.oss.protocol.internal.Message; 23 | import com.datastax.oss.protocol.internal.PrimitiveCodec; 24 | import com.datastax.oss.protocol.internal.PrimitiveSizes; 25 | import com.datastax.oss.protocol.internal.request.Query; 26 | 27 | /** 28 | * {@code QUERY} codec for DSE-specific native protocols (DSE 5.1 and above). 29 | * 30 | *
Similar to the OSS codec, but in addition to regular messages, it can encode {@link 31 | * RawBytesQuery} (for fluent graph statements), and the options can be a {@link DseQueryOptions}. 32 | * 33 | * @see DseQueryCodecV4 34 | */ 35 | public class DseQueryCodec extends Query.Codec { 36 | 37 | public DseQueryCodec(int protocolVersion) { 38 | super(protocolVersion, new DseQueryOptionsCodec(protocolVersion)); 39 | assert protocolVersion >= DSE_V1; 40 | } 41 | 42 | @Override 43 | public void encode(B dest, Message message, PrimitiveCodec encoder) { 44 | if (message instanceof RawBytesQuery) { 45 | RawBytesQuery query = (RawBytesQuery) message; 46 | encoder.writeBytes(query.query, dest); 47 | optionsCodec.encode(dest, query.options, encoder); 48 | } else { 49 | super.encode(dest, message, encoder); 50 | } 51 | } 52 | 53 | @Override 54 | public int encodedSize(Message message) { 55 | if (message instanceof RawBytesQuery) { 56 | RawBytesQuery query = (RawBytesQuery) message; 57 | return PrimitiveSizes.sizeOfBytes(query.query) + optionsCodec.encodedSize(query.options); 58 | } else { 59 | return super.encodedSize(message); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/datastax/dse/protocol/internal/request/DseQueryCodecV4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright DataStax, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.datastax.dse.protocol.internal.request; 17 | 18 | import com.datastax.oss.protocol.internal.Message; 19 | import com.datastax.oss.protocol.internal.PrimitiveCodec; 20 | import com.datastax.oss.protocol.internal.PrimitiveSizes; 21 | import com.datastax.oss.protocol.internal.ProtocolConstants; 22 | import com.datastax.oss.protocol.internal.request.Query; 23 | import com.datastax.oss.protocol.internal.request.query.QueryOptions; 24 | 25 | /** 26 | * {@code QUERY} codec for native protocol V4 (DSE 5.0). 27 | * 28 | *
Similar to the OSS codec, but in addition to regular messages, it can encode {@link 29 | * RawBytesQuery} (for fluent graph statements). However, queries still uses a standard OSS {@link 30 | * QueryOptions}. 31 | * 32 | * @see DseQueryCodec 33 | */ 34 | public class DseQueryCodecV4 extends Query.Codec { 35 | 36 | public DseQueryCodecV4(int protocolVersion) { 37 | super(protocolVersion, new QueryOptions.Codec(protocolVersion)); 38 | assert protocolVersion == ProtocolConstants.Version.V4; 39 | } 40 | 41 | @Override 42 | public void encode(B dest, Message message, PrimitiveCodec encoder) { 43 | if (message instanceof RawBytesQuery) { 44 | RawBytesQuery query = (RawBytesQuery) message; 45 | encoder.writeBytes(query.query, dest); 46 | optionsCodec.encode(dest, query.options, encoder); 47 | } else { 48 | super.encode(dest, message, encoder); 49 | } 50 | } 51 | 52 | @Override 53 | public int encodedSize(Message message) { 54 | if (message instanceof RawBytesQuery) { 55 | RawBytesQuery query = (RawBytesQuery) message; 56 | return PrimitiveSizes.sizeOfBytes(query.query) + optionsCodec.encodedSize(query.options); 57 | } else { 58 | return super.encodedSize(message); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/datastax/dse/protocol/internal/request/RawBytesQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright DataStax, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.datastax.dse.protocol.internal.request; 17 | 18 | import com.datastax.dse.protocol.internal.request.query.DseQueryOptions; 19 | import com.datastax.oss.protocol.internal.Message; 20 | import com.datastax.oss.protocol.internal.ProtocolConstants; 21 | import com.datastax.oss.protocol.internal.util.Bytes; 22 | 23 | /** 24 | * A specialized {@code QUERY} message where the query string is represented directly as a byte 25 | * array. 26 | * 27 | *
It is used to avoid materializing a string if the incoming query is already encoded (namely,
28 | * in DSE graph).
29 | */
30 | public class RawBytesQuery extends Message {
31 |
32 | public final byte[] query;
33 | public final DseQueryOptions options;
34 |
35 | public RawBytesQuery(byte[] query, DseQueryOptions options) {
36 | super(false, ProtocolConstants.Opcode.QUERY);
37 | this.query = query;
38 | this.options = options;
39 | }
40 |
41 | @Override
42 | public String toString() {
43 | return "QUERY (" + Bytes.toHexString(query) + ')';
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/dse/protocol/internal/request/Revise.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.dse.protocol.internal.request;
17 |
18 | import com.datastax.dse.protocol.internal.DseProtocolConstants;
19 | import com.datastax.oss.protocol.internal.Message;
20 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
21 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
22 |
23 | public class Revise extends Message {
24 |
25 | public static Revise cancelContinuousPaging(int streamId) {
26 | return new Revise(DseProtocolConstants.RevisionType.CANCEL_CONTINUOUS_PAGING, streamId, -1);
27 | }
28 |
29 | public static Revise requestMoreContinuousPages(int streamId, int amount) {
30 | return new Revise(DseProtocolConstants.RevisionType.MORE_CONTINUOUS_PAGES, streamId, amount);
31 | }
32 |
33 | /** @see DseProtocolConstants.RevisionType */
34 | public final int revisionType;
35 |
36 | public final int streamId;
37 | public final int nextPages;
38 |
39 | public Revise(int revisionType, int streamId, int nextPages) {
40 | super(false, DseProtocolConstants.Opcode.REVISE_REQUEST);
41 | this.revisionType = revisionType;
42 | this.streamId = streamId;
43 | this.nextPages = nextPages;
44 | }
45 |
46 | public static class Codec extends Message.Codec {
47 |
48 | public Codec(int protocolVersion) {
49 | super(DseProtocolConstants.Opcode.REVISE_REQUEST, protocolVersion);
50 | }
51 |
52 | @Override
53 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
54 | Revise revise = (Revise) message;
55 | encoder.writeInt(revise.revisionType, dest);
56 | encoder.writeInt(revise.streamId, dest);
57 | if (revise.revisionType == DseProtocolConstants.RevisionType.MORE_CONTINUOUS_PAGES) {
58 | encoder.writeInt(revise.nextPages, dest);
59 | }
60 | }
61 |
62 | @Override
63 | public int encodedSize(Message message) {
64 | Revise revise = (Revise) message;
65 | return PrimitiveSizes.INT
66 | * (revise.revisionType == DseProtocolConstants.RevisionType.MORE_CONTINUOUS_PAGES
67 | ? 3
68 | : 2);
69 | }
70 |
71 | @Override
72 | public Message decode(B source, PrimitiveCodec decoder) {
73 | int revisionType = decoder.readInt(source);
74 | int streamId = decoder.readInt(source);
75 | int nextPages =
76 | (revisionType == DseProtocolConstants.RevisionType.MORE_CONTINUOUS_PAGES)
77 | ? decoder.readInt(source)
78 | : -1;
79 | return new Revise(revisionType, streamId, nextPages);
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/dse/protocol/internal/request/query/ContinuousPagingOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.dse.protocol.internal.request.query;
17 |
18 | public class ContinuousPagingOptions {
19 |
20 | public final int maxPages;
21 | public final int pagesPerSecond;
22 | public final int nextPages;
23 |
24 | public ContinuousPagingOptions(int maxPages, int pagesPerSecond, int nextPages) {
25 | this.maxPages = maxPages;
26 | this.pagesPerSecond = pagesPerSecond;
27 | this.nextPages = nextPages;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/dse/protocol/internal/response/result/DsePreparedSubCodec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.dse.protocol.internal.response.result;
17 |
18 | import static com.datastax.dse.protocol.internal.DseProtocolConstants.Version.DSE_V1;
19 | import static com.datastax.dse.protocol.internal.DseProtocolConstants.Version.DSE_V2;
20 |
21 | import com.datastax.oss.protocol.internal.Message;
22 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
23 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
24 | import com.datastax.oss.protocol.internal.ProtocolConstants;
25 | import com.datastax.oss.protocol.internal.response.Result;
26 | import com.datastax.oss.protocol.internal.response.result.Prepared;
27 | import com.datastax.oss.protocol.internal.response.result.RowsMetadata;
28 |
29 | public class DsePreparedSubCodec extends Result.SubCodec {
30 |
31 | public DsePreparedSubCodec(int protocolVersion) {
32 | super(ProtocolConstants.ResultKind.PREPARED, protocolVersion);
33 | assert protocolVersion >= DSE_V1;
34 | }
35 |
36 | @Override
37 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
38 | Prepared prepared = (Prepared) message;
39 | encoder.writeShortBytes(prepared.preparedQueryId, dest);
40 | if (protocolVersion >= DSE_V2) {
41 | encoder.writeShortBytes(prepared.resultMetadataId, dest);
42 | }
43 | prepared.variablesMetadata.encode(dest, encoder, true, protocolVersion);
44 | prepared.resultMetadata.encode(dest, encoder, false, protocolVersion);
45 | }
46 |
47 | @Override
48 | public int encodedSize(Message message) {
49 | Prepared prepared = (Prepared) message;
50 | int size = PrimitiveSizes.sizeOfShortBytes(prepared.preparedQueryId);
51 | if (protocolVersion >= DSE_V2) {
52 | assert prepared.resultMetadataId != null;
53 | size += PrimitiveSizes.sizeOfShortBytes(prepared.resultMetadataId);
54 | }
55 | size += prepared.variablesMetadata.encodedSize(true, protocolVersion);
56 | size += prepared.resultMetadata.encodedSize(false, protocolVersion);
57 | return size;
58 | }
59 |
60 | @Override
61 | public Message decode(B source, PrimitiveCodec decoder) {
62 | byte[] preparedQueryId = decoder.readShortBytes(source);
63 | byte[] resultMetadataId = (protocolVersion >= DSE_V2) ? decoder.readShortBytes(source) : null;
64 | RowsMetadata variablesMetadata = RowsMetadata.decode(source, decoder, true, protocolVersion);
65 | RowsMetadata resultMetadata = RowsMetadata.decode(source, decoder, false, protocolVersion);
66 | return new Prepared(preparedQueryId, resultMetadataId, variablesMetadata, resultMetadata);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/dse/protocol/internal/response/result/DseRowsSubCodec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.dse.protocol.internal.response.result;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.response.result.DefaultRows;
21 | import java.nio.ByteBuffer;
22 | import java.util.ArrayDeque;
23 | import java.util.ArrayList;
24 | import java.util.List;
25 | import java.util.Queue;
26 |
27 | public class DseRowsSubCodec extends DefaultRows.SubCodec {
28 |
29 | public DseRowsSubCodec(int protocolVersion) {
30 | super(protocolVersion);
31 | }
32 |
33 | // No need to override `encode` and `encodedSize`, if the metadata is a DseRowsMetadata it knows
34 | // how to encode itself.
35 |
36 | @Override
37 | public Message decode(B source, PrimitiveCodec decoder) {
38 | DseRowsMetadata metadata = DseRowsMetadata.decode(source, decoder, false, protocolVersion);
39 | int rowCount = decoder.readInt(source);
40 |
41 | Queue It's the string that will be used in the {@code STARTUP} message. Null or empty means no
28 | * compression.
29 | */
30 | String algorithm();
31 |
32 | /**
33 | * Compresses a payload using the "legacy" format of protocol v4- frame bodies.
34 | *
35 | * The resulting payload encodes the uncompressed length, and is therefore self-sufficient for
36 | * decompression.
37 | */
38 | B compress(B uncompressed);
39 |
40 | /** Decompresses a payload that was compressed with {@link #compress(Object)}. */
41 | B decompress(B compressed);
42 |
43 | /**
44 | * Compresses a payload using the "modern" format of protocol v5+ segments.
45 | *
46 | * The resulting payload does not encode the uncompressed length. It must be stored separately,
47 | * and provided to the decompression method.
48 | */
49 | B compressWithoutLength(B uncompressed);
50 |
51 | /** Decompresses a payload that was compressed with {@link #compressWithoutLength(Object)}. */
52 | B decompressWithoutLength(B compressed, int uncompressedLength);
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/CrcMismatchException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | /** Thrown when the checksums in an incoming {@link Segment} don't match (protocol v5 or above). */
19 | public class CrcMismatchException extends Exception {
20 |
21 | private static final long serialVersionUID = 0;
22 |
23 | public CrcMismatchException(String message) {
24 | super(message);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/Message.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | public abstract class Message {
19 | public final boolean isResponse;
20 |
21 | /** @see ProtocolConstants.Opcode */
22 | public final int opcode;
23 |
24 | protected Message(boolean isResponse, int opcode) {
25 | this.isResponse = isResponse;
26 | this.opcode = opcode;
27 | }
28 |
29 | public abstract static class Codec {
30 | /** @see ProtocolConstants.Opcode */
31 | public final int opcode;
32 | /** @see ProtocolConstants.Version */
33 | public final int protocolVersion;
34 |
35 | protected Codec(int opcode, int protocolVersion) {
36 | this.opcode = opcode;
37 | this.protocolVersion = protocolVersion;
38 | }
39 |
40 | public abstract void encode(B dest, Message message, PrimitiveCodec encoder);
41 |
42 | public abstract int encodedSize(Message message);
43 |
44 | public abstract Message decode(B source, PrimitiveCodec decoder);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/NoopCompressor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | public class NoopCompressor implements Compressor {
19 |
20 | @Override
21 | public String algorithm() {
22 | return null;
23 | }
24 |
25 | @Override
26 | public B compress(B uncompressed) {
27 | return uncompressed;
28 | }
29 |
30 | @Override
31 | public B decompress(B compressed) {
32 | return compressed;
33 | }
34 |
35 | @Override
36 | public B compressWithoutLength(B uncompressed) {
37 | return uncompressed;
38 | }
39 |
40 | @Override
41 | public B decompressWithoutLength(B compressed, int uncompressedLength) {
42 | return compressed;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/ProtocolErrors.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | /**
19 | * Errors thrown when a message to (de)serialize doesn't respect the protocol spec.
20 | *
21 | * Clients are supposed to passed well-formed messages, so these are IllegalArgumentExceptions
22 | * indicating a programming error.
23 | */
24 | public class ProtocolErrors {
25 | public static void check(boolean condition, String errorWhenFalse, Object... arguments) {
26 | if (!condition) {
27 | throw new IllegalArgumentException(String.format(errorWhenFalse, arguments));
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/ProtocolV3ClientCodecs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | import com.datastax.oss.protocol.internal.request.AuthResponse;
19 | import com.datastax.oss.protocol.internal.request.Batch;
20 | import com.datastax.oss.protocol.internal.request.Execute;
21 | import com.datastax.oss.protocol.internal.request.Options;
22 | import com.datastax.oss.protocol.internal.request.Prepare;
23 | import com.datastax.oss.protocol.internal.request.Query;
24 | import com.datastax.oss.protocol.internal.request.Register;
25 | import com.datastax.oss.protocol.internal.request.Startup;
26 | import com.datastax.oss.protocol.internal.response.AuthChallenge;
27 | import com.datastax.oss.protocol.internal.response.AuthSuccess;
28 | import com.datastax.oss.protocol.internal.response.Authenticate;
29 | import com.datastax.oss.protocol.internal.response.Error;
30 | import com.datastax.oss.protocol.internal.response.Event;
31 | import com.datastax.oss.protocol.internal.response.Ready;
32 | import com.datastax.oss.protocol.internal.response.Result;
33 | import com.datastax.oss.protocol.internal.response.Supported;
34 |
35 | public class ProtocolV3ClientCodecs implements FrameCodec.CodecGroup {
36 | @Override
37 | public void registerCodecs(Registry registry) {
38 | registry
39 | .addEncoder(new AuthResponse.Codec(ProtocolConstants.Version.V3))
40 | .addEncoder(new Batch.Codec(ProtocolConstants.Version.V3))
41 | .addEncoder(new Execute.Codec(ProtocolConstants.Version.V3))
42 | .addEncoder(new Options.Codec(ProtocolConstants.Version.V3))
43 | .addEncoder(new Prepare.Codec(ProtocolConstants.Version.V3))
44 | .addEncoder(new Query.Codec(ProtocolConstants.Version.V3))
45 | .addEncoder(new Register.Codec(ProtocolConstants.Version.V3))
46 | .addEncoder(new Startup.Codec(ProtocolConstants.Version.V3));
47 |
48 | registry
49 | .addDecoder(new AuthChallenge.Codec(ProtocolConstants.Version.V3))
50 | .addDecoder(new Authenticate.Codec(ProtocolConstants.Version.V3))
51 | .addDecoder(new AuthSuccess.Codec(ProtocolConstants.Version.V3))
52 | .addDecoder(new Error.Codec(ProtocolConstants.Version.V3))
53 | .addDecoder(new Event.Codec(ProtocolConstants.Version.V3))
54 | .addDecoder(new Ready.Codec(ProtocolConstants.Version.V3))
55 | .addDecoder(new Result.Codec(ProtocolConstants.Version.V3))
56 | .addDecoder(new Supported.Codec(ProtocolConstants.Version.V3));
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/ProtocolV3ServerCodecs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | import com.datastax.oss.protocol.internal.request.AuthResponse;
19 | import com.datastax.oss.protocol.internal.request.Batch;
20 | import com.datastax.oss.protocol.internal.request.Execute;
21 | import com.datastax.oss.protocol.internal.request.Options;
22 | import com.datastax.oss.protocol.internal.request.Prepare;
23 | import com.datastax.oss.protocol.internal.request.Query;
24 | import com.datastax.oss.protocol.internal.request.Register;
25 | import com.datastax.oss.protocol.internal.request.Startup;
26 | import com.datastax.oss.protocol.internal.response.AuthChallenge;
27 | import com.datastax.oss.protocol.internal.response.AuthSuccess;
28 | import com.datastax.oss.protocol.internal.response.Authenticate;
29 | import com.datastax.oss.protocol.internal.response.Error;
30 | import com.datastax.oss.protocol.internal.response.Event;
31 | import com.datastax.oss.protocol.internal.response.Ready;
32 | import com.datastax.oss.protocol.internal.response.Result;
33 | import com.datastax.oss.protocol.internal.response.Supported;
34 |
35 | public class ProtocolV3ServerCodecs implements FrameCodec.CodecGroup {
36 | @Override
37 | public void registerCodecs(Registry registry) {
38 | registry
39 | .addDecoder(new AuthResponse.Codec(ProtocolConstants.Version.V3))
40 | .addDecoder(new Batch.Codec(ProtocolConstants.Version.V3))
41 | .addDecoder(new Execute.Codec(ProtocolConstants.Version.V3))
42 | .addDecoder(new Options.Codec(ProtocolConstants.Version.V3))
43 | .addDecoder(new Prepare.Codec(ProtocolConstants.Version.V3))
44 | .addDecoder(new Query.Codec(ProtocolConstants.Version.V3))
45 | .addDecoder(new Register.Codec(ProtocolConstants.Version.V3))
46 | .addDecoder(new Startup.Codec(ProtocolConstants.Version.V3));
47 |
48 | registry
49 | .addEncoder(new AuthChallenge.Codec(ProtocolConstants.Version.V3))
50 | .addEncoder(new Authenticate.Codec(ProtocolConstants.Version.V3))
51 | .addEncoder(new AuthSuccess.Codec(ProtocolConstants.Version.V3))
52 | .addEncoder(new Error.Codec(ProtocolConstants.Version.V3))
53 | .addEncoder(new Event.Codec(ProtocolConstants.Version.V3))
54 | .addEncoder(new Ready.Codec(ProtocolConstants.Version.V3))
55 | .addEncoder(new Result.Codec(ProtocolConstants.Version.V3))
56 | .addEncoder(new Supported.Codec(ProtocolConstants.Version.V3));
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/ProtocolV4ClientCodecs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | import com.datastax.oss.protocol.internal.request.AuthResponse;
19 | import com.datastax.oss.protocol.internal.request.Batch;
20 | import com.datastax.oss.protocol.internal.request.Execute;
21 | import com.datastax.oss.protocol.internal.request.Options;
22 | import com.datastax.oss.protocol.internal.request.Prepare;
23 | import com.datastax.oss.protocol.internal.request.Query;
24 | import com.datastax.oss.protocol.internal.request.Register;
25 | import com.datastax.oss.protocol.internal.request.Startup;
26 | import com.datastax.oss.protocol.internal.response.AuthChallenge;
27 | import com.datastax.oss.protocol.internal.response.AuthSuccess;
28 | import com.datastax.oss.protocol.internal.response.Authenticate;
29 | import com.datastax.oss.protocol.internal.response.Error;
30 | import com.datastax.oss.protocol.internal.response.Event;
31 | import com.datastax.oss.protocol.internal.response.Ready;
32 | import com.datastax.oss.protocol.internal.response.Result;
33 | import com.datastax.oss.protocol.internal.response.Supported;
34 |
35 | public class ProtocolV4ClientCodecs implements FrameCodec.CodecGroup {
36 | @Override
37 | public void registerCodecs(Registry registry) {
38 | registry
39 | .addEncoder(new AuthResponse.Codec(ProtocolConstants.Version.V4))
40 | .addEncoder(new Batch.Codec(ProtocolConstants.Version.V4))
41 | .addEncoder(new Execute.Codec(ProtocolConstants.Version.V4))
42 | .addEncoder(new Options.Codec(ProtocolConstants.Version.V4))
43 | .addEncoder(new Prepare.Codec(ProtocolConstants.Version.V4))
44 | .addEncoder(new Query.Codec(ProtocolConstants.Version.V4))
45 | .addEncoder(new Register.Codec(ProtocolConstants.Version.V4))
46 | .addEncoder(new Startup.Codec(ProtocolConstants.Version.V4));
47 |
48 | registry
49 | .addDecoder(new AuthChallenge.Codec(ProtocolConstants.Version.V4))
50 | .addDecoder(new Authenticate.Codec(ProtocolConstants.Version.V4))
51 | .addDecoder(new AuthSuccess.Codec(ProtocolConstants.Version.V4))
52 | .addDecoder(new Error.Codec(ProtocolConstants.Version.V4))
53 | .addDecoder(new Event.Codec(ProtocolConstants.Version.V4))
54 | .addDecoder(new Ready.Codec(ProtocolConstants.Version.V4))
55 | .addDecoder(new Result.Codec(ProtocolConstants.Version.V4))
56 | .addDecoder(new Supported.Codec(ProtocolConstants.Version.V4));
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/ProtocolV4ServerCodecs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | import static com.datastax.oss.protocol.internal.ProtocolConstants.Version.V4;
19 |
20 | import com.datastax.oss.protocol.internal.request.AuthResponse;
21 | import com.datastax.oss.protocol.internal.request.Batch;
22 | import com.datastax.oss.protocol.internal.request.Execute;
23 | import com.datastax.oss.protocol.internal.request.Options;
24 | import com.datastax.oss.protocol.internal.request.Prepare;
25 | import com.datastax.oss.protocol.internal.request.Query;
26 | import com.datastax.oss.protocol.internal.request.Register;
27 | import com.datastax.oss.protocol.internal.request.Startup;
28 | import com.datastax.oss.protocol.internal.response.AuthChallenge;
29 | import com.datastax.oss.protocol.internal.response.AuthSuccess;
30 | import com.datastax.oss.protocol.internal.response.Authenticate;
31 | import com.datastax.oss.protocol.internal.response.Error;
32 | import com.datastax.oss.protocol.internal.response.Event;
33 | import com.datastax.oss.protocol.internal.response.Ready;
34 | import com.datastax.oss.protocol.internal.response.Result;
35 | import com.datastax.oss.protocol.internal.response.Supported;
36 |
37 | public class ProtocolV4ServerCodecs implements FrameCodec.CodecGroup {
38 | @Override
39 | public void registerCodecs(Registry registry) {
40 | registry
41 | .addDecoder(new AuthResponse.Codec(V4))
42 | .addDecoder(new Batch.Codec(V4))
43 | .addDecoder(new Execute.Codec(V4))
44 | .addDecoder(new Options.Codec(V4))
45 | .addDecoder(new Prepare.Codec(V4))
46 | .addDecoder(new Query.Codec(V4))
47 | .addDecoder(new Register.Codec(V4))
48 | .addDecoder(new Startup.Codec(V4));
49 |
50 | registry
51 | .addEncoder(new AuthChallenge.Codec(V4))
52 | .addEncoder(new Authenticate.Codec(V4))
53 | .addEncoder(new AuthSuccess.Codec(V4))
54 | .addEncoder(new Error.Codec(V4))
55 | .addEncoder(new Event.Codec(V4))
56 | .addEncoder(new Ready.Codec(V4))
57 | .addEncoder(new Result.Codec(V4))
58 | .addEncoder(new Supported.Codec(V4));
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/ProtocolV5ClientCodecs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | import static com.datastax.oss.protocol.internal.ProtocolConstants.Version.V5;
19 |
20 | import com.datastax.oss.protocol.internal.request.AuthResponse;
21 | import com.datastax.oss.protocol.internal.request.Batch;
22 | import com.datastax.oss.protocol.internal.request.Execute;
23 | import com.datastax.oss.protocol.internal.request.Options;
24 | import com.datastax.oss.protocol.internal.request.Prepare;
25 | import com.datastax.oss.protocol.internal.request.Query;
26 | import com.datastax.oss.protocol.internal.request.Register;
27 | import com.datastax.oss.protocol.internal.request.Startup;
28 | import com.datastax.oss.protocol.internal.response.AuthChallenge;
29 | import com.datastax.oss.protocol.internal.response.AuthSuccess;
30 | import com.datastax.oss.protocol.internal.response.Authenticate;
31 | import com.datastax.oss.protocol.internal.response.Error;
32 | import com.datastax.oss.protocol.internal.response.Event;
33 | import com.datastax.oss.protocol.internal.response.Ready;
34 | import com.datastax.oss.protocol.internal.response.Result;
35 | import com.datastax.oss.protocol.internal.response.Supported;
36 |
37 | public class ProtocolV5ClientCodecs implements FrameCodec.CodecGroup {
38 | @Override
39 | public void registerCodecs(Registry registry) {
40 | registry
41 | .addEncoder(new AuthResponse.Codec(V5))
42 | .addEncoder(new Batch.Codec(V5))
43 | .addEncoder(new Execute.Codec(V5))
44 | .addEncoder(new Options.Codec(V5))
45 | .addEncoder(new Prepare.Codec(V5))
46 | .addEncoder(new Query.Codec(V5))
47 | .addEncoder(new Register.Codec(V5))
48 | .addEncoder(new Startup.Codec(V5));
49 |
50 | registry
51 | .addDecoder(new AuthChallenge.Codec(V5))
52 | .addDecoder(new Authenticate.Codec(V5))
53 | .addDecoder(new AuthSuccess.Codec(V5))
54 | .addDecoder(new Error.Codec(V5))
55 | .addDecoder(new Event.Codec(V5))
56 | .addDecoder(new Ready.Codec(V5))
57 | .addDecoder(new Result.Codec(V5))
58 | .addDecoder(new Supported.Codec(V5));
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/ProtocolV5ServerCodecs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | import com.datastax.oss.protocol.internal.request.AuthResponse;
19 | import com.datastax.oss.protocol.internal.request.Batch;
20 | import com.datastax.oss.protocol.internal.request.Execute;
21 | import com.datastax.oss.protocol.internal.request.Options;
22 | import com.datastax.oss.protocol.internal.request.Prepare;
23 | import com.datastax.oss.protocol.internal.request.Query;
24 | import com.datastax.oss.protocol.internal.request.Register;
25 | import com.datastax.oss.protocol.internal.request.Startup;
26 | import com.datastax.oss.protocol.internal.response.AuthChallenge;
27 | import com.datastax.oss.protocol.internal.response.AuthSuccess;
28 | import com.datastax.oss.protocol.internal.response.Authenticate;
29 | import com.datastax.oss.protocol.internal.response.Error;
30 | import com.datastax.oss.protocol.internal.response.Event;
31 | import com.datastax.oss.protocol.internal.response.Ready;
32 | import com.datastax.oss.protocol.internal.response.Result;
33 | import com.datastax.oss.protocol.internal.response.Supported;
34 |
35 | public class ProtocolV5ServerCodecs implements FrameCodec.CodecGroup {
36 | @Override
37 | public void registerCodecs(Registry registry) {
38 | registry
39 | .addDecoder(new AuthResponse.Codec(ProtocolConstants.Version.V5))
40 | .addDecoder(new Batch.Codec(ProtocolConstants.Version.V5))
41 | .addDecoder(new Execute.Codec(ProtocolConstants.Version.V5))
42 | .addDecoder(new Options.Codec(ProtocolConstants.Version.V5))
43 | .addDecoder(new Prepare.Codec(ProtocolConstants.Version.V5))
44 | .addDecoder(new Query.Codec(ProtocolConstants.Version.V5))
45 | .addDecoder(new Register.Codec(ProtocolConstants.Version.V5))
46 | .addDecoder(new Startup.Codec(ProtocolConstants.Version.V5));
47 |
48 | registry
49 | .addEncoder(new AuthChallenge.Codec(ProtocolConstants.Version.V5))
50 | .addEncoder(new Authenticate.Codec(ProtocolConstants.Version.V5))
51 | .addEncoder(new AuthSuccess.Codec(ProtocolConstants.Version.V5))
52 | .addEncoder(new Error.Codec(ProtocolConstants.Version.V5))
53 | .addEncoder(new Event.Codec(ProtocolConstants.Version.V5))
54 | .addEncoder(new Ready.Codec(ProtocolConstants.Version.V5))
55 | .addEncoder(new Result.Codec(ProtocolConstants.Version.V5))
56 | .addEncoder(new Supported.Codec(ProtocolConstants.Version.V5));
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/ProtocolV6ClientCodecs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | import static com.datastax.oss.protocol.internal.ProtocolConstants.Version.V6;
19 |
20 | import com.datastax.oss.protocol.internal.request.AuthResponse;
21 | import com.datastax.oss.protocol.internal.request.Batch;
22 | import com.datastax.oss.protocol.internal.request.Execute;
23 | import com.datastax.oss.protocol.internal.request.Options;
24 | import com.datastax.oss.protocol.internal.request.Prepare;
25 | import com.datastax.oss.protocol.internal.request.Query;
26 | import com.datastax.oss.protocol.internal.request.Register;
27 | import com.datastax.oss.protocol.internal.request.Startup;
28 | import com.datastax.oss.protocol.internal.response.AuthChallenge;
29 | import com.datastax.oss.protocol.internal.response.AuthSuccess;
30 | import com.datastax.oss.protocol.internal.response.Authenticate;
31 | import com.datastax.oss.protocol.internal.response.Error;
32 | import com.datastax.oss.protocol.internal.response.Event;
33 | import com.datastax.oss.protocol.internal.response.Ready;
34 | import com.datastax.oss.protocol.internal.response.Result;
35 | import com.datastax.oss.protocol.internal.response.Supported;
36 |
37 | public class ProtocolV6ClientCodecs implements FrameCodec.CodecGroup {
38 | @Override
39 | public void registerCodecs(Registry registry) {
40 | registry
41 | .addEncoder(new AuthResponse.Codec(V6))
42 | .addEncoder(new Batch.Codec(V6))
43 | .addEncoder(new Execute.Codec(V6))
44 | .addEncoder(new Options.Codec(V6))
45 | .addEncoder(new Prepare.Codec(V6))
46 | .addEncoder(new Query.Codec(V6))
47 | .addEncoder(new Register.Codec(V6))
48 | .addEncoder(new Startup.Codec(V6));
49 |
50 | registry
51 | .addDecoder(new AuthChallenge.Codec(V6))
52 | .addDecoder(new Authenticate.Codec(V6))
53 | .addDecoder(new AuthSuccess.Codec(V6))
54 | .addDecoder(new Error.Codec(V6))
55 | .addDecoder(new Event.Codec(V6))
56 | .addDecoder(new Ready.Codec(V6))
57 | .addDecoder(new Result.Codec(V6))
58 | .addDecoder(new Supported.Codec(V6));
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/ProtocolV6ServerCodecs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | import com.datastax.oss.protocol.internal.request.AuthResponse;
19 | import com.datastax.oss.protocol.internal.request.Batch;
20 | import com.datastax.oss.protocol.internal.request.Execute;
21 | import com.datastax.oss.protocol.internal.request.Options;
22 | import com.datastax.oss.protocol.internal.request.Prepare;
23 | import com.datastax.oss.protocol.internal.request.Query;
24 | import com.datastax.oss.protocol.internal.request.Register;
25 | import com.datastax.oss.protocol.internal.request.Startup;
26 | import com.datastax.oss.protocol.internal.response.AuthChallenge;
27 | import com.datastax.oss.protocol.internal.response.AuthSuccess;
28 | import com.datastax.oss.protocol.internal.response.Authenticate;
29 | import com.datastax.oss.protocol.internal.response.Error;
30 | import com.datastax.oss.protocol.internal.response.Event;
31 | import com.datastax.oss.protocol.internal.response.Ready;
32 | import com.datastax.oss.protocol.internal.response.Result;
33 | import com.datastax.oss.protocol.internal.response.Supported;
34 |
35 | public class ProtocolV6ServerCodecs implements FrameCodec.CodecGroup {
36 | @Override
37 | public void registerCodecs(Registry registry) {
38 | registry
39 | .addDecoder(new AuthResponse.Codec(ProtocolConstants.Version.V6))
40 | .addDecoder(new Batch.Codec(ProtocolConstants.Version.V6))
41 | .addDecoder(new Execute.Codec(ProtocolConstants.Version.V6))
42 | .addDecoder(new Options.Codec(ProtocolConstants.Version.V6))
43 | .addDecoder(new Prepare.Codec(ProtocolConstants.Version.V6))
44 | .addDecoder(new Query.Codec(ProtocolConstants.Version.V6))
45 | .addDecoder(new Register.Codec(ProtocolConstants.Version.V6))
46 | .addDecoder(new Startup.Codec(ProtocolConstants.Version.V6));
47 |
48 | registry
49 | .addEncoder(new AuthChallenge.Codec(ProtocolConstants.Version.V6))
50 | .addEncoder(new Authenticate.Codec(ProtocolConstants.Version.V6))
51 | .addEncoder(new AuthSuccess.Codec(ProtocolConstants.Version.V6))
52 | .addEncoder(new Error.Codec(ProtocolConstants.Version.V6))
53 | .addEncoder(new Event.Codec(ProtocolConstants.Version.V6))
54 | .addEncoder(new Ready.Codec(ProtocolConstants.Version.V6))
55 | .addEncoder(new Result.Codec(ProtocolConstants.Version.V6))
56 | .addEncoder(new Supported.Codec(ProtocolConstants.Version.V6));
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/Segment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal;
17 |
18 | /**
19 | * A container of {@link Frame}s in protocol v5 and above. This is a new protocol construct that
20 | * allows checksumming and compressing multiple messages together.
21 | *
22 | * {@link #payload} contains either:
23 | *
24 | * Naming is provisional: it's possible that this type will be renamed to "frame", and {@link
35 | * Frame} to something else, at some point in the future (this is an ongoing discussion on the
36 | * server ticket).
37 | */
38 | public class Segment {
39 |
40 | public static int MAX_PAYLOAD_LENGTH = 128 * 1024 - 1;
41 |
42 | public final B payload;
43 | public final boolean isSelfContained;
44 |
45 | public Segment(B payload, boolean isSelfContained) {
46 | this.payload = payload;
47 | this.isSelfContained = isSelfContained;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/request/AuthResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.request;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
21 | import com.datastax.oss.protocol.internal.ProtocolConstants;
22 | import com.datastax.oss.protocol.internal.util.Bytes;
23 | import java.nio.ByteBuffer;
24 |
25 | /**
26 | * Note that, if the token is writable, the built-in codec will clear its contents
27 | * immediately after writing it (to avoid keeping sensitive information in memory). If you want to
28 | * reuse the same buffer across multiple message instances, make it {@linkplain
29 | * ByteBuffer#asReadOnlyBuffer() read-only}.
30 | */
31 | public class AuthResponse extends Message {
32 | public final ByteBuffer token;
33 |
34 | public AuthResponse(ByteBuffer token) {
35 | super(false, ProtocolConstants.Opcode.AUTH_RESPONSE);
36 | this.token = token;
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "AUTH_RESPONSE";
42 | }
43 |
44 | public static class Codec extends Message.Codec {
45 |
46 | public Codec(int protocolVersion) {
47 | super(ProtocolConstants.Opcode.AUTH_RESPONSE, protocolVersion);
48 | }
49 |
50 | @Override
51 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
52 | AuthResponse authResponse = (AuthResponse) message;
53 | ByteBuffer token = authResponse.token;
54 | if (token == null) {
55 | encoder.writeBytes(token, dest);
56 | } else {
57 | token.mark();
58 | encoder.writeBytes(token, dest);
59 | token.reset();
60 | Bytes.erase(token);
61 | }
62 | }
63 |
64 | @Override
65 | public int encodedSize(Message message) {
66 | AuthResponse authResponse = (AuthResponse) message;
67 | return PrimitiveSizes.sizeOfBytes(authResponse.token);
68 | }
69 |
70 | @Override
71 | public Message decode(B source, PrimitiveCodec decoder) {
72 | ByteBuffer token = decoder.readBytes(source);
73 | return new AuthResponse(token);
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/request/Execute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.request;
17 |
18 | import static com.datastax.oss.protocol.internal.ProtocolConstants.Version.V5;
19 |
20 | import com.datastax.oss.protocol.internal.Message;
21 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
22 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
23 | import com.datastax.oss.protocol.internal.ProtocolConstants;
24 | import com.datastax.oss.protocol.internal.request.query.QueryOptions;
25 | import com.datastax.oss.protocol.internal.util.Bytes;
26 |
27 | public class Execute extends Message {
28 |
29 | public final byte[] queryId;
30 | public final byte[] resultMetadataId;
31 | public final QueryOptions options;
32 |
33 | public Execute(byte[] queryId, byte[] resultMetadataId, QueryOptions options) {
34 | super(false, ProtocolConstants.Opcode.EXECUTE);
35 | this.queryId = queryId;
36 | this.resultMetadataId = resultMetadataId;
37 | this.options = options;
38 | }
39 |
40 | public Execute(byte[] queryId, QueryOptions options) {
41 | this(queryId, null, options);
42 | }
43 |
44 | @Override
45 | public String toString() {
46 | return "EXECUTE(" + Bytes.toHexString(queryId) + ')';
47 | }
48 |
49 | public static class Codec extends Message.Codec {
50 |
51 | private final QueryOptions.Codec optionsCodec;
52 |
53 | public Codec(int protocolVersion, QueryOptions.Codec optionsCodec) {
54 | super(ProtocolConstants.Opcode.EXECUTE, protocolVersion);
55 | this.optionsCodec = optionsCodec;
56 | }
57 |
58 | public Codec(int protocolVersion) {
59 | this(protocolVersion, new QueryOptions.Codec(protocolVersion));
60 | }
61 |
62 | @Override
63 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
64 | Execute execute = (Execute) message;
65 | encoder.writeShortBytes(execute.queryId, dest);
66 | if (protocolVersion >= V5) {
67 | encoder.writeShortBytes(execute.resultMetadataId, dest);
68 | }
69 | optionsCodec.encode(dest, execute.options, encoder);
70 | }
71 |
72 | @Override
73 | public int encodedSize(Message message) {
74 | Execute execute = (Execute) message;
75 | int size = PrimitiveSizes.sizeOfShortBytes(execute.queryId);
76 | if (protocolVersion >= V5) {
77 | assert execute.resultMetadataId != null;
78 | size += PrimitiveSizes.sizeOfShortBytes(execute.resultMetadataId);
79 | }
80 | size += optionsCodec.encodedSize(execute.options);
81 | return size;
82 | }
83 |
84 | @Override
85 | public Message decode(B source, PrimitiveCodec decoder) {
86 | byte[] queryId = decoder.readShortBytes(source);
87 | byte[] resultMetadataId = (protocolVersion >= V5) ? decoder.readShortBytes(source) : null;
88 | QueryOptions options = optionsCodec.decode(source, decoder);
89 | return new Execute(queryId, resultMetadataId, options);
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/request/Options.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.request;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.ProtocolConstants;
21 |
22 | public class Options extends Message {
23 | public static final Options INSTANCE = new Options();
24 |
25 | private Options() {
26 | super(false, ProtocolConstants.Opcode.OPTIONS);
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return "OPTIONS";
32 | }
33 |
34 | public static class Codec extends Message.Codec {
35 | public Codec(int protocolVersion) {
36 | super(ProtocolConstants.Opcode.OPTIONS, protocolVersion);
37 | }
38 |
39 | @Override
40 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
41 | // nothing to do
42 | }
43 |
44 | @Override
45 | public int encodedSize(Message message) {
46 | return 0;
47 | }
48 |
49 | @Override
50 | public Message decode(B source, PrimitiveCodec decoder) {
51 | return Options.INSTANCE;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/request/Prepare.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.request;
17 |
18 | import static com.datastax.oss.protocol.internal.ProtocolConstants.Version.V5;
19 |
20 | import com.datastax.oss.protocol.internal.Message;
21 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
22 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
23 | import com.datastax.oss.protocol.internal.ProtocolConstants;
24 |
25 | public class Prepare extends Message {
26 | public final String cqlQuery;
27 | public final String keyspace;
28 |
29 | public Prepare(String cqlQuery, String keyspace) {
30 | super(false, ProtocolConstants.Opcode.PREPARE);
31 | this.cqlQuery = cqlQuery;
32 | this.keyspace = keyspace;
33 | }
34 |
35 | public Prepare(String cqlQuery) {
36 | this(cqlQuery, null);
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "PREPARE(" + cqlQuery + ", " + keyspace + ')';
42 | }
43 |
44 | public static class Codec extends Message.Codec {
45 | public Codec(int protocolVersion) {
46 | super(ProtocolConstants.Opcode.PREPARE, protocolVersion);
47 | }
48 |
49 | @Override
50 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
51 | Prepare prepare = (Prepare) message;
52 | encoder.writeLongString(prepare.cqlQuery, dest);
53 | if (protocolVersion >= V5) {
54 | // There is only one PREPARE flag for now, so hard-code for simplicity:
55 | encoder.writeInt((prepare.keyspace == null) ? 0x00 : 0x01, dest);
56 | if (prepare.keyspace != null) {
57 | encoder.writeString(prepare.keyspace, dest);
58 | }
59 | }
60 | }
61 |
62 | @Override
63 | public int encodedSize(Message message) {
64 | Prepare prepare = (Prepare) message;
65 | int size = PrimitiveSizes.sizeOfLongString(prepare.cqlQuery);
66 | if (protocolVersion >= V5) {
67 | size += PrimitiveSizes.INT; // flags
68 | if (prepare.keyspace != null) {
69 | size += PrimitiveSizes.sizeOfString(prepare.keyspace);
70 | }
71 | }
72 | return size;
73 | }
74 |
75 | @Override
76 | public Message decode(B source, PrimitiveCodec decoder) {
77 | String cqlQuery = decoder.readLongString(source);
78 | String keyspace = null;
79 | if (protocolVersion >= V5) {
80 | int flags = decoder.readInt(source);
81 | if ((flags & 0x01) == 0x01) {
82 | keyspace = decoder.readString(source);
83 | }
84 | }
85 | return new Prepare(cqlQuery, keyspace);
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/request/Query.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.request;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
21 | import com.datastax.oss.protocol.internal.ProtocolConstants;
22 | import com.datastax.oss.protocol.internal.request.query.QueryOptions;
23 |
24 | public class Query extends Message {
25 | public final String query;
26 | public final QueryOptions options;
27 |
28 | public Query(String query, QueryOptions options) {
29 | super(false, ProtocolConstants.Opcode.QUERY);
30 | this.query = query;
31 | this.options = options;
32 | }
33 |
34 | public Query(String query) {
35 | this(query, QueryOptions.DEFAULT);
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return "QUERY (" + query + ')';
41 | }
42 |
43 | public static class Codec extends Message.Codec {
44 |
45 | protected final QueryOptions.Codec optionsCodec;
46 |
47 | public Codec(int protocolVersion, QueryOptions.Codec optionsCodec) {
48 | super(ProtocolConstants.Opcode.QUERY, protocolVersion);
49 | this.optionsCodec = optionsCodec;
50 | }
51 |
52 | public Codec(int protocolVersion) {
53 | this(protocolVersion, new QueryOptions.Codec(protocolVersion));
54 | }
55 |
56 | @Override
57 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
58 | Query query = (Query) message;
59 | encoder.writeLongString(query.query, dest);
60 | optionsCodec.encode(dest, query.options, encoder);
61 | }
62 |
63 | @Override
64 | public int encodedSize(Message message) {
65 | Query query = (Query) message;
66 | return PrimitiveSizes.sizeOfLongString(query.query) + optionsCodec.encodedSize(query.options);
67 | }
68 |
69 | @Override
70 | public Message decode(B source, PrimitiveCodec decoder) {
71 | String query = decoder.readLongString(source);
72 | QueryOptions options = optionsCodec.decode(source, decoder);
73 | return new Query(query, options);
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/request/Register.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.request;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
21 | import com.datastax.oss.protocol.internal.ProtocolConstants;
22 | import java.util.List;
23 |
24 | public class Register extends Message {
25 |
26 | /** @see ProtocolConstants.EventType */
27 | public final List It is possible to have {@code received >= blockFor} if {@code data_present} is false. Also
33 | * in the (unlikely) case where {@code consistencyLevel} is achieved but the coordinator node
34 | * times out while waiting for read-repair acknowledgement.
35 | */
36 | public final int blockFor;
37 | /** Whether the replica that was asked for data responded. */
38 | public final boolean dataPresent;
39 |
40 | public ReadTimeout(
41 | String message, int consistencyLevel, int received, int blockFor, boolean dataPresent) {
42 | super(ProtocolConstants.ErrorCode.READ_TIMEOUT, message);
43 | this.consistencyLevel = consistencyLevel;
44 | this.received = received;
45 | this.blockFor = blockFor;
46 | this.dataPresent = dataPresent;
47 | }
48 |
49 | public static class SubCodec extends Error.SubCodec {
50 | public SubCodec(int protocolVersion) {
51 | super(ProtocolConstants.ErrorCode.READ_TIMEOUT, protocolVersion);
52 | }
53 |
54 | @Override
55 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
56 | ReadTimeout readTimeout = (ReadTimeout) message;
57 | encoder.writeString(readTimeout.message, dest);
58 | encoder.writeUnsignedShort(readTimeout.consistencyLevel, dest);
59 | encoder.writeInt(readTimeout.received, dest);
60 | encoder.writeInt(readTimeout.blockFor, dest);
61 | encoder.writeByte((byte) (readTimeout.dataPresent ? 1 : 0), dest);
62 | }
63 |
64 | @Override
65 | public int encodedSize(Message message) {
66 | ReadTimeout readTimeout = (ReadTimeout) message;
67 | return PrimitiveSizes.sizeOfString(readTimeout.message)
68 | + PrimitiveSizes.SHORT
69 | + PrimitiveSizes.INT
70 | + PrimitiveSizes.INT
71 | + PrimitiveSizes.BYTE;
72 | }
73 |
74 | @Override
75 | public Message decode(B source, PrimitiveCodec decoder) {
76 | String message = decoder.readString(source);
77 | int consistencyLevel = decoder.readUnsignedShort(source);
78 | int received = decoder.readInt(source);
79 | int blockFor = decoder.readInt(source);
80 | boolean dataPresent = decoder.readByte(source) != 0;
81 | return new ReadTimeout(message, consistencyLevel, received, blockFor, dataPresent);
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/response/error/Unavailable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.response.error;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
21 | import com.datastax.oss.protocol.internal.ProtocolConstants;
22 | import com.datastax.oss.protocol.internal.response.Error;
23 |
24 | public class Unavailable extends Error {
25 | /** The consistency level of the query that triggered the exception. */
26 | public final int consistencyLevel;
27 | /** The number of nodes that should be alive to respect {@code consistencyLevel}. */
28 | public final int required;
29 | /**
30 | * The number of replicas that were known to be alive when the request was processed (since an
31 | * unavailable exception has been triggered, {@code alive < required}.
32 | */
33 | public final int alive;
34 |
35 | public Unavailable(String message, int consistencyLevel, int required, int alive) {
36 | super(ProtocolConstants.ErrorCode.UNAVAILABLE, message);
37 | this.consistencyLevel = consistencyLevel;
38 | this.required = required;
39 | this.alive = alive;
40 | }
41 |
42 | public static class SubCodec extends Error.SubCodec {
43 | public SubCodec(int protocolVersion) {
44 | super(ProtocolConstants.ErrorCode.UNAVAILABLE, protocolVersion);
45 | }
46 |
47 | @Override
48 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
49 | Unavailable unavailable = (Unavailable) message;
50 | encoder.writeString(unavailable.message, dest);
51 | encoder.writeUnsignedShort(unavailable.consistencyLevel, dest);
52 | encoder.writeInt(unavailable.required, dest);
53 | encoder.writeInt(unavailable.alive, dest);
54 | }
55 |
56 | @Override
57 | public int encodedSize(Message message) {
58 | Unavailable unavailable = (Unavailable) message;
59 | return PrimitiveSizes.sizeOfString(unavailable.message)
60 | + PrimitiveSizes.SHORT
61 | + PrimitiveSizes.INT
62 | + PrimitiveSizes.INT;
63 | }
64 |
65 | @Override
66 | public Message decode(B source, PrimitiveCodec decoder) {
67 | String message = decoder.readString(source);
68 | int consistencyLevel = decoder.readUnsignedShort(source);
69 | int required = decoder.readInt(source);
70 | int alive = decoder.readInt(source);
71 | return new Unavailable(message, consistencyLevel, required, alive);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/response/error/Unprepared.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.response.error;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
21 | import com.datastax.oss.protocol.internal.ProtocolConstants;
22 | import com.datastax.oss.protocol.internal.response.Error;
23 |
24 | public class Unprepared extends Error {
25 | public final byte[] id;
26 |
27 | public Unprepared(String message, byte[] id) {
28 | super(ProtocolConstants.ErrorCode.UNPREPARED, message);
29 | this.id = id;
30 | }
31 |
32 | public static class SubCodec extends Error.SubCodec {
33 | public SubCodec(int protocolVersion) {
34 | super(ProtocolConstants.ErrorCode.UNPREPARED, protocolVersion);
35 | }
36 |
37 | @Override
38 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
39 | Unprepared unprepared = (Unprepared) message;
40 | encoder.writeString(unprepared.message, dest);
41 | encoder.writeShortBytes(unprepared.id, dest);
42 | }
43 |
44 | @Override
45 | public int encodedSize(Message message) {
46 | Unprepared unprepared = (Unprepared) message;
47 | return PrimitiveSizes.sizeOfString(unprepared.message)
48 | + PrimitiveSizes.sizeOfShortBytes(unprepared.id);
49 | }
50 |
51 | @Override
52 | public Message decode(B source, PrimitiveCodec decoder) {
53 | String message = decoder.readString(source);
54 | byte[] id = decoder.readShortBytes(source);
55 | return new Unprepared(message, id);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/response/error/WriteTimeout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.response.error;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
21 | import com.datastax.oss.protocol.internal.ProtocolConstants;
22 | import com.datastax.oss.protocol.internal.response.Error;
23 |
24 | public class WriteTimeout extends Error {
25 | /** The consistency level of the query that triggered the exception. */
26 | public final int consistencyLevel;
27 | /** The number of nodes having acknowledged the request. */
28 | public final int received;
29 | /**
30 | * The number of replicas whose acknowledgment is required to achieve {@code consistencyLevel}.
31 | */
32 | public final int blockFor;
33 | /** The type of the write that timed out. */
34 | public final String writeType;
35 |
36 | public WriteTimeout(
37 | String message, int consistencyLevel, int received, int blockFor, String writeType) {
38 | super(ProtocolConstants.ErrorCode.WRITE_TIMEOUT, message);
39 | this.consistencyLevel = consistencyLevel;
40 | this.received = received;
41 | this.blockFor = blockFor;
42 | this.writeType = writeType;
43 | }
44 |
45 | public static class SubCodec extends Error.SubCodec {
46 | public SubCodec(int protocolVersion) {
47 | super(ProtocolConstants.ErrorCode.WRITE_TIMEOUT, protocolVersion);
48 | }
49 |
50 | @Override
51 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
52 | WriteTimeout writeTimeout = (WriteTimeout) message;
53 | encoder.writeString(writeTimeout.message, dest);
54 | encoder.writeUnsignedShort(writeTimeout.consistencyLevel, dest);
55 | encoder.writeInt(writeTimeout.received, dest);
56 | encoder.writeInt(writeTimeout.blockFor, dest);
57 | encoder.writeString(writeTimeout.writeType, dest);
58 | }
59 |
60 | @Override
61 | public int encodedSize(Message message) {
62 | WriteTimeout writeTimeout = (WriteTimeout) message;
63 | return PrimitiveSizes.sizeOfString(writeTimeout.message)
64 | + PrimitiveSizes.SHORT
65 | + PrimitiveSizes.INT
66 | + PrimitiveSizes.INT
67 | + PrimitiveSizes.sizeOfString(writeTimeout.writeType);
68 | }
69 |
70 | @Override
71 | public Message decode(B source, PrimitiveCodec decoder) {
72 | String message = decoder.readString(source);
73 | int consistencyLevel = decoder.readUnsignedShort(source);
74 | int received = decoder.readInt(source);
75 | int blockFor = decoder.readInt(source);
76 | String writeType = decoder.readString(source);
77 | return new WriteTimeout(message, consistencyLevel, received, blockFor, writeType);
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/response/event/StatusChangeEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.response.event;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
21 | import com.datastax.oss.protocol.internal.ProtocolConstants;
22 | import com.datastax.oss.protocol.internal.response.Event;
23 | import java.net.InetSocketAddress;
24 |
25 | public class StatusChangeEvent extends Event {
26 |
27 | /** @see ProtocolConstants.StatusChangeType */
28 | public final String changeType;
29 |
30 | public final InetSocketAddress address;
31 |
32 | public StatusChangeEvent(String changeType, InetSocketAddress address) {
33 | super(ProtocolConstants.EventType.STATUS_CHANGE);
34 | this.changeType = changeType;
35 | this.address = address;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return String.format("EVENT STATUS_CHANGE(%s %s)", changeType, address);
41 | }
42 |
43 | public static class SubCodec extends Event.SubCodec {
44 | public SubCodec(int protocolVersion) {
45 | super(ProtocolConstants.EventType.STATUS_CHANGE, protocolVersion);
46 | }
47 |
48 | @Override
49 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
50 | StatusChangeEvent event = (StatusChangeEvent) message;
51 | encoder.writeString(event.changeType, dest);
52 | encoder.writeInet(event.address, dest);
53 | }
54 |
55 | @Override
56 | public int encodedSize(Message message) {
57 | StatusChangeEvent event = (StatusChangeEvent) message;
58 | return PrimitiveSizes.sizeOfString(event.changeType)
59 | + PrimitiveSizes.sizeOfInet(event.address);
60 | }
61 |
62 | @Override
63 | public Message decode(B source, PrimitiveCodec decoder) {
64 | String changeType = decoder.readString(source);
65 | InetSocketAddress address = decoder.readInet(source);
66 | return new StatusChangeEvent(changeType, address);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/response/event/TopologyChangeEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.response.event;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
21 | import com.datastax.oss.protocol.internal.ProtocolConstants;
22 | import com.datastax.oss.protocol.internal.response.Event;
23 | import java.net.InetSocketAddress;
24 |
25 | public class TopologyChangeEvent extends Event {
26 |
27 | /** @see ProtocolConstants.TopologyChangeType */
28 | public final String changeType;
29 |
30 | public final InetSocketAddress address;
31 |
32 | public TopologyChangeEvent(String changeType, InetSocketAddress address) {
33 | super(ProtocolConstants.EventType.TOPOLOGY_CHANGE);
34 | this.changeType = changeType;
35 | this.address = address;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return String.format("EVENT TOPOLOGY_CHANGE(%s %s)", changeType, address);
41 | }
42 |
43 | public static class SubCodec extends Event.SubCodec {
44 | public SubCodec(int protocolVersion) {
45 | super(ProtocolConstants.EventType.TOPOLOGY_CHANGE, protocolVersion);
46 | }
47 |
48 | @Override
49 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
50 | TopologyChangeEvent event = (TopologyChangeEvent) message;
51 | encoder.writeString(event.changeType, dest);
52 | encoder.writeInet(event.address, dest);
53 | }
54 |
55 | @Override
56 | public int encodedSize(Message message) {
57 | TopologyChangeEvent event = (TopologyChangeEvent) message;
58 | return PrimitiveSizes.sizeOfString(event.changeType)
59 | + PrimitiveSizes.sizeOfInet(event.address);
60 | }
61 |
62 | @Override
63 | public Message decode(B source, PrimitiveCodec decoder) {
64 | String changeType = decoder.readString(source);
65 | InetSocketAddress address = decoder.readInet(source);
66 | return new TopologyChangeEvent(changeType, address);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/response/result/ColumnSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.response.result;
17 |
18 | import java.util.Objects;
19 |
20 | public class ColumnSpec {
21 | public final String ksName;
22 | public final String tableName;
23 | public final String name;
24 | public final int index;
25 | public final RawType type;
26 |
27 | /**
28 | * @param index the position of the column. This is provided for convenience if a decoding client
29 | * needs to reorder the specs (for example index them by name). For encoding, it is ignored.
30 | */
31 | public ColumnSpec(String ksName, String tableName, String name, int index, RawType type) {
32 | this.ksName = ksName;
33 | this.tableName = tableName;
34 | this.name = name;
35 | this.index = index;
36 | this.type = type;
37 | }
38 |
39 | @Override
40 | public boolean equals(Object other) {
41 | if (other == this) {
42 | return true;
43 | } else if (other instanceof ColumnSpec) {
44 | ColumnSpec that = (ColumnSpec) other;
45 | return Objects.equals(this.ksName, that.ksName)
46 | && Objects.equals(this.tableName, that.tableName)
47 | && Objects.equals(this.name, that.name)
48 | && Objects.equals(this.type, that.type);
49 | } else {
50 | return false;
51 | }
52 | }
53 |
54 | @Override
55 | public int hashCode() {
56 | return Objects.hash(ksName, tableName, name, type);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/response/result/DefaultRows.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.response.result;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
21 | import com.datastax.oss.protocol.internal.ProtocolConstants;
22 | import com.datastax.oss.protocol.internal.response.Result;
23 | import com.datastax.oss.protocol.internal.util.collection.NullAllowingImmutableList;
24 | import java.nio.ByteBuffer;
25 | import java.util.ArrayDeque;
26 | import java.util.List;
27 | import java.util.Queue;
28 |
29 | public class DefaultRows extends Rows {
30 | private final RowsMetadata metadata;
31 | private final Queue> data = new ArrayDeque<>(rowCount);
42 | for (int i = 0; i < rowCount; i++) {
43 | List
25 | *
30 | *
31 | * The payload is not compressed; compression is handled at a lower level when encoding or decoding
32 | * this object.
33 | *
34 | * > data;
32 |
33 | public DefaultRows(RowsMetadata metadata, Queue
> data) {
34 | this.metadata = metadata;
35 | this.data = data;
36 | }
37 |
38 | @Override
39 | public RowsMetadata getMetadata() {
40 | return metadata;
41 | }
42 |
43 | @Override
44 | public Queue
> getData() {
45 | return data;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "ROWS(" + data.size() + " x " + metadata.columnCount + " columns)";
51 | }
52 |
53 | public static class SubCodec extends Result.SubCodec {
54 | public SubCodec(int protocolVersion) {
55 | super(ProtocolConstants.ResultKind.ROWS, protocolVersion);
56 | }
57 |
58 | @Override
59 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
60 | DefaultRows rows = (DefaultRows) message;
61 | rows.metadata.encode(dest, encoder, false, protocolVersion);
62 | encoder.writeInt(rows.data.size(), dest);
63 | for (List
> data = new ArrayDeque<>(rowCount);
88 | for (int i = 0; i < rowCount; i++) {
89 | NullAllowingImmutableList.Builder
> getData();
29 |
30 | protected Rows() {
31 | super(ProtocolConstants.ResultKind.ROWS);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/response/result/SetKeyspace.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.response.result;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.PrimitiveSizes;
21 | import com.datastax.oss.protocol.internal.ProtocolConstants;
22 | import com.datastax.oss.protocol.internal.response.Result;
23 |
24 | public class SetKeyspace extends Result {
25 | public final String keyspace;
26 |
27 | public SetKeyspace(String keyspace) {
28 | super(ProtocolConstants.ResultKind.SET_KEYSPACE);
29 | this.keyspace = keyspace;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return "SET_KEYSPACE(" + keyspace + ')';
35 | }
36 |
37 | public static class SubCodec extends Result.SubCodec {
38 | public SubCodec(int protocolVersion) {
39 | super(ProtocolConstants.ResultKind.SET_KEYSPACE, protocolVersion);
40 | }
41 |
42 | @Override
43 | public void encode(B dest, Message message, PrimitiveCodec encoder) {
44 | SetKeyspace setKeyspace = (SetKeyspace) message;
45 | encoder.writeString(setKeyspace.keyspace, dest);
46 | }
47 |
48 | @Override
49 | public int encodedSize(Message message) {
50 | SetKeyspace setKeyspace = (SetKeyspace) message;
51 | return PrimitiveSizes.sizeOfString(setKeyspace.keyspace);
52 | }
53 |
54 | @Override
55 | public Message decode(B source, PrimitiveCodec decoder) {
56 | String keyspace = decoder.readString(source);
57 | return new SetKeyspace(keyspace);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/response/result/Void.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.response.result;
17 |
18 | import com.datastax.oss.protocol.internal.Message;
19 | import com.datastax.oss.protocol.internal.PrimitiveCodec;
20 | import com.datastax.oss.protocol.internal.ProtocolConstants;
21 | import com.datastax.oss.protocol.internal.response.Result;
22 |
23 | @SuppressWarnings("JavaLangClash")
24 | public class Void extends Result {
25 | public static final Void INSTANCE = new Void();
26 |
27 | private Void() {
28 | super(ProtocolConstants.ResultKind.VOID);
29 | }
30 |
31 | @Override
32 | public String toString() {
33 | return "VOID";
34 | }
35 |
36 | public static class SubCodec extends Result.SubCodec {
37 | public SubCodec(int protocolVersion) {
38 | super(ProtocolConstants.ResultKind.VOID, protocolVersion);
39 | }
40 |
41 | @Override
42 | public void encode(B dest, Message message, PrimitiveCodec encoder) {}
43 |
44 | @Override
45 | public int encodedSize(Message message) {
46 | return 0;
47 | }
48 |
49 | @Override
50 | public Message decode(B source, PrimitiveCodec decoder) {
51 | return INSTANCE;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/util/Flags.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.util;
17 |
18 | public class Flags {
19 |
20 | public static boolean contains(int flags, int mask) {
21 | return (flags & mask) == mask;
22 | }
23 |
24 | public static int add(int flags, int mask) {
25 | return flags | mask;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/datastax/oss/protocol/internal/util/IntIntMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright DataStax, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.datastax.oss.protocol.internal.util;
17 |
18 | import java.util.HashMap;
19 | import java.util.Map;
20 |
21 | /** An {@link IntMap} containing other {@code IntMap}s. */
22 | public class IntIntMap