@@ -34,8 +34,8 @@ internal constructor(
3434 }
3535
3636 private class State (val readMode : Boolean ) {
37- var count = 0
38- val sequence = mutableListOf<Pair <String , SnapshotValue >>()
37+ var currentFrame = 0
38+ val frames = mutableListOf<Pair <String , SnapshotValue >>()
3939 }
4040 private val state: State
4141
@@ -55,61 +55,66 @@ internal constructor(
5555 check(num == idx)
5656 ++ idx
5757 val keyAfterNum = key.substring(nextClose + 1 )
58- state.sequence .add(keyAfterNum to value)
58+ state.frames .add(keyAfterNum to value)
5959 }
6060 }
6161 }
6262 override fun close () {
6363 if (state.readMode) {
64- if (state.sequence .size != state.count ) {
64+ if (state.frames .size != state.currentFrame ) {
6565 throw Selfie .system.fs.assertFailed(
66- Selfie .system.mode.msgVcrKeyUnread (state.sequence .size, state.count ))
66+ Selfie .system.mode.msgVcrUnread (state.frames .size, state.currentFrame ))
6767 }
6868 } else {
6969 var snapshot = Snapshot .of(" " )
7070 var idx = 1
71- for ((key, value) in state.sequence ) {
71+ for ((key, value) in state.frames ) {
7272 snapshot = snapshot.plusFacet(" $OPEN$idx$CLOSE$key " , value)
7373 }
7474 disk.writeDisk(snapshot, sub, call)
7575 }
7676 }
77- private fun nextValue (key : String ): SnapshotValue {
77+ private fun nextFrameValue (key : String ): SnapshotValue {
7878 val mode = Selfie .system.mode
7979 val fs = Selfie .system.fs
80- if (state.sequence .size <= state.count ) {
81- throw fs.assertFailed(mode.msgVcrKeyUnderflow (state.sequence .size))
80+ if (state.frames .size <= state.currentFrame ) {
81+ throw fs.assertFailed(mode.msgVcrUnderflow (state.frames .size))
8282 }
83- val expected = state.sequence [state.count ++ ]
83+ val expected = state.frames [state.currentFrame ++ ]
8484 if (expected.first != key) {
8585 throw fs.assertFailed(
86- mode.msgVcrKeyMismatch (" $sub [$OPEN${state.count }$CLOSE ]" , expected.first, key),
86+ mode.msgVcrMismatch (" $sub [$OPEN${state.currentFrame }$CLOSE ]" , expected.first, key),
8787 expected.first,
8888 key)
8989 }
9090 return expected.second
9191 }
92- fun <V > next (key : String , roundtripValue : Roundtrip <V , String >, value : Cacheable <V >): V {
92+ fun <V > nextFrame (key : String , roundtripValue : Roundtrip <V , String >, value : Cacheable <V >): V {
9393 if (state.readMode) {
94- return roundtripValue.parse(nextValue (key).valueString())
94+ return roundtripValue.parse(nextFrameValue (key).valueString())
9595 } else {
9696 val value = value.get()
97- state.sequence .add(key to SnapshotValue .of(roundtripValue.serialize(value)))
97+ state.frames .add(key to SnapshotValue .of(roundtripValue.serialize(value)))
9898 return value
9999 }
100100 }
101- fun next (key : String , value : Cacheable <String >): String = next(key, Roundtrip .identity(), value)
102- inline fun <reified V > nextJson (key : String , value : Cacheable <V >): V =
103- next(key, RoundtripJson .of<V >(), value)
104- fun <V > nextBinary (key : String , roundtripValue : Roundtrip <V , ByteArray >, value : Cacheable <V >): V {
101+ fun nextFrame (key : String , value : Cacheable <String >): String =
102+ nextFrame(key, Roundtrip .identity(), value)
103+ inline fun <reified V > nextFrameJson (key : String , value : Cacheable <V >): V =
104+ nextFrame(key, RoundtripJson .of<V >(), value)
105+ fun <V > nextFrameBinary (
106+ key : String ,
107+ roundtripValue : Roundtrip <V , ByteArray >,
108+ value : Cacheable <V >
109+ ): V {
105110 if (state.readMode) {
106- return roundtripValue.parse(nextValue (key).valueBinary())
111+ return roundtripValue.parse(nextFrameValue (key).valueBinary())
107112 } else {
108113 val value = value.get()
109- state.sequence .add(key to SnapshotValue .of(roundtripValue.serialize(value)))
114+ state.frames .add(key to SnapshotValue .of(roundtripValue.serialize(value)))
110115 return value
111116 }
112117 }
113- fun <V > nextBinary (key : String , value : Cacheable <ByteArray >): ByteArray =
114- nextBinary (key, Roundtrip .identity(), value)
118+ fun <V > nextFrameBinary (key : String , value : Cacheable <ByteArray >): ByteArray =
119+ nextFrameBinary (key, Roundtrip .identity(), value)
115120}
0 commit comments