Skip to content

Commit a6defcc

Browse files
committed
Add RuleDump
1 parent 2f9d25f commit a6defcc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.github.binaryfoo.firewall.cp
2+
3+
import io.github.binaryfoo.firewall.cp.rules._
4+
5+
object RuleDump {
6+
def toString(rule: FwrValue, buf: StringBuilder = new StringBuilder(), indent: String = ""): String = {
7+
rule match {
8+
case FwrObject(tag, values) =>
9+
buf.append(indent).append("(").append(tag).append(":")
10+
values match {
11+
case List(v: FwrLiteral) => buf.append(" ").append(v)
12+
case List(v: FwrAddressRange) => buf.append(" ").append(v)
13+
case List(v: FwrTableRef) => buf.append(" ").append(v)
14+
case _ =>
15+
for (value <- values) {
16+
buf.append("\n")
17+
toString(value, buf, indent + " ")
18+
}
19+
}
20+
buf.append(")")
21+
case other =>
22+
buf.append(indent).append(rule)
23+
}
24+
buf.toString()
25+
}
26+
}

0 commit comments

Comments
 (0)