SegmentParser { public BlobInfo parseString(RecordId stringId) { int size = 0; BlobType blobType; Segment segment = stringId.getSegment(); long length = segment.readLength(stringId.getRecordNumber()); if (length < Segment.SMALL_LIMIT) { size += (1 + length); blobType = BlobType.SMALL; } else if (length < Segment.MEDIUM_LIMIT) { size += (2 + length); blobType = BlobType.MEDIUM; } else if (length < Integer.MAX_VALUE) { int count = (int) ((length + BLOCK_SIZE - 1) / BLOCK_SIZE); RecordId listId = segment.readRecordId(stringId.getRecordNumber(), 8); onList(stringId, listId, count); size += (8 + RECORD_ID_BYTES + length); blobType = BlobType.LONG; } else { throw new IllegalStateException("String is too long: " + length); } return new BlobInfo(stringId, blobType, size); } SegmentParser(@NotNull SegmentReader reader); NodeInfo parseNode(RecordId nodeId); TemplateInfo parseTemplate(RecordId templateId); MapInfo parseMap(RecordId parentId, RecordId mapId, MapRecord map); MapInfo parseMapDiff(RecordId mapId, MapRecord map); MapInfo parseMapLeaf(RecordId mapId, MapRecord map); MapInfo parseMapBranch(RecordId mapId, MapRecord map); PropertyInfo parseProperty(RecordId parentId, RecordId propertyId, PropertyTemplate template); ValueInfo parseValue(RecordId parentId, RecordId valueId, Type<?> type); BlobInfo parseBlob(RecordId blobId); BlobInfo parseString(RecordId stringId); ListInfo parseList(RecordId parentId, RecordId listId, int count); ListBucketInfo parseListBucket(RecordId listId, int index, int count, int capacity);  }
@Test public void shortString() throws IOException { RecordId stringId = writer.writeString("short"); BlobInfo blobInfo = new TestParser(store.getReader(), "shortString").parseString(stringId); assertEquals(stringId, blobInfo.blobId); assertEquals(SMALL, blobInfo.blobType); }
@Test public void mediumString() throws IOException { RecordId stringId = writer.writeString(repeat("s", SMALL_LIMIT)); BlobInfo blobInfo = new TestParser(store.getReader(), "mediumString").parseString(stringId); assertEquals(stringId, blobInfo.blobId); assertEquals(MEDIUM, blobInfo.blobType); }
@Test public void longString() throws IOException { RecordId stringId = writer.writeString(repeat("s", MEDIUM_LIMIT)); BlobInfo blobInfo = new TestParser(store.getReader(), "longString"){ @Override protected void onList(RecordId parentId, RecordId listId, int count) { } }.parseString(stringId); assertEquals(stringId, blobInfo.blobId); assertEquals(LONG, blobInfo.blobType); }