Skip to content

Commit

Permalink
GoCompiler: add kaitai.Struct interface support
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyCat committed Mar 31, 2024
1 parent 15959f0 commit bcf8724
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions shared/src/main/scala/io/kaitai/struct/languages/GoCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class GoCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.dec
out.puts("}")
universalFooter

ioAccessor()
}

override def classConstructorFooter: Unit = {}
Expand Down Expand Up @@ -568,6 +570,15 @@ class GoCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.dec
out.puts("}")
}

def ioAccessor(): Unit = {
out.puts
out.puts(s"func (this ${types2class(typeProvider.nowClass.name)}) IO_() *$kstreamName {")
out.inc
out.puts(s"return this._io")
out.dec
out.puts("}")
}
}

object GoCompiler extends LanguageCompilerStatic
Expand Down Expand Up @@ -631,7 +642,7 @@ object GoCompiler extends LanguageCompilerStatic

case AnyType => "interface{}"
case KaitaiStructType | CalcKaitaiStructType(_) => kstructName
case KaitaiStreamType | OwnedKaitaiStreamType => "*" + kstreamName
case KaitaiStreamType | OwnedKaitaiStreamType => s"*$kstreamName"

case t: UserType => "*" + types2class(t.classSpec match {
case Some(cs) => cs.name
Expand All @@ -657,7 +668,7 @@ object GoCompiler extends LanguageCompilerStatic
types2class(typeName) + "__" + type2class(enumName)

override def kstreamName: String = "kaitai.Stream"
override def kstructName: String = "interface{}"
override def kstructName: String = "kaitai.Struct"
override def ksErrorName(err: KSError): String = err match {
case ConversionError => "strconv.NumError"
case _ => s"kaitai.${err.name}"
Expand Down

0 comments on commit bcf8724

Please sign in to comment.