SlideShare a Scribd company logo
1 of 40
Download to read offline
Err....




          Quarks
          Preon
Preon




  A
declarative
data
binding
framework
for
binary

                    encoded
data
Binary Encoded Data?

Any
file
for
which

'file
‐bi
{filename}'

does

 not
return
a
mimetype
starting
with
'text/'


  Non‐binary:          Binary:
  text/plain
(*.txt)   application/pdf
(*.pdf)
  text/html
(*.html)   application/octet‐stream
(*.mp4)
  text/xml
(*.xml)     image/png
(*.png)
Not only byte stream

Always
octects
(8
bit
values)

             8
bits
                                
                                 8

                                   bi
                                      ts
                                        
But also bit stream

Always
octects
(8
bit
values)

         5
bits 5
b
                      its
Compressed Data




                  2
kg
                  1021
pages
Network Traffic
TomTom Map Files




Approx.
300
pages
of
C++
source
code,

  just
for
decoding
only...
Why?



  Binary
45.71%

                                          Non‐binary
54.29%




       Binary
vs.
non‐binary
distribution
on
a

          random
directory
on
my
system
Why?




          100%
           Binary
files
only




       ...and
on
my
wife's
system
Challenges
●   Decoding
from
bit
stream
not
for
the
faint‐hearted
●   Encoding
to
bit
stream
not
for
the
faint‐hearted
●   Hard
to
maintain
●   Hard
to
extend
●   Java
doesn't
help
(Bug
4504839)
●   Decoder
and
encoder
easily
go
out
of
sync
●   Documentation
and
software
easily
go
out
of
sync
What if....



  ..this could all be
     solved easily?
Preon Ambitions
●   Declaratively
map
data
structure
to
encoding

    format
●   Get
the
decoder/encoder/documentation,

    free
of
charge
5-Second User Guide

Decoding
a
BitMap:

01

File
file
=
new
File(...);
02

Codec<BitMap>
codec
=
Codecs.create(BitMap.class);
03

BitMap
bitmap
=
Codecs.decode(codec,
file);
What just happened?

       Create
a
Codec
for
instances
of
BitMap

01

File
file
=
new
File(...);
02

Codec<BitMap>
codec
=
Codecs.create(BitMap.class);
03

BitMap
bitmap
=
Codecs.decode(codec,
file);


       ...
and
use
it
to
decode
a
BitMap.
Find the specification

The
data
structure
IS
the
specification:
class
BitMap
{


@Bound
int
width;


@Bound
int
height;


@Bound
int
nrColors;


@BoundList(size=”nrColors”)
Color[];


@BoundList(size=”width*height”)
byte[]
pixels;
}

class
Color
{


@Bound
int
red;


@Bound
int
green;


@Bound
int
blue;
}
Demo Decoding
But what is actually happening?
                 Codec
is
nothing
but
a

                 facace
to
a
chain
of

                 Codecs.

                 Each
Codec
only

                 understands
its
own
task.

                 Codecs
will
delegate
to

                 other
Codecs
Codecs
Encapsulate
everything
there
is
to
know
about
the

  mapping
between
in‐memory
representation
and

  encoded
representation
Demo Documentation
So, now....




      Forget
everything
I
just
told
you
Preon just works

Annotations            Types
●   @Bound             int,
byte,
short,
long,
Integer,

●   @BoundList         Byte,
Short,
Long,
boolean,

●   @BoundString       Boolean,
String,
List<T>,
T[],

●   @BoundNumber       type‐safe
enums,

Object
●   @BoundObject
                       Expressions
●   @BoundExplicitly
●   @If
               attributes:
.{name}
●   @LazyLoading       items:
[{number}],
or
[{expr}]
●   @LengthPrefix      arithmetic:
+,
‐,
/,
*,
^
●   @TypePrefix        combinatorial:
&&,
||
●   @ByteAlign         relational:
>=,
<=,
==,
<,
>
●   @Slice             literals:
'foobar',
0x0f,
0b01101
Convention over Configuration
//
Default
settings
for
int
Codec:

//
32‐bits,
little
endian
@Bound
int
foo;

//
Read
an
int,
but
construct
the
int

//
from
5
bits
only
@BoundNumber(size=”5”)
int
foo;
Expressions (1)
/**

*
An
icon
of
maximal
15
*
15
pixels.
Each
color

*
has
a
color
in
the
range
0‐255.

*/
public
class
Icon
{
@BoundNumber(size=”4”)
int
height;
@BoundNumber(size=”4”)
int
width;
@BoundList(size=”height
*
width”)
byte[]
pixels;
}


              By
accepting
Strings
instead
of
booleans
and

         integers,
Preon
allows
you
to
pass
in
expressions.
Expressions (2)
@BoundString(size=”{expr}”,
...)
@BoundList(size=”{expr}”,
offset=”{expr}”,
...)
@BoundNumber(size=”{expr}”,
...)
@Slice(“{expr}”)
...
Boolean expressions
@Bound
private
int
mapVersion;

@If(“mapVersion
>=
700”)
@Bound

private
MapFlags
flags;

//
But
also:
//
mapVersion
+
1
>=
700
//
mapVersion
>
3
&&
mapVersion
<
300
//
etc.
References


                          Backward
references
only
                          Reference
the
“outer”
object




  addresses[1].street
  outer.driversLicenses[1].state
  driveresLicenses[nrDriverLicenses
‐
1].state
Variable Introductions

    @Bound
int[]
offsets;
    @BoundList(offset=”offsets[index]”,...)

      List<Node>
nodes;
                                                 Introduction
●   Preon
will
inject
List
implementation
●   List
implementation
will
load
Nodes
lazily,
on
demand
●   Calling
nodes.get(3)
will
cause
the
List
implementation
to
     –   Calculate
the
node's
position:
offsets[index=3]
=
120
     –   Call
Codec<Node>
to
start
decoding
from
that
point
Inheritance

 Java
Classes   Preon
Perspective
Codecs class is your friend
static <T> T decode(Codec<T> codec, byte[] buffer)
static <T> T decode(Codec<T> codec, ByteBuffer buffer)
static <T> T decode(Codec<T> codec, File file)

static <T> Codec<T> create(Class<T> type)
static <T> Codec<T> create(Class<T> type, CodecFactory...
  factories)
static <T> Codec<T> create(Class<T> type, CodecDecorator...
  decorators)

static <T> void document(Codec<T> codec, ArticleDocument
  document)
static <T> void document(Codec<T> codec, DocumentType type,
  OutputStream out)
static <T> void document(Codec<T> codec, DocumentType type, File
  file)
Preon Layers

                                      Data
binding



                                      A
fluent
interface
for

                                      generating
documents.
                                      (pecia.sourceforget.net)



                         An
expression
language
capable
of

BitBuffer
abstractions   rendering
itself
to
human
readable

                         text.
(limbo.sourceforge.net)
Preon License

                                         GPL
+
Classpath

                                         Exception


                                         Apache
2.0




                            Apache
2.0
GPL
+
Classpath
Exception
If not Preon, then what else?
Declarative
approach
is
not
new:
– BSDL
(Bitstream
Syntax
Description
Language)
– Flavor
(http://flavor.sourceforge.net/)
– XFlavor
– BFlavor
(http://multimedialab.elis.ugent.be/bflavor/)


None
of
them
would
worked
in
our
case:
– Overly
complicated
– No
solid
implementation
– Assumptions
are
surreal:
   ● “everything
will
just
fit
in
memory”

   ● “there
will
only
be
a
single
thread”

   ● “our
current
feature
set
is
all
you
ever
need”
The Preon Answer
“everything
will
just
fit
in
memory”
   Preon
is
capable
of
using
memory‐mapped
data.
(Default

     BitBuffer
implementation
wraps
around
ByteBuffer,
and

     hence
also
MappedByteBuffer.)
“there
will
only
be
a
single
thread”
   In
Preon,
every
thread
can
have
its
own
reference
to
the

     current
position
in
the
BitBuffer.
“our
current
feature
set
is
all
you
ever
need”
   Preon
has
incredibly
open:
implement
CodecFactory
or

     CodecDecorator
to
create
your
own
codecs
based
on
type

     information
or
annotations.
CodecFactory

             Annotations
on
the
object
expecting
data

             to
be
decoded
by
the
Codec.
interface CodecFactory {
<T> Codec<T> create(AnnotatedElement metadata,
                    Class<T> type,
                    ResolverContext context);
}


The
type
of
object
to
       The
object
for
constructing

be
decoded.                  references.


returns
null
if
it
does
not
have
a
way
to
construct
a
Codec
CodecFactory Usage
●   CodecFactories
can
be
passed
to
Codecs.create(...)
●   ...
which
will
cause
the
Codecs
class
to
consider

    these
factories
when
constructing
the
various

    Codecs.
●   Internally,
a
big
chain
of
commands
Current Status
●   http://preon.sourceforge.net/
●   Interfaces
fairly
stable
●   Current
version
1.0‐SNAPSHOT
●   Complete
Java
class
example
before
first
release

    candidate
●   Bugs...
●   I
want
you
Future work
●   The
encode
operation
(after
1.0)
●   Better
debugging
●   Annotation
driven
support
for
other
compression

    techniques
●   More
hyperlinking
in
the
documentation
●   Better
algebraic
simplification
of
expressions
●   Descriptions
from
JavaDoc
If there is only a couple of things...
●   XML
is
just
a
lame
way
of
binary
encoding
●   Preon
cuts
out
the
Infoset
model,
preventing

    unnecessary
transformations
●   Preon
makes
binary
encoding
easy
●   Preon
is
extensible
●   Preon
(probably)
scales
quite
well
●   Preon
is
friendly
to
Java
developers
Confused?

More Related Content

What's hot

javascript teach
javascript teachjavascript teach
javascript teach
guest3732fa
 
Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lv
Anton Arhipov
 

What's hot (14)

Java Programming Guide Quick Reference
Java Programming Guide Quick ReferenceJava Programming Guide Quick Reference
Java Programming Guide Quick Reference
 
Why rust?
Why rust?Why rust?
Why rust?
 
Quick Intro To JRuby
Quick Intro To JRubyQuick Intro To JRuby
Quick Intro To JRuby
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
 
The walking 0xDEAD
The walking 0xDEADThe walking 0xDEAD
The walking 0xDEAD
 
javascript teach
javascript teachjavascript teach
javascript teach
 
tictactoe groovy
tictactoe groovytictactoe groovy
tictactoe groovy
 
Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lv
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Object Calisthenics em Go
Object Calisthenics em GoObject Calisthenics em Go
Object Calisthenics em Go
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
 
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String MethodsPython Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String Methods
 
Book
BookBook
Book
 
Basic NLP with Python and NLTK
Basic NLP with Python and NLTKBasic NLP with Python and NLTK
Basic NLP with Python and NLTK
 

Similar to Preon (J-Fall 2008)

JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
guest3732fa
 
Generator Tricks for Systems Programmers
Generator Tricks for Systems ProgrammersGenerator Tricks for Systems Programmers
Generator Tricks for Systems Programmers
Hiroshi Ono
 
Fedora App Slide 2009 Hastac
Fedora App Slide 2009 HastacFedora App Slide 2009 Hastac
Fedora App Slide 2009 Hastac
Loretta Auvil
 
Adrian Weisberg Ajax World Presentation
Adrian Weisberg   Ajax World PresentationAdrian Weisberg   Ajax World Presentation
Adrian Weisberg Ajax World Presentation
rajivmordani
 
Microblogging via XMPP
Microblogging via XMPPMicroblogging via XMPP
Microblogging via XMPP
Stoyan Zhekov
 

Similar to Preon (J-Fall 2008) (20)

HA+DRBD+Postgres - PostgresWest '08
HA+DRBD+Postgres - PostgresWest '08HA+DRBD+Postgres - PostgresWest '08
HA+DRBD+Postgres - PostgresWest '08
 
Multiprocessing with python
Multiprocessing with pythonMultiprocessing with python
Multiprocessing with python
 
HTML Parsing With Hpricot
HTML Parsing With HpricotHTML Parsing With Hpricot
HTML Parsing With Hpricot
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
 
Yakov Fain - Design Patterns a Deep Dive
Yakov Fain - Design Patterns a Deep DiveYakov Fain - Design Patterns a Deep Dive
Yakov Fain - Design Patterns a Deep Dive
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
Generator Tricks for Systems Programmers
Generator Tricks for Systems ProgrammersGenerator Tricks for Systems Programmers
Generator Tricks for Systems Programmers
 
The Tantric Team: Getting Your Automated Build Groove On
The Tantric Team: Getting Your Automated Build Groove OnThe Tantric Team: Getting Your Automated Build Groove On
The Tantric Team: Getting Your Automated Build Groove On
 
Pc54
Pc54Pc54
Pc54
 
Fedora App Slide 2009 Hastac
Fedora App Slide 2009 HastacFedora App Slide 2009 Hastac
Fedora App Slide 2009 Hastac
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
 
sysprog1
sysprog1sysprog1
sysprog1
 
Peer Code Review: In a Nutshell and The Tantric Team: Getting Your Automated ...
Peer Code Review: In a Nutshell and The Tantric Team: Getting Your Automated ...Peer Code Review: In a Nutshell and The Tantric Team: Getting Your Automated ...
Peer Code Review: In a Nutshell and The Tantric Team: Getting Your Automated ...
 
High-Octane Dev Teams: Three Things You Can Do To Improve Code Quality
High-Octane Dev Teams: Three Things You Can Do To Improve Code QualityHigh-Octane Dev Teams: Three Things You Can Do To Improve Code Quality
High-Octane Dev Teams: Three Things You Can Do To Improve Code Quality
 
Streaming huge databases using logical decoding
Streaming huge databases using logical decodingStreaming huge databases using logical decoding
Streaming huge databases using logical decoding
 
Adrian Weisberg Ajax World Presentation
Adrian Weisberg   Ajax World PresentationAdrian Weisberg   Ajax World Presentation
Adrian Weisberg Ajax World Presentation
 
XS Boston 2008 Network Topology
XS Boston 2008 Network TopologyXS Boston 2008 Network Topology
XS Boston 2008 Network Topology
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Development
 
Genome Browser
Genome BrowserGenome Browser
Genome Browser
 
Microblogging via XMPP
Microblogging via XMPPMicroblogging via XMPP
Microblogging via XMPP
 

More from Wilfred Springer (12)

Unfiltered Unveiled
Unfiltered UnveiledUnfiltered Unveiled
Unfiltered Unveiled
 
Scala in your organisation
Scala in your organisationScala in your organisation
Scala in your organisation
 
Simplicity
SimplicitySimplicity
Simplicity
 
Unfiltered Unveiled
Unfiltered UnveiledUnfiltered Unveiled
Unfiltered Unveiled
 
Mongo
MongoMongo
Mongo
 
NoSQL
NoSQLNoSQL
NoSQL
 
NoSQL Rollercoaster
NoSQL RollercoasterNoSQL Rollercoaster
NoSQL Rollercoaster
 
Byzantine Generals
Byzantine GeneralsByzantine Generals
Byzantine Generals
 
Eventually Consistent
Eventually ConsistentEventually Consistent
Eventually Consistent
 
Into the Wild
Into the WildInto the Wild
Into the Wild
 
Spring ME JavaOne
Spring ME JavaOneSpring ME JavaOne
Spring ME JavaOne
 
Spring ME
Spring MESpring ME
Spring ME
 

Recently uploaded

Recently uploaded (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Preon (J-Fall 2008)