-
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.
- Loading branch information
1 parent
3b42356
commit 19a25a3
Showing
12 changed files
with
308 additions
and
54 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 |
---|---|---|
@@ -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.