HCOLL-136 HCOLL-137 Improved BytesReader, BytesWriter and BytesInterop docs [dc]

This commit is contained in:
leventov
2014-11-07 14:16:31 +03:00
parent 28d20d03b6
commit f96d369cdd
22 changed files with 339 additions and 49 deletions
@@ -18,7 +18,7 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.serialization.impl.ByteableMarshaller;
import net.openhft.chronicle.hash.serialization.internal.ByteableMarshaller;
import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.NativeBytes;
import net.openhft.lang.io.serialization.BytesMarshaller;
@@ -18,7 +18,7 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.serialization.impl.ByteableMarshaller;
import net.openhft.chronicle.hash.serialization.internal.ByteableMarshaller;
import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.NativeBytes;
import net.openhft.lang.io.serialization.BytesMarshaller;
@@ -0,0 +1,21 @@
/*
* Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
*
* 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 net.openhft.chronicle.map.fromdocs;
public final class LongPair {
long first, second;
}
@@ -0,0 +1,54 @@
/*
* Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
*
* 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 net.openhft.chronicle.map.fromdocs;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.lang.io.Bytes;
import java.util.Arrays;
enum LongPairArrayReader implements BytesReader<LongPair[]> {
INSTANCE;
@Override
public LongPair[] read(Bytes bytes, long size) {
return read(bytes, size, null);
}
@Override
public LongPair[] read(Bytes bytes, long size, LongPair[] toReuse) {
int resLen = (int) (size / 16L);
LongPair[] res;
if (toReuse != null) {
if (toReuse.length == resLen) {
res = toReuse;
} else {
res = Arrays.copyOf(toReuse, resLen);
}
} else {
res = new LongPair[resLen];
}
for (int i = 0; i < resLen; i++) {
LongPair pair = res[i];
if (pair == null)
res[i] = pair = new LongPair();
pair.first = bytes.readLong();
pair.second = bytes.readLong();
}
return res;
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
*
* 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 net.openhft.chronicle.map.fromdocs;
import net.openhft.chronicle.hash.serialization.BytesWriter;
import net.openhft.lang.io.Bytes;
enum LongPairArrayWriter implements BytesWriter<LongPair[]> {
INSTANCE;
@Override
public long size(LongPair[] longPairs) {
return longPairs.length * 16L;
}
@Override
public void write(Bytes bytes, LongPair[] longPairs) {
for (LongPair pair : longPairs) {
bytes.writeLong(pair.first);
bytes.writeLong(pair.second);
}
}
}