-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from multiversx/TOOL-328-fix-explicit-enums
Add explicit enums implementation
- Loading branch information
Showing
15 changed files
with
329 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,33 @@ | ||
import { StringValue } from "../typesystem"; | ||
import { ExplicitEnumType, ExplicitEnumValue, ExplicitEnumVariantDefinition } from "../typesystem/explicit-enum"; | ||
import { StringBinaryCodec } from "./string"; | ||
|
||
export class ExplicitEnumBinaryCodec { | ||
private readonly stringCodec: StringBinaryCodec; | ||
|
||
constructor() { | ||
this.stringCodec = new StringBinaryCodec(); | ||
} | ||
|
||
decodeTopLevel(buffer: Buffer, type: ExplicitEnumType): ExplicitEnumValue { | ||
const stringValue = this.stringCodec.decodeTopLevel(buffer); | ||
return new ExplicitEnumValue(type, new ExplicitEnumVariantDefinition(stringValue.valueOf())); | ||
} | ||
|
||
decodeNested(buffer: Buffer, type: ExplicitEnumType): [ExplicitEnumValue, number] { | ||
const [value, length] = this.stringCodec.decodeNested(buffer); | ||
const enumValue = new ExplicitEnumValue(type, new ExplicitEnumVariantDefinition(value.valueOf())); | ||
|
||
return [enumValue, length]; | ||
} | ||
|
||
encodeNested(enumValue: ExplicitEnumValue): Buffer { | ||
const buffer = this.stringCodec.encodeNested(new StringValue(enumValue.valueOf().name)); | ||
return buffer; | ||
} | ||
|
||
encodeTopLevel(enumValue: ExplicitEnumValue): Buffer { | ||
const buffer = this.stringCodec.encodeTopLevel(new StringValue(enumValue.valueOf().name)); | ||
return buffer; | ||
} | ||
} |
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
Oops, something went wrong.