Skip to content

Commit a0d45ea

Browse files
committed
fu flv
1 parent 0d2509b commit a0d45ea

File tree

123 files changed

+3723
-2815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+3723
-2815
lines changed

amf/src/commonMain/kotlin/io/github/thibaultbee/krtmp/amf/elements/AmfElementFactory.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@
1515
*/
1616
package io.github.thibaultbee.krtmp.amf.elements
1717

18-
import io.github.thibaultbee.krtmp.amf.elements.containers.AmfContainer
19-
import io.github.thibaultbee.krtmp.amf.elements.containers.AmfEcmaArray
20-
import io.github.thibaultbee.krtmp.amf.elements.containers.AmfObject
21-
import io.github.thibaultbee.krtmp.amf.elements.containers.AmfStrictArray
18+
import io.github.thibaultbee.krtmp.amf.elements.containers.amfContainerOf
19+
import io.github.thibaultbee.krtmp.amf.elements.containers.amfEcmaArrayOf
20+
import io.github.thibaultbee.krtmp.amf.elements.containers.amfObjectOf
21+
import io.github.thibaultbee.krtmp.amf.elements.containers.amfStrictArrayOf
2222
import io.github.thibaultbee.krtmp.amf.elements.primitives.AmfBoolean
23-
import io.github.thibaultbee.krtmp.amf.elements.primitives.AmfDate
2423
import io.github.thibaultbee.krtmp.amf.elements.primitives.AmfNull
2524
import io.github.thibaultbee.krtmp.amf.elements.primitives.AmfNumber
2625
import io.github.thibaultbee.krtmp.amf.elements.primitives.AmfString
26+
import io.github.thibaultbee.krtmp.amf.elements.primitives.amfDateOf
2727
import kotlinx.datetime.Instant
2828
import kotlinx.io.IOException
2929

3030
object AmfElementFactory {
31-
fun buildContainer(value: List<Any?>) = AmfContainer(value)
31+
fun buildContainer(value: List<Any?>) = amfContainerOf(value)
3232

33-
fun buildEcmaArray(value: Map<String, Any?>) = AmfEcmaArray(value)
33+
fun buildEcmaArray(value: Map<String, Any?>) = amfEcmaArrayOf(value)
3434

35-
fun buildObject(value: Map<String, Any?>) = AmfObject(value)
35+
fun buildObject(value: Map<String, Any?>) = amfObjectOf(value)
3636

37-
fun buildStrictArray(value: List<Any?>) = AmfStrictArray(value)
37+
fun buildStrictArray(value: List<Any?>) = amfStrictArrayOf(value)
3838

3939
fun build(value: Any?): AmfElement {
4040
if (value == null) {
@@ -45,15 +45,16 @@ object AmfElementFactory {
4545
is Boolean -> AmfBoolean(value)
4646
is Double -> AmfNumber(value)
4747
is String -> AmfString(value)
48-
is List<*> -> AmfStrictArray(value)
49-
is Instant -> AmfDate(value)
48+
is List<*> -> amfStrictArrayOf(value)
49+
is Instant -> amfDateOf(value)
5050
is Map<*, *> -> {
5151
if (value.keys.any { it !is String }) {
5252
throw IOException("AMF ECMA array keys must be String. At least one is not a String in ${value.keys}")
5353
}
5454
@Suppress("UNCHECKED_CAST")
55-
AmfEcmaArray(value as Map<String, Any?>)
55+
amfEcmaArrayOf(value as Map<String, Any?>)
5656
}
57+
5758
else -> throw IOException("Can't build an AmfParameter for ${value::class.simpleName}: $value")
5859
}
5960
}

amf/src/commonMain/kotlin/io/github/thibaultbee/krtmp/amf/elements/AmfElementReader.kt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
*/
1616
package io.github.thibaultbee.krtmp.amf.elements
1717

18-
import io.github.thibaultbee.krtmp.amf.elements.containers.Amf0Container
19-
import io.github.thibaultbee.krtmp.amf.elements.containers.Amf0EcmaArray
20-
import io.github.thibaultbee.krtmp.amf.elements.containers.Amf0Object
21-
import io.github.thibaultbee.krtmp.amf.elements.containers.Amf0StrictArray
22-
import io.github.thibaultbee.krtmp.amf.elements.primitives.Amf0Boolean
23-
import io.github.thibaultbee.krtmp.amf.elements.primitives.Amf0Date
24-
import io.github.thibaultbee.krtmp.amf.elements.primitives.Amf0Null
25-
import io.github.thibaultbee.krtmp.amf.elements.primitives.Amf0Number
26-
import io.github.thibaultbee.krtmp.amf.elements.primitives.Amf0String
18+
import io.github.thibaultbee.krtmp.amf.elements.containers.amf0ContainerFrom
19+
import io.github.thibaultbee.krtmp.amf.elements.containers.amf0EcmaArrayFrom
20+
import io.github.thibaultbee.krtmp.amf.elements.containers.amf0ObjectFrom
21+
import io.github.thibaultbee.krtmp.amf.elements.containers.amf0StrictArrayFrom
22+
import io.github.thibaultbee.krtmp.amf.elements.primitives.amf0BooleanFrom
23+
import io.github.thibaultbee.krtmp.amf.elements.primitives.amf0DateFrom
24+
import io.github.thibaultbee.krtmp.amf.elements.primitives.amf0NullFrom
25+
import io.github.thibaultbee.krtmp.amf.elements.primitives.amf0NumberFrom
26+
import io.github.thibaultbee.krtmp.amf.elements.primitives.amf0StringFrom
2727
import kotlinx.io.IOException
2828
import kotlinx.io.Source
2929

@@ -41,25 +41,25 @@ interface AmfElementReader {
4141

4242
object Amf0ElementReader : AmfElementReader {
4343
override fun readContainer(numOfElements: Int, source: Source) =
44-
Amf0Container(numOfElements, source)
44+
amf0ContainerFrom(numOfElements, source)
4545

46-
override fun readEcmaArray(source: Source) = Amf0EcmaArray(source)
46+
override fun readEcmaArray(source: Source) = amf0EcmaArrayFrom(source)
4747

48-
override fun readObject(source: Source) = Amf0Object(source)
48+
override fun readObject(source: Source) = amf0ObjectFrom(source)
4949

50-
override fun buildStrictArray(source: Source) = Amf0StrictArray(source)
50+
override fun buildStrictArray(source: Source) = amf0StrictArrayFrom(source)
5151

5252
override fun read(source: Source): AmfElement {
5353
return when (val type = source.peek().readByte()) {
54-
Amf0Type.NUMBER.value -> Amf0Number(source)
55-
Amf0Type.BOOLEAN.value -> Amf0Boolean(source)
56-
Amf0Type.STRING.value -> Amf0String(source)
57-
Amf0Type.LONG_STRING.value -> Amf0String(source)
58-
Amf0Type.OBJECT.value -> Amf0Object(source)
59-
Amf0Type.NULL.value -> Amf0Null(source)
60-
Amf0Type.ECMA_ARRAY.value -> Amf0EcmaArray(source)
61-
Amf0Type.STRICT_ARRAY.value -> Amf0StrictArray(source)
62-
Amf0Type.DATE.value -> Amf0Date(source)
54+
Amf0Type.NUMBER.value -> amf0NumberFrom(source)
55+
Amf0Type.BOOLEAN.value -> amf0BooleanFrom(source)
56+
Amf0Type.STRING.value -> amf0StringFrom(source)
57+
Amf0Type.LONG_STRING.value -> amf0StringFrom(source)
58+
Amf0Type.OBJECT.value -> amf0ObjectFrom(source)
59+
Amf0Type.NULL.value -> amf0NullFrom(source)
60+
Amf0Type.ECMA_ARRAY.value -> amf0EcmaArrayFrom(source)
61+
Amf0Type.STRICT_ARRAY.value -> amf0StrictArrayFrom(source)
62+
Amf0Type.DATE.value -> amf0DateFrom(source)
6363
else -> throw IOException("Invalid AMF0 type: $type")
6464
}
6565
}

amf/src/commonMain/kotlin/io/github/thibaultbee/krtmp/amf/elements/containers/AmfContainer.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import kotlinx.io.Source
2727
* @param expectedNumOfElements the number of elements in the container
2828
* @param source the source containing elements
2929
*/
30-
fun Amf0Container(expectedNumOfElements: Int, source: Source): AmfContainer {
30+
fun amf0ContainerFrom(expectedNumOfElements: Int, source: Source): AmfContainer {
3131
val amfContainer = AmfContainer()
3232
var numOfElements = 0
3333
while (numOfElements < expectedNumOfElements) {
@@ -37,13 +37,14 @@ fun Amf0Container(expectedNumOfElements: Int, source: Source): AmfContainer {
3737
return amfContainer
3838
}
3939

40-
fun AmfContainer(initialElements: List<Any?>) =
40+
fun amfContainerOf(initialElements: List<Any?>) =
4141
AmfContainer().apply { addAll(initialElements) }
4242

4343
/**
4444
* A container is a list of [AmfElement]. Contrary to [AmfStrictArray], it doesn't have a size.
4545
*/
46-
class AmfContainer(private val elements: MutableList<AmfElement> = mutableListOf()) : AmfElement(),
46+
class AmfContainer internal constructor(private val elements: MutableList<AmfElement> = mutableListOf()) :
47+
AmfElement(),
4748
MutableList<AmfElement> by elements {
4849

4950
override val size0: Int

amf/src/commonMain/kotlin/io/github/thibaultbee/krtmp/amf/elements/containers/AmfEcmaArray.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import kotlinx.io.Source
2626
import kotlinx.io.readString
2727
import kotlinx.io.writeString
2828

29-
fun Amf0EcmaArray(source: Source): AmfEcmaArray {
29+
fun amf0EcmaArrayFrom(source: Source): AmfEcmaArray {
3030
val type = source.readByte()
3131
require(type == Amf0Type.ECMA_ARRAY.value) { "Amf0EcmaArray cannot read buffer because it's not ECMA_ARRAY type" }
3232

@@ -47,10 +47,10 @@ fun Amf0EcmaArray(source: Source): AmfEcmaArray {
4747
return amf0EcmaArray
4848
}
4949

50-
fun AmfEcmaArray(initialElements: Map<String, Any?>) =
50+
fun amfEcmaArrayOf(initialElements: Map<String, Any?>) =
5151
AmfEcmaArray().apply { putAll(initialElements) }
5252

53-
class AmfEcmaArray(private val elements: MutableMap<String, AmfElement> = mutableMapOf()) :
53+
class AmfEcmaArray internal constructor(private val elements: MutableMap<String, AmfElement> = mutableMapOf()) :
5454
AmfElement(), MutableMap<String, AmfElement> by elements {
5555
override val size0: Int
5656
get() {

amf/src/commonMain/kotlin/io/github/thibaultbee/krtmp/amf/elements/containers/AmfObject.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import kotlinx.io.Source
2626
import kotlinx.io.readString
2727
import kotlinx.io.writeString
2828

29-
fun Amf0Object(source: Source): AmfObject {
29+
fun amf0ObjectFrom(source: Source): AmfObject {
3030
val type = source.readByte()
3131
require(type == Amf0Type.OBJECT.value) { "Amf0Object cannot read buffer because it's not OBJECT type" }
3232

@@ -41,9 +41,10 @@ fun Amf0Object(source: Source): AmfObject {
4141
return amf0Object
4242
}
4343

44-
fun AmfObject(initialElements: Map<String, Any?>) = AmfObject().apply { putAll(initialElements) }
44+
fun amfObjectOf(initialElements: Map<String, Any?> = emptyMap()) =
45+
AmfObject().apply { putAll(initialElements) }
4546

46-
class AmfObject(private val elements: MutableMap<String, AmfElement> = mutableMapOf()) :
47+
class AmfObject internal constructor(private val elements: MutableMap<String, AmfElement> = mutableMapOf()) :
4748
AmfElement(), MutableMap<String, AmfElement> by elements {
4849
override val size0: Int
4950
get() {

amf/src/commonMain/kotlin/io/github/thibaultbee/krtmp/amf/elements/containers/AmfStrictArray.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import io.github.thibaultbee.krtmp.amf.elements.extensions.addAll
2222
import kotlinx.io.Sink
2323
import kotlinx.io.Source
2424

25-
fun Amf0StrictArray(source: Source): AmfStrictArray {
25+
fun amf0StrictArrayFrom(source: Source): AmfStrictArray {
2626
val type = source.readByte()
2727
require(type == Amf0Type.STRICT_ARRAY.value) { "Amf0StrictArray cannot read buffer because it's not STRICT_ARRAY type" }
2828

@@ -34,9 +34,9 @@ fun Amf0StrictArray(source: Source): AmfStrictArray {
3434
return amf0StrictArray
3535
}
3636

37-
fun AmfStrictArray(initialElements: List<Any?>) = AmfStrictArray().apply { addAll(initialElements) }
37+
fun amfStrictArrayOf(initialElements: List<Any?>) = AmfStrictArray().apply { addAll(initialElements) }
3838

39-
class AmfStrictArray(private val elements: MutableList<AmfElement> = mutableListOf()) :
39+
class AmfStrictArray internal constructor(private val elements: MutableList<AmfElement> = mutableListOf()) :
4040
AmfElement(), MutableList<AmfElement> by elements {
4141
override val size0: Int
4242
get() = 5 + elements.sumOf { it.size0 }

amf/src/commonMain/kotlin/io/github/thibaultbee/krtmp/amf/elements/primitives/AmfBoolean.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import io.github.thibaultbee.krtmp.amf.elements.AmfPrimitive
2121
import kotlinx.io.Sink
2222
import kotlinx.io.Source
2323

24-
fun Amf0Boolean(source: Source): AmfBoolean {
24+
fun amf0BooleanFrom(source: Source): AmfBoolean {
2525
val type = source.readByte()
2626
require(type == Amf0Type.BOOLEAN.value) { "Amf0Boolean cannot read buffer because it's not BOOLEAN type" }
2727
return AmfBoolean(source.readByte() == AMF0_TRUE)

amf/src/commonMain/kotlin/io/github/thibaultbee/krtmp/amf/elements/primitives/AmfDate.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import kotlinx.io.Source
2323
import kotlinx.io.readDouble
2424
import kotlinx.io.writeDouble
2525

26-
fun Amf0Date(source: Source): AmfDate {
26+
fun amf0DateFrom(source: Source): AmfDate {
2727
val type = source.readByte()
2828
require(type == Amf0Type.DATE.value) { "Amf0Date cannot read buffer because it's not DATE type" }
2929
return AmfDate(source.readDouble().toLong(), source.readShort())
3030
}
3131

32-
fun AmfDate(instant: Instant): AmfDate {
32+
fun amfDateOf(instant: Instant): AmfDate {
3333
return AmfDate(instant.toEpochMilliseconds(), 0)
3434
}
3535

amf/src/commonMain/kotlin/io/github/thibaultbee/krtmp/amf/elements/primitives/AmfInt.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import io.github.thibaultbee.krtmp.amf.elements.AmfPrimitive
1919
import kotlinx.io.Sink
2020

2121
class AmfInt(override val value: Int) : AmfPrimitive<Int>() {
22-
override val size0 = -1
22+
override val size0 = throw NotImplementedError("Int not supported in AMF0")
2323

2424
override val size3: Int
2525
get() {

amf/src/commonMain/kotlin/io/github/thibaultbee/krtmp/amf/elements/primitives/AmfNull.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import io.github.thibaultbee.krtmp.amf.elements.AmfElement
2020
import kotlinx.io.Sink
2121
import kotlinx.io.Source
2222

23-
fun Amf0Null(source: Source): AmfNull {
23+
fun amf0NullFrom(source: Source): AmfNull {
2424
val type = source.readByte()
2525
require(type == Amf0Type.NULL.value) { "Amf0Null cannot read buffer because it's not NULL type" }
2626
return AmfNull()
@@ -44,5 +44,5 @@ open class AmfNull : AmfElement() {
4444

4545
override fun toString() = "null"
4646

47-
companion object Default: AmfNull()
47+
companion object Default : AmfNull()
4848
}

0 commit comments

Comments
 (0)