public interface SizeMarshaller extends Serializable, net.openhft.chronicle.wire.Marshallable
int
, 8 bytes for long
is rather wasteful for marshalling purposes, when the number (size) to store is usually very
small, and 1-2 bytes could be enough to encode it (this is how stopBit()
marshaller
work). Also, this interface allows to generalize storing constantly-sized and variable-sized
blocks of data. Constantly-sized don't require to store the size actually, the corresponding
constant(long)
SizeMarshaller
consumes 0 bytes.
Some SizeMarshaller
implementations couldn't store the whole long
range, for
example each constant(long)
SizeMarshaller
is able to "store" only a single specific
value (it's constant size). If the marshaller is fed with the size it is not able store, it could
throw an IllegalArgumentException
.
Modifier and Type | Method and Description |
---|---|
static SizeMarshaller |
constant(long constantSize) |
long |
maxStorableSize()
Returns the maximum size this
SizeMarshaller is able to store. |
int |
maxStoringLengthOfSizesInRange(long minSize,
long maxSize)
Returns the maximum storing length this
SizeMarshaller produces for some value in the
given range (both bounds are inclusive). |
long |
minStorableSize()
Returns the minimum size this
SizeMarshaller is able to store. |
int |
minStoringLengthOfSizesInRange(long minSize,
long maxSize)
Returns the minimum storing length this
SizeMarshaller produces for some size in the
given range (both bounds are inclusive). |
long |
readSize(Bytes in)
Reads and returns a size from the input.
|
static SizeMarshaller |
stopBit() |
int |
storingLength(long size)
Calculates how many bytes is takes to store the given
size with this SizeMarshaller . |
void |
writeSize(Bytes out,
long sizeToWrite)
Writes the given size into the streaming output.
|
static SizeMarshaller stopBit()
static SizeMarshaller constant(long constantSize)
int storingLength(long size)
size
with this SizeMarshaller
.size
- the size to storeIllegalArgumentException
- might be thrown, if the given size if not storable by this
SizeMarshaller
long minStorableSize()
SizeMarshaller
is able to store.SizeMarshaller
is able to storelong maxStorableSize()
SizeMarshaller
is able to store.SizeMarshaller
is able to storeint minStoringLengthOfSizesInRange(long minSize, long maxSize)
SizeMarshaller
produces for some size in the
given range (both bounds are inclusive).minSize
- the lower bound of the range (inclusive)maxSize
- the upper bound of the range (inclusive)maxStoringLengthOfSizesInRange(long, long)
int maxStoringLengthOfSizesInRange(long minSize, long maxSize)
SizeMarshaller
produces for some value in the
given range (both bounds are inclusive).minSize
- the lower bound of the range (inclusive)maxSize
- the upper bound of the range (inclusive)minStoringLengthOfSizesInRange(long, long)
void writeSize(Bytes out, long sizeToWrite)
out
- the StreamingDataOutput
to write the size tosizeToWrite
- the size to writeIllegalArgumentException
- might be thrown, if the given size if not storable by this
SizeMarshaller
readSize(Bytes)
long readSize(Bytes in)
in
- the StreamingDataInput
to read the size fromwriteSize(Bytes, long)
Copyright © 2015. All rights reserved.