Skip to content

Commit d85deb7

Browse files
Add new message format support [ECR-3473]: (#1085)
Add support for new protocol buffers-based message format. SignedMessage supports any Exonum message; whilst TransactionMessage (including ParsedTransactionMessage) represent a transaction message and allow to access any properties of the transaction. As transaction payloads (arguments) are often protocol buffer messages, some methods now have protobuf-specific overloads for higher convenience (e.g., TransactionMessage.Builder#payload).
1 parent b711d30 commit d85deb7

File tree

23 files changed

+836
-591
lines changed

23 files changed

+836
-591
lines changed

exonum-java-binding/common/checkstyle-suppressions.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@
1414
<!-- Allow underscore in the class name so that IDEs work properly. -->
1515
<suppress files="Message_Builder2Test\.java" checks="TypeName"/>
1616

17+
<!-- Allow `aInstance` name -->
18+
<suppress files="SignedMessageTest.java|ParsedTransactionMessageTest.java|JsonSerializerTest.java"
19+
checks="MethodName"/>
1720
</suppressions>

exonum-java-binding/common/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
<executions>
143143
<execution>
144144
<goals>
145+
<goal>compile</goal>
145146
<goal>test-compile</goal>
146147
</goals>
147148
<configuration>

exonum-java-binding/common/src/main/java/com/exonum/binding/common/crypto/AbstractKey.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import static com.exonum.binding.common.crypto.CryptoUtils.byteArrayToHex;
2020
import static com.google.common.base.Preconditions.checkArgument;
2121

22+
import com.exonum.binding.common.hash.Funnel;
23+
import com.exonum.binding.common.hash.PrimitiveSink;
2224
import java.util.Arrays;
2325

2426
/**
@@ -78,4 +80,20 @@ public final int hashCode() {
7880
public String toString() {
7981
return byteArrayToHex(rawKey);
8082
}
83+
84+
/**
85+
* Returns a funnel for any key.
86+
*/
87+
public static Funnel<AbstractKey> keyFunnel() {
88+
return KeyFunnel.INSTANCE;
89+
}
90+
91+
private enum KeyFunnel implements Funnel<AbstractKey> {
92+
INSTANCE;
93+
94+
@Override
95+
public void funnel(AbstractKey from, PrimitiveSink into) {
96+
into.putBytes(from.toBytesNoCopy());
97+
}
98+
}
8199
}

exonum-java-binding/common/src/main/java/com/exonum/binding/common/message/BinaryTransactionMessage.java

Lines changed: 0 additions & 149 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2019 The Exonum Team
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+
17+
package com.exonum.binding.common.message;
18+
19+
import com.exonum.binding.common.hash.Funnel;
20+
import com.exonum.binding.common.hash.PrimitiveSink;
21+
import com.google.protobuf.ByteString;
22+
23+
/**
24+
* A funnel for ByteStrings which puts their bytes to the sink without copying.
25+
*/
26+
enum ByteStringFunnel implements Funnel<ByteString> {
27+
28+
INSTANCE;
29+
30+
static Funnel<ByteString> byteStringFunnel() {
31+
return INSTANCE;
32+
}
33+
34+
@Override
35+
public void funnel(ByteString from, PrimitiveSink into) {
36+
// We use #asReadOnlyByteBuffer instead of #asReadOnlyByteBufferList because
37+
// it is not expected that in our main usages of this funnel a RopeByteString will
38+
// appear.
39+
// If this funnel is used more widely, it might be reasonable to use #asReadOnlyByteBufferList
40+
// to prevent copying in case of RopeByteString.
41+
into.putBytes(from.asReadOnlyByteBuffer());
42+
}
43+
}

exonum-java-binding/common/src/main/java/com/exonum/binding/common/message/MessageType.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)