// deserialize the Grib1Record object private Grib1Record readRecord(Grib1IndexProto.Grib1Record p) { Grib1SectionIndicator is = new Grib1SectionIndicator(p.getGribMessageStart(), p.getGribMessageLength()); Grib1SectionProductDefinition pds = new Grib1SectionProductDefinition(p.getPds().toByteArray()); Grib1SectionGridDefinition gds = pds.gdsExists() ? gdsList.get(p.getGdsIdx()) : new Grib1SectionGridDefinition(pds); Grib1SectionBitMap bms = pds.bmsExists() ? new Grib1SectionBitMap(p.getBmsPos()) : null; Grib1SectionBinaryData dataSection = new Grib1SectionBinaryData(p.getDataPos(), p.getDataLen()); return new Grib1Record(p.getHeader().toByteArray(), is, gds, pds, bms, dataSection); }
private ucar.nc2.grib.grib1.Grib1IndexProto.Grib1Record makeRecordProto( Grib1Record r, int gdsIndex) throws IOException { Grib1IndexProto.Grib1Record.Builder b = Grib1IndexProto.Grib1Record.newBuilder(); b.setHeader(ByteString.copyFrom(r.getHeader())); b.setGribMessageStart(r.getIs().getStartPos()); b.setGribMessageLength(r.getIs().getMessageLength()); b.setGdsIdx(gdsIndex); Grib1SectionProductDefinition pds = r.getPDSsection(); b.setPds(ByteString.copyFrom(pds.getRawBytes())); if (pds.bmsExists()) { Grib1SectionBitMap bms = r.getBitMapSection(); b.setBmsPos(bms.getStartingPosition()); } Grib1SectionBinaryData ds = r.getDataSection(); b.setDataPos(ds.getStartingPosition()); b.setDataLen(ds.getLength()); return b.build(); }