-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 11997: Backport the fix for 11996 to release 0.47 (#11999)
Signed-off-by: Artem Ananev <[email protected]>
- Loading branch information
1 parent
1dbe451
commit e77c6fd
Showing
4 changed files
with
272 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
platform-sdk/swirlds-merkle/src/test/java/com/swirlds/virtual/merkle/TestObjectKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright (C) 2016-2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.swirlds.virtual.merkle; | ||
|
||
import com.hedera.pbj.runtime.io.ReadableSequentialData; | ||
import com.hedera.pbj.runtime.io.WritableSequentialData; | ||
import com.swirlds.common.io.streams.SerializableDataInputStream; | ||
import com.swirlds.common.io.streams.SerializableDataOutputStream; | ||
import com.swirlds.virtualmap.VirtualKey; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
|
||
public final class TestObjectKey implements VirtualKey { | ||
|
||
public static final int BYTES = Long.BYTES * 2; | ||
|
||
private long k; | ||
|
||
public TestObjectKey() {} | ||
|
||
public TestObjectKey(long value) { | ||
this.k = value; | ||
} | ||
|
||
public TestObjectKey copy() { | ||
return new TestObjectKey(k); | ||
} | ||
|
||
@Override | ||
public int getVersion() { | ||
return 1; | ||
} | ||
|
||
long getValue() { | ||
return k; | ||
} | ||
|
||
@Override | ||
public void serialize(SerializableDataOutputStream out) throws IOException { | ||
out.writeLong(k); | ||
out.writeLong(k); | ||
} | ||
|
||
void serialize(final WritableSequentialData out) { | ||
out.writeLong(k); | ||
out.writeLong(k); | ||
} | ||
|
||
void serialize(final ByteBuffer buffer) { | ||
buffer.putLong(k); | ||
buffer.putLong(k); | ||
} | ||
|
||
@Override | ||
public void deserialize(SerializableDataInputStream in, int version) throws IOException { | ||
k = in.readLong(); | ||
long kk = in.readLong(); | ||
assert k == kk : "Malformed TestObjectKey"; | ||
} | ||
|
||
void deserialize(final ReadableSequentialData in) { | ||
k = in.readLong(); | ||
long kk = in.readLong(); | ||
assert k == kk : "Malformed TestObjectKey"; | ||
} | ||
|
||
void deserialize(final ByteBuffer buffer) { | ||
k = buffer.getLong(); | ||
long kk = buffer.getLong(); | ||
assert k == kk : "Malformed TestObjectKey"; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Long.hashCode(k); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (Character.isAlphabetic((char) k)) { | ||
return "TestObjectKey{ " + ((char) k) + " }"; | ||
} else { | ||
return "TestObjectKey{ " + k + " }"; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
TestObjectKey other = (TestObjectKey) o; | ||
return k == other.k; | ||
} | ||
|
||
@Override | ||
public long getClassId() { | ||
return 0x255bb9565ebfad4bL; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...-sdk/swirlds-merkle/src/test/java/com/swirlds/virtual/merkle/TestObjectKeySerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (C) 2016-2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.swirlds.virtual.merkle; | ||
|
||
import com.hedera.pbj.runtime.io.ReadableSequentialData; | ||
import com.hedera.pbj.runtime.io.WritableSequentialData; | ||
import com.hedera.pbj.runtime.io.buffer.BufferedData; | ||
import com.swirlds.merkledb.serialize.KeySerializer; | ||
import java.nio.ByteBuffer; | ||
|
||
public class TestObjectKeySerializer implements KeySerializer<TestObjectKey> { | ||
|
||
public TestObjectKeySerializer() { | ||
// required for deserialization | ||
} | ||
|
||
@Override | ||
public long getClassId() { | ||
return 8838922; | ||
} | ||
|
||
@Override | ||
public int getVersion() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public int getSerializedSize() { | ||
return TestObjectKey.BYTES; | ||
} | ||
|
||
@Override | ||
public long getCurrentDataVersion() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public void serialize(final TestObjectKey data, final WritableSequentialData out) { | ||
data.serialize(out); | ||
} | ||
|
||
@Override | ||
public void serialize(TestObjectKey data, ByteBuffer buffer) { | ||
data.serialize(buffer); | ||
} | ||
|
||
@Override | ||
public TestObjectKey deserialize(final ReadableSequentialData in) { | ||
final TestObjectKey key = new TestObjectKey(); | ||
key.deserialize(in); | ||
return key; | ||
} | ||
|
||
@Override | ||
public TestObjectKey deserialize(final ByteBuffer buffer, final long dataVersion) { | ||
final TestObjectKey key = new TestObjectKey(); | ||
key.deserialize(buffer); | ||
return key; | ||
} | ||
|
||
@Override | ||
public boolean equals(final BufferedData buffer, final TestObjectKey keyToCompare) { | ||
return (buffer.readLong() == keyToCompare.getValue()) && (buffer.readLong() == keyToCompare.getValue()); | ||
} | ||
|
||
@Override | ||
public boolean equals(final ByteBuffer buffer, final int dataVersion, final TestObjectKey keyToCompare) { | ||
return (buffer.getLong() == keyToCompare.getValue()) && (buffer.getLong() == keyToCompare.getValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters