Skip to content

Commit e676e5a

Browse files
author
Dr. Brandon Wiley
committed
Some symbols have been ported to the new interface
1 parent f45494a commit e676e5a

File tree

4 files changed

+101
-103
lines changed

4 files changed

+101
-103
lines changed

Codex/src/main/java/org/operatorfoundation/codex/symbols/Binary.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Binary : Symbol {
88
}
99

1010
override fun decode(encodedValue: ByteArray): Int {
11-
return when (encodedValue) {
11+
return when (encodedValue.decodeToString()) {
1212
"0" -> 0
1313
"1" -> 1
1414
else -> throw IllegalArgumentException("Binary, bad value $encodedValue")
@@ -17,8 +17,8 @@ class Binary : Symbol {
1717

1818
override fun encode(numericValue: Int): ByteArray {
1919
return when (numericValue) {
20-
0 -> "0"
21-
1 -> "1"
20+
0 -> "0".toByteArray()
21+
1 -> "1".toByteArray()
2222
else -> throw IllegalArgumentException("Unknown value $numericValue for Binary")
2323
}
2424
}

Codex/src/main/java/org/operatorfoundation/codex/symbols/Byte.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@ class Byte : Symbol {
1212
if (numericValue < 0 || numericValue > 255) {
1313
throw Exception("Invalid value $numericValue for Byte (must be 0-255)")
1414
}
15-
return numericValue.toChar().toString()
15+
return numericValue.toChar().toString().toByteArray()
1616
}
1717

1818
override fun decode(encodedValue: ByteArray): Int {
19-
val value = when (encodedValue) {
20-
is Int -> encodedValue
21-
is kotlin.Byte -> encodedValue.toInt() and 0xFF // Handle signed bytes properly
22-
is Char -> encodedValue.code // ASCII value of character
23-
else -> throw Exception("Invalid type for Byte decode: ${encodedValue::class}")
19+
if (encodedValue.size != 1)
20+
{
21+
throw Exception("Too many bytes")
2422
}
25-
if (value < 0 || value > 255) {
26-
throw Exception("Invalid value $value for Byte (must be 0-255)")
27-
}
28-
return value
23+
24+
return encodedValue[0].toInt()
2925
}
3026
}
Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
package org.operatorfoundation.codex.Symbols
1+
package org.operatorfoundation.codex.symbols
22

3-
class CallAny {
4-
val length: Int
5-
get() = 26 + 10 + 1
3+
class CallAny : Symbol {
4+
override fun size(): Int {
5+
return 26 + 10 + 1
6+
}
67

78
override fun toString(): String {
89
return "CallAny"
910
}
1011

11-
fun decode(n: ByteArray): Int {
12-
return when (n) {
12+
override fun decode(encodedValue: ByteArray): Int {
13+
return when (encodedValue.toString()) {
1314
"A" -> 0
1415
"B" -> 1
1516
"C" -> 2
@@ -47,50 +48,50 @@ class CallAny {
4748
"8" -> 34
4849
"9" -> 35
4950
" " -> 36
50-
else -> throw IllegalArgumentException("CallAny, bad value: $n")
51+
else -> throw IllegalArgumentException("CallAny, bad value: $encodedValue")
5152
}
5253
}
5354

54-
fun encode(n: Int): ByteArray {
55-
return when (n) {
56-
0 -> "A"
57-
1 -> "B"
58-
2 -> "C"
59-
3 -> "D"
60-
4 -> "E"
61-
5 -> "F"
62-
6 -> "G"
63-
7 -> "H"
64-
8 -> "I"
65-
9 -> "J"
66-
10 -> "K"
67-
11 -> "L"
68-
12 -> "M"
69-
13 -> "N"
70-
14 -> "O"
71-
15 -> "P"
72-
16 -> "Q"
73-
17 -> "R"
74-
18 -> "S"
75-
19 -> "T"
76-
20 -> "U"
77-
21 -> "V"
78-
22 -> "W"
79-
23 -> "X"
80-
24 -> "Y"
81-
25 -> "Z"
82-
26 -> "0"
83-
27 -> "1"
84-
28 -> "2"
85-
29 -> "3"
86-
30 -> "4"
87-
31 -> "5"
88-
32 -> "6"
89-
33 -> "7"
90-
34 -> "8"
91-
35 -> "9"
92-
36 -> " "
93-
else -> throw IllegalArgumentException("Unknown value $n for CallAny")
55+
override fun encode(numericValue: Int): ByteArray {
56+
return when (numericValue) {
57+
0 -> "A".toByteArray()
58+
1 -> "B".toByteArray()
59+
2 -> "C".toByteArray()
60+
3 -> "D".toByteArray()
61+
4 -> "E".toByteArray()
62+
5 -> "F".toByteArray()
63+
6 -> "G".toByteArray()
64+
7 -> "H".toByteArray()
65+
8 -> "I".toByteArray()
66+
9 -> "J".toByteArray()
67+
10 -> "K".toByteArray()
68+
11 -> "L".toByteArray()
69+
12 -> "M".toByteArray()
70+
13 -> "N".toByteArray()
71+
14 -> "O".toByteArray()
72+
15 -> "P".toByteArray()
73+
16 -> "Q".toByteArray()
74+
17 -> "R".toByteArray()
75+
18 -> "S".toByteArray()
76+
19 -> "T".toByteArray()
77+
20 -> "U".toByteArray()
78+
21 -> "V".toByteArray()
79+
22 -> "W".toByteArray()
80+
23 -> "X".toByteArray()
81+
24 -> "Y".toByteArray()
82+
25 -> "Z".toByteArray()
83+
26 -> "0".toByteArray()
84+
27 -> "1".toByteArray()
85+
28 -> "2".toByteArray()
86+
29 -> "3".toByteArray()
87+
30 -> "4".toByteArray()
88+
31 -> "5".toByteArray()
89+
32 -> "6".toByteArray()
90+
33 -> "7".toByteArray()
91+
34 -> "8".toByteArray()
92+
35 -> "9".toByteArray()
93+
36 -> " ".toByteArray()
94+
else -> throw IllegalArgumentException("Unknown value $numericValue for CallAny")
9495
}
9596
}
9697
}

Codex/src/main/java/org/operatorfoundation/codex/symbols/CallLetterNumber.kt

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
package org.operatorfoundation.codex.Symbols
1+
package org.operatorfoundation.codex.symbols
22

3-
class CallLetterNumber {
4-
val length: Int
5-
get() = 26 + 10
3+
class CallLetterNumber : Symbol {
4+
override fun size(): Int {
5+
return 26 + 10
6+
}
67

78
override fun toString(): String {
89
return "CallLetterNumber"
910
}
1011

11-
fun decode(n: ByteArray): Int {
12-
return when (n) {
12+
override fun decode(n: ByteArray): Int {
13+
return when (n.toString()) {
1314
"A" -> 0
1415
"B" -> 1
1516
"C" -> 2
@@ -50,44 +51,44 @@ class CallLetterNumber {
5051
}
5152
}
5253

53-
fun encode(n: Int): ByteArray {
54+
override fun encode(n: Int): ByteArray {
5455
return when (n) {
55-
0 -> "A"
56-
1 -> "B"
57-
2 -> "C"
58-
3 -> "D"
59-
4 -> "E"
60-
5 -> "F"
61-
6 -> "G"
62-
7 -> "H"
63-
8 -> "I"
64-
9 -> "J"
65-
10 -> "K"
66-
11 -> "L"
67-
12 -> "M"
68-
13 -> "N"
69-
14 -> "O"
70-
15 -> "P"
71-
16 -> "Q"
72-
17 -> "R"
73-
18 -> "S"
74-
19 -> "T"
75-
20 -> "U"
76-
21 -> "V"
77-
22 -> "W"
78-
23 -> "X"
79-
24 -> "Y"
80-
25 -> "Z"
81-
26 -> "0"
82-
27 -> "1"
83-
28 -> "2"
84-
29 -> "3"
85-
30 -> "4"
86-
31 -> "5"
87-
32 -> "6"
88-
33 -> "7"
89-
34 -> "8"
90-
35 -> "9"
56+
0 -> "A".toByteArray()
57+
1 -> "B".toByteArray()
58+
2 -> "C".toByteArray()
59+
3 -> "D".toByteArray()
60+
4 -> "E".toByteArray()
61+
5 -> "F".toByteArray()
62+
6 -> "G".toByteArray()
63+
7 -> "H".toByteArray()
64+
8 -> "I".toByteArray()
65+
9 -> "J".toByteArray()
66+
10 -> "K".toByteArray()
67+
11 -> "L".toByteArray()
68+
12 -> "M".toByteArray()
69+
13 -> "N".toByteArray()
70+
14 -> "O".toByteArray()
71+
15 -> "P".toByteArray()
72+
16 -> "Q".toByteArray()
73+
17 -> "R".toByteArray()
74+
18 -> "S".toByteArray()
75+
19 -> "T".toByteArray()
76+
20 -> "U".toByteArray()
77+
21 -> "V".toByteArray()
78+
22 -> "W".toByteArray()
79+
23 -> "X".toByteArray()
80+
24 -> "Y".toByteArray()
81+
25 -> "Z".toByteArray()
82+
26 -> "0".toByteArray()
83+
27 -> "1".toByteArray()
84+
28 -> "2".toByteArray()
85+
29 -> "3".toByteArray()
86+
30 -> "4".toByteArray()
87+
31 -> "5".toByteArray()
88+
32 -> "6".toByteArray()
89+
33 -> "7".toByteArray()
90+
34 -> "8".toByteArray()
91+
35 -> "9".toByteArray()
9192
else -> throw IllegalArgumentException("Unknown value $n for CallLetterNumber")
9293
}
9394
}

0 commit comments

Comments
 (0)