Created
March 20, 2020 06:34
-
-
Save hejfelix/6d77a999c7b4aa647e0dbf9e6a283f79 to your computer and use it in GitHub Desktop.
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
module Advertising = { | |
type byte = int; | |
type systemType = | |
| LEGO_WeDo_2_0 | |
| LEGO_Duplo | |
| LEGO_System_1 | |
| LEGO_System_2 | |
| UNKNOWN(byte); | |
let toByte: systemType => byte = | |
sysType => | |
switch (sysType) { | |
| LEGO_WeDo_2_0 => 0 | |
| LEGO_Duplo => 1 | |
| LEGO_System_1 => 2 | |
| LEGO_System_2 => 3 | |
| UNKNOWN(byte) => byte | |
}; | |
let fromByte: byte => systemType = | |
typeAndNumber => | |
typeAndNumber | |
->(land)(int_of_string("1110_0000b")) | |
->(lsr)(5) | |
->( | |
masked => | |
switch (masked) { | |
| 0 => LEGO_WeDo_2_0 | |
| 1 => LEGO_Duplo | |
| 2 => LEGO_System_1 | |
| 3 => LEGO_System_2 | |
| byte => UNKNOWN(byte) | |
} | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment