何らかの理由でフラットバッファから文字列を読み取るときに、IndexOutOfBoundsExpetion を取得しています。私のスキーマ:
namespace com.busalarmclock.flatbuffers;
table Message {
routes:[Route];
stops:[Stop];
trips:[Trip];
}
table Route {
route_id:string;
route_name:string;
route_description:string;
trips:[Trip];
}
table Trip {
trip_id:string;
op_days:int;
stops:[TripStop];
}
table Stop {
stop_id:int;
stop_name:string;
stop_lon:double;
stop_lat:double;
}
table TripStop {
stop:Stop;
arrival_time:long;
departure_time:long;
dropoff_type:short;
}
root_type Message;
これは私がバッファを書いている方法です:
public static byte[] createStopMessage(TopDocs hits, IndexSearcher indexSearcher) throws IOException {
FlatBufferBuilder builder = new FlatBufferBuilder(1);
int[] stopData = new int[hits.totalHits];
for (int i = 0; i < hits.totalHits; i++)
stopData[i] = createStopObject(indexSearcher.doc(hits.scoreDocs[i].doc), builder);
int stopsOffset = Message.createStopsVector(builder, stopData);
Message.startMessage(builder);
Message.addStops(builder, stopsOffset);
int root = Message.endMessage(builder);
builder.finish(root);
return builder.sizedByteArray();
}
public static byte[] createTripStopsMessage(TripModel trip, IndexSearcher indexSearcher) {
FlatBufferBuilder builder = new FlatBufferBuilder(1);
int[] tripStopData = new int[trip.tripStopModels.length];
for (int i = 0; i < trip.tripStopModels.length; i++)
tripStopData[i] = createTripStopObject(trip.tripStopModels[i], builder);
System.out.printf("tripId:%s", trip.tripId);
int tripIdOffset = builder.createString(trip.tripId);
int tripStopsOffset = Trip.createStopsVector(builder, tripStopData);
Trip.startTrip(builder);
Trip.addTripId(builder, tripIdOffset);
Trip.addStops(builder, tripStopsOffset);
int tripOffset = Trip.endTrip(builder);
Message.startMessage(builder);
Message.addTrips(builder, tripOffset);
int messageOffset = Message.endMessage(builder);
builder.finish(messageOffset);
return builder.sizedByteArray();
}
public static int createTripStopObject(TripStopModel tripStopModel, FlatBufferBuilder builder) {
int stopOffset = createStopObject(tripStopModel.stop, builder);
return TripStop.createTripStop(builder, stopOffset, tripStopModel.arrivalTime,
tripStopModel.departureTime, tripStopModel.dropoffType);
}
これらは私のモデルです:
public class TripModel {
public String tripId;
public int opDays;
public TripStopModel[] tripStopModels;
public TripModel() {
}
public TripModel(String tripId) {
this.tripId = tripId;
}
public TripModel(String tripId, TripStopModel[] tripStationHits) {
this.tripStopModels = tripStationHits;
this.tripId = tripId;
}
public TripModel(String tripId, int opDays, TripStopModel[] tripStationHits) {
this.tripId = tripId;
this.opDays = opDays;
this.tripStopModels = tripStationHits;
}
import org.apache.lucene.document.Document;
/**
* Created by User on 09/07/2016.
*/
public class TripStopModel {
public long arrivalTime;
public long departureTime;
public short dropoffType;
public Document stop;
public TripStopModel() {
}
public TripStopModel(long arrivalTime, long departureTime, short dropoffType, Document stop) {
this.arrivalTime = arrivalTime;
this.departureTime = departureTime;
this.dropoffType = dropoffType;
this.stop = stop;
}
}
lucene データベースがあり、そこからデータをフラットバッファ メッセージに取得しようとしています。バッファを作成するときにエラーは発生しませんが、最初のバッファからバッファを読み取るときに IndexOutOfBoundsExeption が発生します。確認しましたが、解析時に文字列が null ではありません。