mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Full proof read and edit
This commit is contained in:
+17
-20
@@ -8,41 +8,38 @@ Neil Clifford
|
||||
|
||||
toc::[]
|
||||
|
||||
This pair of interfaces is configured via `ChronicleMapBuilder.keyMarshallers()` or
|
||||
`valueMarshallers()` for the key or value type of the map, respectively (overloaded methods, those
|
||||
This pair of interfaces is configured using `ChronicleMapBuilder.keyMarshallers()` or
|
||||
`valueMarshallers()` for the key, or value type, of the map, respectively. Overloaded methods; those
|
||||
for [`BytesWriter` and `BytesReader`](#byteswriter-and-bytesreader) interfaces have the same names).
|
||||
|
||||
The main two methods to implement in `SizedWriter` interface:
|
||||
The main two methods to implement in `SizedWriter` interface are:
|
||||
|
||||
- `long size(@NotNull T toWrite);` returns the number of bytes, which is written by the subsequent
|
||||
`write()` method given the same `toWrite` instance of the serialized type.
|
||||
- `void write(Bytes out, long size, @NotNull T toWrite);` writes the given `toWrite` instance to
|
||||
the given `out` bytes sink. Additionally `size` is provided, which is the value computed for the
|
||||
same `toWrite` instance by calling `size()` method. Hence, when `SizedWriter` is used internally,
|
||||
`size()` method is always called before `write()`, caching logic in `SizedWriter` implementation
|
||||
may rely on this. This method should advance `writePosition()` of the given out `Bytes` exactly by
|
||||
the given `out` bytes sink. Additionally, `size` is provided, which is the value computed for the
|
||||
same `toWrite` instance by calling `size()` method. When `SizedWriter` is used internally,
|
||||
the `size()` method is always called before `write()`; caching logic in `SizedWriter` implementation
|
||||
may rely on this. This method should advance the `writePosition()` of the given out `Bytes` exactly by
|
||||
the given `size` number of bytes.
|
||||
|
||||
`SizedReader`'s `T read(Bytes in, long size, @Nullable T using);` method is similar to the
|
||||
corresponding `read()` method in `BytesReader` interface, except the size of the serialized object
|
||||
is provided.
|
||||
corresponding `read()` method in `BytesReader` interface, except that the size of the serialized object is provided.
|
||||
|
||||
This pair of interfaces is suitable, if
|
||||
This pair of interfaces is suitable, if:
|
||||
|
||||
- The serialized form of the type effectively includes the size of the rest of the serialized form
|
||||
in the beginning,
|
||||
- But the type is not a plain sequence of bytes like `byte[]` or `ByteBuffer` (for those types
|
||||
[`DataAccess` and `SizedReader`](#dataaccess-and-sizedreader) pair of interfaces is a much better
|
||||
choice).
|
||||
in the beginning.
|
||||
|
||||
Examples of such types include lists and arrays of constant-sized elements.
|
||||
- The type is not a plain sequence of bytes; for example, `byte[]` or `ByteBuffer`. For `byte[]` or `ByteBuffer`, the <<CM_Tutorial_DataAccess#, `DataAccess` and `SizedReader`>> pair of interfaces is a much better
|
||||
choice.
|
||||
|
||||
Compared to `BytesWriter` and `BytesReader`, this pair of interfaces allows to share the information
|
||||
about the serialized form between serialization logic and the Chronicle Map, saving a few bytes by
|
||||
storing the serialization size only once rather than twice. This pair of interfaces is not much more
|
||||
difficult to implement, but the gains are also not big.
|
||||
Examples of such types include lists, and arrays of constant-sized elements.
|
||||
|
||||
Example: serializing lists of simple `Point` structures:
|
||||
Compared to `BytesWriter` and `BytesReader`, this pair of interfaces allows the sharing of information
|
||||
about the serialized form, between serialization logic, and the Chronicle Map; this saves a few bytes by storing the serialization size only once, rather than twice. This pair of interfaces is not much more difficult to implement, but the gains are also not large.
|
||||
|
||||
Example: Serializing lists of simple `Point` structures:
|
||||
|
||||
```java
|
||||
public final class Point {
|
||||
|
||||
Reference in New Issue
Block a user