Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Add version list to get human-readable version ids
Browse files Browse the repository at this point in the history
  • Loading branch information
SerVB committed Jul 14, 2020
1 parent 3e139d6 commit d3384fe
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ import org.jetbrains.projector.common.protocol.MessageDecoder
import org.jetbrains.projector.common.protocol.MessageEncoder
import org.jetbrains.projector.common.protocol.compress.MessageCompressor
import org.jetbrains.projector.common.protocol.compress.MessageDecompressor
import org.jetbrains.projector.common.protocol.handshake.COMMON_VERSION
import org.jetbrains.projector.common.protocol.handshake.ToClientHandshakeFailureEvent
import org.jetbrains.projector.common.protocol.handshake.ToClientHandshakeSuccessEvent
import org.jetbrains.projector.common.protocol.handshake.ToServerHandshakeEvent
import org.jetbrains.projector.common.protocol.handshake.*
import org.jetbrains.projector.common.protocol.toClient.ServerDrawCommandsEvent
import org.jetbrains.projector.common.protocol.toClient.ToClientMessageDecoder
import org.jetbrains.projector.common.protocol.toServer.*
Expand Down Expand Up @@ -133,6 +130,7 @@ sealed class ClientState {
val handshakeEvent = with(SupportedTypesProvider) {
ToServerHandshakeEvent(
commonVersion = COMMON_VERSION,
commonVersionId = commonVersionList.indexOf(COMMON_VERSION),
token = ParamsProvider.HANDSHAKE_TOKEN,
initialSize = windowSizeController.currentSize,
supportedToClientCompressions = supportedToClientDecompressors.map(MessageDecompressor<*>::compressionType),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ import org.jetbrains.projector.common.protocol.toServer.ClientEvent
val COMMON_VERSION = listOf(ServerEvent.serializer(), ClientEvent.serializer())
.map { it.list.descriptor.compatibilityHash }
.reduce(Int::xor)

// Don't change order here: it's used to obtain readable "human id"
val commonVersionList = listOf(
-1663032476
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.jetbrains.projector.common.protocol.data.CommonIntSize
@Serializable
data class ToServerHandshakeEvent(
val commonVersion: Int,
val commonVersionId: Int,
val token: String? = null,
val initialSize: CommonIntSize,
val supportedToClientCompressions: List<CompressionType>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* MIT License
*
* Copyright (c) 2019-2020 JetBrains s.r.o.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.jetbrains.projector.common.protocol

import org.jetbrains.projector.common.protocol.handshake.COMMON_VERSION
import org.jetbrains.projector.common.protocol.handshake.commonVersionList
import kotlin.test.Test
import kotlin.test.assertTrue

class CommonVersionPresenceTest {

@Test
fun commonVersionListShouldContainCurrentCommonVersion() {
assertTrue(
COMMON_VERSION in commonVersionList,
"""
|Current common version of protocol should be in `commonVersionList`.
|It seems that protocol has been updated.
|Please append the current COMMON_VERSION to the commonVersionList as the last element.
|Current values:
|COMMON_VERSION = $COMMON_VERSION
|commonVersionList = $commonVersionList
""".trimMargin()
)
}
}

0 comments on commit d3384fe

Please sign in to comment.