001/* 002 * Copyright 2013 Alex Kasko (alexkasko.com) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.alexkasko.unsafe.offheapstruct; 018 019/** 020 * Interface for accessing fields of a single struct 021 * 022 * @author alexkasko 023 * Date: 9/12/13 024 */ 025public interface OffHeapStructAccessor { 026 027 /** 028 * Returns length of the single struct in bytes 029 * 030 * @return length of the single struct in bytes 031 */ 032 int structLength(); 033 034 /** 035 * Copies struct into specified buffer 036 * 037 * @param buffer buffer to copy struct into 038 */ 039 void get(byte[] buffer); 040 041 /** 042 * Copies part of struct into specified buffer 043 * 044 * @param srcPos 045 * @param dest 046 * @param destPos 047 * @param length 048 */ 049 void get(int srcPos, byte[] dest, int destPos, int length); 050 051 /** 052 * Gets byte from struct with specified offset 053 * 054 * @param offset byte array index 055 * @return byte 056 */ 057 byte getByte(int offset); 058 059 /** 060 * Gets one byte (stored as one signed byte) from struct on specified index 061 * with specified offset, converts it to unsigned and returns it as short 062 * 063 * @param offset byte array index 064 * @return unsigned byte as short 065 */ 066 short getUnsignedByte(int offset); 067 068 /** 069 * Gets two bytes as short from struct with specified offset 070 * 071 * @param offset byte array offset 072 * @return short value 073 */ 074 short getShort(int offset); 075 076 /** 077 * Gets unsigned short (stored as two bytes) from struct on specified index 078 * with specified offset and returns it as int 079 * 080 * @param offset byte array offset 081 * @return unsigned short as int 082 */ 083 int getUnsignedShort(int offset); 084 085 /** 086 * Gets four bytes as int from struct with specified offset 087 * 088 * @param offset byte array offset 089 * @return int value 090 */ 091 int getInt(int offset); 092 093 /** 094 * Gets unsigned int (stored as 4 bytes) and returns it as long 095 * from struct with specified offset 096 * 097 * @param offset byte array offset 098 * @return unsigned int as long 099 */ 100 long getUnsignedInt(int offset); 101 102 /** 103 * Gets long from struct with specified offset 104 * 105 * @param offset byte array offset 106 * @return long value 107 */ 108 long getLong(int offset); 109}