-
Notifications
You must be signed in to change notification settings - Fork 11
Instant converter #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Instant converter #293
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2fa599d
long array mapper
anatennis 952a1fd
long array mapper fix & test
anatennis e210a34
fix & test message pack
anatennis 2ccce35
add serialVersion, changelog
anatennis d2e67ab
instant coverter
anatennis 0252fa7
instant converter add test
anatennis 0994dc8
add serialVersion, changelog, tests
anatennis 0318593
add space
anatennis 00fcdef
Merge branch 'master' into datetimetype
anatennis 452de0d
add space
anatennis 58611f7
add space
anatennis 41c950f
W/A for not available 2.10 version in installer
akudiyar 0e30464
add space
anatennis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
31 changes: 31 additions & 0 deletions
31
...o/tarantool/driver/mappers/converters/object/DefaultInstantToExtensionValueConverter.java
This file contains hidden or 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,31 @@ | ||
package io.tarantool.driver.mappers.converters.object; | ||
|
||
import io.tarantool.driver.mappers.converters.ObjectConverter; | ||
import org.msgpack.value.ExtensionValue; | ||
import org.msgpack.value.ValueFactory; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.time.Instant; | ||
|
||
/** | ||
* Default {@link java.time.Instant} to {@link ExtensionValue} converter | ||
* | ||
* @author Anastasiia Romanova | ||
*/ | ||
public class DefaultInstantToExtensionValueConverter implements ObjectConverter<Instant, ExtensionValue> { | ||
|
||
private static final long serialVersionUID = 20221025L; | ||
|
||
private static final byte DATETIME_TYPE = 0x04; | ||
|
||
private byte[] toBytes(Instant value) { | ||
ByteBuffer buffer = ByteBuffer.wrap(new byte[8]); | ||
buffer.putLong(0, value.getEpochSecond()); | ||
return buffer.array(); | ||
} | ||
|
||
@Override | ||
public ExtensionValue toValue(Instant object) { | ||
return ValueFactory.newExtension(DATETIME_TYPE, toBytes(object)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...io/tarantool/driver/mappers/converters/value/DefaultExtensionValueToInstantConverter.java
This file contains hidden or 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,33 @@ | ||
package io.tarantool.driver.mappers.converters.value; | ||
|
||
import io.tarantool.driver.mappers.converters.ValueConverter; | ||
import org.msgpack.value.ExtensionValue; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.time.Instant; | ||
|
||
/** | ||
* Default {@link ExtensionValue} to {@link java.time.Instant} converter | ||
* | ||
* @author Anastasiia Romanova | ||
*/ | ||
public class DefaultExtensionValueToInstantConverter implements ValueConverter<ExtensionValue, Instant> { | ||
|
||
private static final long serialVersionUID = 20221025L; | ||
private static final byte DATETIME_TYPE = 0x04; | ||
|
||
private Instant fromBytes(byte[] bytes) { | ||
ByteBuffer buffer = ByteBuffer.wrap(bytes); | ||
return Instant.ofEpochSecond(buffer.getLong()); | ||
} | ||
|
||
@Override | ||
public Instant fromValue(ExtensionValue value) { | ||
return fromBytes(value.getData()); | ||
} | ||
|
||
@Override | ||
public boolean canConvertValue(ExtensionValue value) { | ||
return value.getType() == DATETIME_TYPE; | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.