forked from SandroGrzicic/ScalaBuff
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Importing a fully qualified enum doesn't work SandroGrzicic#109
- Loading branch information
Showing
10 changed files
with
203 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
scalabuff-compiler/src/test/resources/generated/ImportEnum.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Generated by ScalaBuff, the Scala Protocol Buffers compiler. DO NOT EDIT! | ||
// source: import_enum.proto | ||
|
||
package resources.generated | ||
|
||
//import "enum_to_import.proto" | ||
|
||
final case class AnImportEnumMessage ( | ||
`toImport`: resources.generated.nested.AnEnumToImport.EnumVal = resources.generated.nested.AnEnumToImport._UNINITIALIZED | ||
) extends com.google.protobuf.GeneratedMessageLite | ||
with com.google.protobuf.MessageLite.Builder | ||
with net.sandrogrzicic.scalabuff.Message[AnImportEnumMessage] | ||
with net.sandrogrzicic.scalabuff.Parser[AnImportEnumMessage] { | ||
|
||
|
||
|
||
def writeTo(output: com.google.protobuf.CodedOutputStream) { | ||
output.writeEnum(1, `toImport`) | ||
} | ||
|
||
def getSerializedSize = { | ||
import com.google.protobuf.CodedOutputStream._ | ||
var __size = 0 | ||
__size += computeEnumSize(1, `toImport`) | ||
|
||
__size | ||
} | ||
|
||
def mergeFrom(in: com.google.protobuf.CodedInputStream, extensionRegistry: com.google.protobuf.ExtensionRegistryLite): AnImportEnumMessage = { | ||
import com.google.protobuf.ExtensionRegistryLite.{getEmptyRegistry => _emptyRegistry} | ||
var __toImport: resources.generated.nested.AnEnumToImport.EnumVal = resources.generated.nested.AnEnumToImport._UNINITIALIZED | ||
|
||
def __newMerged = AnImportEnumMessage( | ||
__toImport | ||
) | ||
while (true) in.readTag match { | ||
case 0 => return __newMerged | ||
case 8 => __toImport = resources.generated.nested.AnEnumToImport.valueOf(in.readEnum()) | ||
case default => if (!in.skipField(default)) return __newMerged | ||
} | ||
null | ||
} | ||
|
||
def mergeFrom(m: AnImportEnumMessage) = { | ||
AnImportEnumMessage( | ||
m.`toImport` | ||
) | ||
} | ||
|
||
def getDefaultInstanceForType = AnImportEnumMessage.defaultInstance | ||
def clear = getDefaultInstanceForType | ||
def isInitialized = true | ||
def build = this | ||
def buildPartial = this | ||
def parsePartialFrom(cis: com.google.protobuf.CodedInputStream, er: com.google.protobuf.ExtensionRegistryLite) = mergeFrom(cis, er) | ||
override def getParserForType = this | ||
def newBuilderForType = getDefaultInstanceForType | ||
def toBuilder = this | ||
def toJson(indent: Int = 0): String = { | ||
val indent0 = "\n" + ("\t" * indent) | ||
val (indent1, indent2) = (indent0 + "\t", indent0 + "\t\t") | ||
val sb = StringBuilder.newBuilder | ||
sb | ||
.append("{") | ||
sb.append(indent1).append("\"toImport\": ").append("\"").append(`toImport`).append("\"").append(',') | ||
if (sb.last.equals(',')) sb.length -= 1 | ||
sb.append(indent0).append("}") | ||
sb.toString() | ||
} | ||
|
||
} | ||
|
||
object AnImportEnumMessage { | ||
@scala.beans.BeanProperty val defaultInstance = new AnImportEnumMessage() | ||
|
||
def parseFrom(data: Array[Byte]): AnImportEnumMessage = defaultInstance.mergeFrom(data) | ||
def parseFrom(data: Array[Byte], offset: Int, length: Int): AnImportEnumMessage = defaultInstance.mergeFrom(data, offset, length) | ||
def parseFrom(byteString: com.google.protobuf.ByteString): AnImportEnumMessage = defaultInstance.mergeFrom(byteString) | ||
def parseFrom(stream: java.io.InputStream): AnImportEnumMessage = defaultInstance.mergeFrom(stream) | ||
def parseDelimitedFrom(stream: java.io.InputStream): Option[AnImportEnumMessage] = defaultInstance.mergeDelimitedFromStream(stream) | ||
|
||
val TO_IMPORT_FIELD_NUMBER = 1 | ||
|
||
def newBuilder = defaultInstance.newBuilderForType | ||
def newBuilder(prototype: AnImportEnumMessage) = defaultInstance.mergeFrom(prototype) | ||
|
||
} | ||
|
||
object ImportEnum { | ||
def registerAllExtensions(registry: com.google.protobuf.ExtensionRegistryLite) { | ||
} | ||
|
||
private val fromBinaryHintMap = collection.immutable.HashMap[String, Array[Byte] ⇒ com.google.protobuf.GeneratedMessageLite]( | ||
"AnImportEnumMessage" -> (bytes ⇒ AnImportEnumMessage.parseFrom(bytes)) | ||
) | ||
|
||
def deserializePayload(payload: Array[Byte], payloadType: String): com.google.protobuf.GeneratedMessageLite = { | ||
fromBinaryHintMap.get(payloadType) match { | ||
case Some(f) ⇒ f(payload) | ||
case None ⇒ throw new IllegalArgumentException(s"unimplemented deserialization of message payload of type [${payloadType}]") | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
scalabuff-compiler/src/test/resources/generated/nested/EnumToImport.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Generated by ScalaBuff, the Scala Protocol Buffers compiler. DO NOT EDIT! | ||
// source: enum_to_import.proto | ||
|
||
package resources.generated.nested | ||
|
||
object AnEnumToImport extends net.sandrogrzicic.scalabuff.Enum { | ||
sealed trait EnumVal extends Value | ||
val _UNINITIALIZED = new EnumVal { val name = "UNINITIALIZED ENUM VALUE"; val id = -1 } | ||
|
||
val KEYBOARD = new EnumVal { val name = "KEYBOARD"; val id = 1 } | ||
val MOUSE = new EnumVal { val name = "MOUSE"; val id = 2 } | ||
|
||
val KEYBOARD_VALUE = 1 | ||
val MOUSE_VALUE = 2 | ||
|
||
def valueOf(id: Int) = id match { | ||
case 1 => KEYBOARD | ||
case 2 => MOUSE | ||
case _default => throw new net.sandrogrzicic.scalabuff.UnknownEnumException(_default) | ||
} | ||
val internalGetValueMap = new com.google.protobuf.Internal.EnumLiteMap[EnumVal] { | ||
def findValueByNumber(id: Int): EnumVal = valueOf(id) | ||
} | ||
} | ||
|
||
object EnumToImport { | ||
def registerAllExtensions(registry: com.google.protobuf.ExtensionRegistryLite) { | ||
} | ||
|
||
private val fromBinaryHintMap = collection.immutable.HashMap[String, Array[Byte] ⇒ com.google.protobuf.GeneratedMessageLite]( | ||
|
||
) | ||
|
||
def deserializePayload(payload: Array[Byte], payloadType: String): com.google.protobuf.GeneratedMessageLite = { | ||
fromBinaryHintMap.get(payloadType) match { | ||
case Some(f) ⇒ f(payload) | ||
case None ⇒ throw new IllegalArgumentException(s"unimplemented deserialization of message payload of type [${payloadType}]") | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
scalabuff-compiler/src/test/resources/generated/other/EnumToImport.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Generated by ScalaBuff, the Scala Protocol Buffers compiler. DO NOT EDIT! | ||
// source: enum_to_import.proto | ||
|
||
package resources.generated.other | ||
|
||
object AnEnumToImport extends net.sandrogrzicic.scalabuff.Enum { | ||
sealed trait EnumVal extends Value | ||
val _UNINITIALIZED = new EnumVal { val name = "UNINITIALIZED ENUM VALUE"; val id = -1 } | ||
|
||
val KEYBOARD = new EnumVal { val name = "KEYBOARD"; val id = 1 } | ||
val MOUSE = new EnumVal { val name = "MOUSE"; val id = 2 } | ||
|
||
val KEYBOARD_VALUE = 1 | ||
val MOUSE_VALUE = 2 | ||
|
||
def valueOf(id: Int) = id match { | ||
case 1 => KEYBOARD | ||
case 2 => MOUSE | ||
case _default => throw new net.sandrogrzicic.scalabuff.UnknownEnumException(_default) | ||
} | ||
val internalGetValueMap = new com.google.protobuf.Internal.EnumLiteMap[EnumVal] { | ||
def findValueByNumber(id: Int): EnumVal = valueOf(id) | ||
} | ||
} | ||
|
||
object EnumToImport { | ||
def registerAllExtensions(registry: com.google.protobuf.ExtensionRegistryLite) { | ||
} | ||
|
||
private val fromBinaryHintMap = collection.immutable.HashMap[String, Array[Byte] ⇒ com.google.protobuf.GeneratedMessageLite]( | ||
|
||
) | ||
|
||
def deserializePayload(payload: Array[Byte], payloadType: String): com.google.protobuf.GeneratedMessageLite = { | ||
fromBinaryHintMap.get(payloadType) match { | ||
case Some(f) ⇒ f(payload) | ||
case None ⇒ throw new IllegalArgumentException(s"unimplemented deserialization of message payload of type [${payloadType}]") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
List(PackageStatement(resources.generated.nested), EnumStatement(AnEnumToImport,List(EnumConstant(KEYBOARD,1), EnumConstant(MOUSE,2)),List())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
List(PackageStatement(resources.generated), ImportStatement("enum_to_import.proto"), Message(AnImportEnumMessage,MessageBody(List(Field(required,resources.generated.nested.AnEnumToImport,to_import,1,List(),)),List(),List(),List(),List(),List(),List()))) |
6 changes: 6 additions & 0 deletions
6
scalabuff-compiler/src/test/resources/proto/enum_to_import.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package resources.generated.nested; | ||
|
||
enum AnEnumToImport { | ||
KEYBOARD = 1; | ||
MOUSE = 2; | ||
} |
7 changes: 7 additions & 0 deletions
7
scalabuff-compiler/src/test/resources/proto/import_enum.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package resources.generated; | ||
|
||
import "enum_to_import.proto"; | ||
|
||
message AnImportEnumMessage { | ||
required resources.generated.nested.AnEnumToImport to_import = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters