org.eclipse.store.storage.restadapter.types.ValueReaderPrimitiveList Maven / Gradle / Ivy
package org.eclipse.store.storage.restadapter.types;
/*-
* #%L
* EclipseStore Storage REST Adapter
* %%
* Copyright (C) 2023 MicroStream Software
* %%
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
* #L%
*/
import org.eclipse.serializer.persistence.binary.types.Binary;
import org.eclipse.serializer.persistence.binary.types.BinaryPersistence;
import org.eclipse.serializer.persistence.types.PersistenceTypeDefinitionMember;
public class ValueReaderPrimitiveList extends ValueReaderVariableLength
{
///////////////////////////////////////////////////////////////////////////
// constructors //
/////////////////
public ValueReaderPrimitiveList(final PersistenceTypeDefinitionMember typeDefinition)
{
super(typeDefinition);
}
///////////////////////////////////////////////////////////////////////////
// methods //
////////////
@Override
public Object readValue(final Binary binary, final long offset)
{
long elementsOffset = Binary.toBinaryListElementsOffset(offset);
final int elementCount = (int) binary.getBinaryListElementCountUnvalidating(offset);
final Object[] values = new Object[elementCount];
for(int i = 0; i < elementCount; i++)
{
values[i] = ViewerBinaryPrimitivesReader.readPrimitive(this.typeDefinition.type(), binary, elementsOffset);
elementsOffset += BinaryPersistence.resolvePrimitiveFieldBinaryLength(this.typeDefinition.type());
}
return values;
}
}