-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rust: Enum names not only numbers (#202)
* Rust: Enum names not only numbers * fix
- Loading branch information
1 parent
ffe4ba5
commit dda3c5e
Showing
17 changed files
with
716 additions
and
68 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
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 |
---|---|---|
|
@@ -33,4 +33,10 @@ enum Color2 { | |
RED2=RED, | ||
GREEN2=1, | ||
BLUE2=2 | ||
}; | ||
}; | ||
|
||
enum Color3 { | ||
RED_1=1, | ||
RED_2_TWO=2, | ||
RED_3=3 | ||
}; |
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
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,61 @@ | ||
// Automatically generated by xdrgen | ||
// DO NOT EDIT or your changes may be overwritten | ||
|
||
package MyXDR; | ||
|
||
import java.io.IOException; | ||
|
||
import org.stellar.sdk.Base64Factory; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
|
||
/** | ||
* Color3's original definition in the XDR file is: | ||
* <pre> | ||
* enum Color3 { | ||
* RED_1=1, | ||
* RED_2_TWO=2, | ||
* RED_3=3 | ||
* }; | ||
* </pre> | ||
*/ | ||
public enum Color3 implements XdrElement { | ||
RED_1(1), | ||
RED_2_TWO(2), | ||
RED_3(3); | ||
|
||
private final int value; | ||
|
||
Color3(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
|
||
public static Color3 decode(XdrDataInputStream stream) throws IOException { | ||
int value = stream.readInt(); | ||
switch (value) { | ||
case 1: return RED_1; | ||
case 2: return RED_2_TWO; | ||
case 3: return RED_3; | ||
default: | ||
throw new IllegalArgumentException("Unknown enum value: " + value); | ||
} | ||
} | ||
|
||
public void encode(XdrDataOutputStream stream) throws IOException { | ||
stream.writeInt(value); | ||
} | ||
public static Color3 fromXdrBase64(String xdr) throws IOException { | ||
byte[] bytes = Base64Factory.getInstance().decode(xdr); | ||
return fromXdrByteArray(bytes); | ||
} | ||
|
||
public static Color3 fromXdrByteArray(byte[] xdr) throws IOException { | ||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); | ||
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); | ||
return decode(xdrDataInputStream); | ||
} | ||
} |
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
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,50 @@ | ||
# This is an automatically generated file. | ||
# DO NOT EDIT or your changes may be overwritten | ||
from __future__ import annotations | ||
|
||
import base64 | ||
from enum import IntEnum | ||
from typing import List, Optional, TYPE_CHECKING | ||
from xdrlib3 import Packer, Unpacker | ||
from .base import Integer, UnsignedInteger, Float, Double, Hyper, UnsignedHyper, Boolean, String, Opaque | ||
from .constants import * | ||
|
||
__all__ = ['Color3'] | ||
class Color3(IntEnum): | ||
""" | ||
XDR Source Code:: | ||
enum Color3 { | ||
RED_1=1, | ||
RED_2_TWO=2, | ||
RED_3=3 | ||
}; | ||
""" | ||
RED_1 = 1 | ||
RED_2_TWO = 2 | ||
RED_3 = 3 | ||
def pack(self, packer: Packer) -> None: | ||
packer.pack_int(self.value) | ||
|
||
@classmethod | ||
def unpack(cls, unpacker: Unpacker) -> Color3: | ||
value = unpacker.unpack_int() | ||
return cls(value) | ||
def to_xdr_bytes(self) -> bytes: | ||
packer = Packer() | ||
self.pack(packer) | ||
return packer.get_buffer() | ||
|
||
@classmethod | ||
def from_xdr_bytes(cls, xdr: bytes) -> Color3: | ||
unpacker = Unpacker(xdr) | ||
return cls.unpack(unpacker) | ||
|
||
def to_xdr(self) -> str: | ||
xdr_bytes = self.to_xdr_bytes() | ||
return base64.b64encode(xdr_bytes).decode() | ||
|
||
@classmethod | ||
def from_xdr(cls, xdr: str) -> Color3: | ||
xdr_bytes = base64.b64decode(xdr.encode()) | ||
return cls.from_xdr_bytes(xdr_bytes) |
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
autoload :MessageType | ||
autoload :Color | ||
autoload :Color2 | ||
autoload :Color3 |
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,21 @@ | ||
# This code was automatically generated using xdrgen | ||
# DO NOT EDIT or your changes may be overwritten | ||
|
||
require 'xdr' | ||
|
||
# === xdr source ============================================================ | ||
# | ||
# enum Color3 { | ||
# RED_1=1, | ||
# RED_2_TWO=2, | ||
# RED_3=3 | ||
# }; | ||
# | ||
# =========================================================================== | ||
class Color3 < XDR::Enum | ||
member :red_1, 1 | ||
member :red_2_two, 2 | ||
member :red_3, 3 | ||
|
||
seal | ||
end |
Oops, something went wrong.