1212 * Interface with the librapidyaml shared library
1313 */
1414public class Rapidyaml {
15- public static String RAPIDYAML_NAME = "rapidyaml .0.8 .0" ;
16- public static String RAPIDYAML_LIBNAME = "librapidyaml .0.8 .0.so" ;
15+ public static String RAPIDYAML_NAME = "ysparse .0.9 .0" ;
16+ public static String RAPIDYAML_LIBNAME = "ysparse .0.9 .0.so" ;
1717
18+ private final long ysparse ; ///< pointer to the c++ object
1819 private native long ysparse_init ();
1920 private native void ysparse_destroy (long ysparse );
2021 private native void ysparse_timing_set (boolean yes );
21- private native int ysparse_parse (
22- long ysparse , String filename ,
23- byte [] ys , int ys_length ,
24- int [] evt , int evt_length );
25- private native int ysparse_parse_buf (
26- long ysparse , String filename ,
27- ByteBuffer ys , int ys_length ,
28- IntBuffer evt , int evt_length );
29- private final long ysparse ;
30-
22+ private native boolean ysparse_parse (long ysparse , String filename ,
23+ byte [] ys , int ys_length ,
24+ byte [] arena , int arena_length ,
25+ int [] evt , int evt_length );
26+ private native boolean ysparse_parse_buf (long ysparse , String filename ,
27+ ByteBuffer ys , int ys_length ,
28+ ByteBuffer arena , int arena_length ,
29+ IntBuffer evt , int evt_length );
30+ private native int ysparse_reqsize_evt ( long ysparse ) ;
31+ private native int ysparse_reqsize_arena ( long ysparse );
3132
3233
3334 // XXX this 'main' is for testing
@@ -72,34 +73,32 @@ public Rapidyaml() throws Exception, IOException {
7273 // EVT
7374 //------------------------
7475
75- public int parseYsToEvt (
76- byte [] src , int [] evts
77- ) throws Exception {
78- return parseYsToEvt ("yamlscript" , src , evts );
76+ public boolean parseYs (byte [] src , byte [] arena , int [] evts ) throws Exception
77+ {
78+ return parseYs ("yamlscript" , src , arena , evts );
7979 }
8080
81- public int parseYsToEvtBuf (
82- ByteBuffer src , IntBuffer evt
83- ) throws Exception {
84- return parseYsToEvtBuf ("yamlscript" , src , evt );
81+ public boolean parseYsDirect (ByteBuffer src , ByteBuffer arena , IntBuffer evt ) throws Exception
82+ {
83+ return parseYsDirect ("yamlscript" , src , arena , evt );
8584 }
8685
87- public int parseYsToEvt (
88- String filename , byte [] src , int [] evts
89- ) throws Exception {
86+ public boolean parseYs (String filename , byte [] src , byte [] arena , int [] evts ) throws Exception
87+ {
9088 long t = timingStart ("ysparse" );
91- int required_size = ysparse_parse (
92- this .ysparse , filename ,
93- src , src .length , evts , evts .length );
89+ boolean fits_buffers = ysparse_parse (this .ysparse , filename ,
90+ src , src .length ,
91+ arena , arena .length ,
92+ evts , evts .length );
9493 timingStop ("ysparse" , t , src .length );
95- return required_size ;
94+ return fits_buffers ;
9695 }
9796
98- public int parseYsToEvtBuf (
99- String filename , ByteBuffer src , IntBuffer evt
100- ) throws Exception {
97+ public boolean parseYsDirect (String filename , ByteBuffer src , ByteBuffer arena , IntBuffer evt ) throws Exception {
10198 if (! src .isDirect ())
10299 throw new RuntimeException ("src must be direct" );
100+ if (! arena .isDirect ())
101+ throw new RuntimeException ("arena must be direct" );
103102 if (! evt .isDirect ())
104103 throw new RuntimeException ("evt must be direct" );
105104 // the byte order for src does not matter
@@ -108,15 +107,21 @@ public int parseYsToEvtBuf(
108107 throw new RuntimeException ("evt byte order must be native" );
109108 long t = timingStart ("ysparseBuf" );
110109 evt .position (evt .capacity ());
111- int reqsize = ysparse_parse_buf (
112- this .ysparse , filename ,
113- src , src .position (), evt , evt .capacity ());
114- if (reqsize <= evt .capacity ())
115- evt .position (reqsize );
110+ boolean fits_buffers = ysparse_parse_buf (this .ysparse , filename ,
111+ src , src .position (),
112+ arena , arena .position (),
113+ evt , evt .capacity ());
114+ if (fits_buffers )
115+ evt .position (ysparse_reqsize_evt (this .ysparse ));
116116 timingStop ("ysparseBuf" , t , src .position ());
117- return reqsize ;
117+ return fits_buffers ;
118118 }
119119
120+ /** Get the required size for the event output buffer, from the last parse call */
121+ public int reqsizeEvt () { return ysparse_reqsize_evt (this .ysparse ); }
122+ /** Get the required size for the arena buffer, from the last parse call */
123+ public int reqsizeArena () { return ysparse_reqsize_arena (this .ysparse ); }
124+
120125 public static IntBuffer mkIntBuffer (int numInts ) {
121126 ByteBuffer bb = ByteBuffer .allocateDirect (/*numBytes*/ 4 * numInts );
122127 // !!! need to explicitly set the byte order to the native order
0 commit comments