Last active
October 16, 2015 23:05
-
-
Save edefazio/494b92ceae3dad0e7435 to your computer and use it in GitHub Desktop.
TypeFrame data vectorization using Types, Fields, and Frames
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
import typeframe.api.Fields; | |
import typeframe.frame.bitwise.BitFrame; | |
import typeframe.type.ByteType; | |
public class Types_Fields_Frames | |
{ | |
public static ByteType COMPONENT = | |
ByteType.INSTANCE; | |
public static final BitFrame RGBColorFrame = | |
BitFrame.of( "RGB (Red Green Blue) Color Frame", | |
Fields.of( "Red", COMPONENT ), | |
Fields.of( "Green", COMPONENT ), | |
Fields.of( "Blue", COMPONENT ) | |
); | |
public static void main (String[] args) | |
{ | |
//this will print out the structure of the Frame | |
//System.out.println ( RGBColorFrame ); | |
//create a vectorized "compound" of data | |
long red = RGBColorFrame.pack( 255, 0, 0 ); | |
System.out.println ( RGBColorFrame.describe( red ) ); | |
/* | |
----------------------------------------111111110000000000000000 [16711680] (24-bits) | |
11111111 Red[255]->255 (8-bits) | |
00000000 Green[0]->0 (8-bits) | |
00000000 Blue[0]->0 (8-bits) | |
*/ | |
//read a single field within the compound | |
byte blueComponent = (Byte)RGBColorFrame.read( "Blue", red ); | |
// update a single field within the compound | |
long redGreen = RGBColorFrame.update( "Green", 255, red ); | |
//unpack the entire compound to an array | |
Byte[] components = new Byte[3]; | |
RGBColorFrame.getUnpacker().asFormsTo( red, components, 0 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeFrame defines {@code Type}s, {@code Field}s and {@code Frame}s for "vectorizing" data.
Data that is vectorized within a word is called a "compound".
(i.e. a {@code BoolType} has (2) states {false, true} represented in (1) bit as either a [0] or [1])
...To use TypeFrame:
TypeFrame precisely defines HOW data is assigned to bits within a word, and
saves developers from writing tedious manual bit-shifting and masking operations.
(which can be error-prone and "ugly").