java-binary-block-parser | dynamic way to process binary data | Parser library
kandi X-RAY | java-binary-block-parser Summary
kandi X-RAY | java-binary-block-parser Summary
Java has some embedded features to parse binary data (for instance ByteBuffer), but sometime it is needed to work on bit level and describe binary structures through some DSL(domain specific language). I was impressed by the the Python Struct package package and wanted to get something like that for Java. So I developed the JBBP library.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Execute the mojo
- Read the CAP comment from the file
- Read custom text from file
- Register the source root directory
- Visits the end of the block
- Print java doc lines with an indent
- Print java comment with indent
- Visit a struct block
- Register a maker for the given fields
- Converts an array field value to its string representation
- Execute mojo
- Visits an action item
- Convert the prepared parser into source items
- Visits a VALUES field
- Read number of unsigned short items from the input stream
- Read integer items from the stream
- Registers a custom field
- Translate script file
- Visit a var field
- Evaluate the expression
- Map a parsed array to an array field
- Visit a primitive field
- Extract the error part from a script
- Map a numeric numeric field to a primitive field
- Register a bit field
- Perform normal action
java-binary-block-parser Key Features
java-binary-block-parser Examples and Code Snippets
Community Discussions
Trending Discussions on java-binary-block-parser
QUESTION
I am trying make a function in Java to splice one binary input into another using Java at the bit level as opposed to a byte level. For example splicing "00000000" into "11111111" a position 3 would produce "1110000000011111".
I have tried looking into the JBBP library for dealing with binary data but it is almost as though there is a special coding language, other than java, which seems to be specific to this library which you write then pass as a string in Java to the JBBPParser.prepare()
function. I tried looking in the java docs for the library but they only describe what the function does, not what the commands you can pass as a sting are, what those commands do, or what the proper syntax for those commands is.
Can anyone provide a link to the documentation for the commands you can pass as strings to the JBBPParser
functions or provide an alternative way to splice binary data together at an arbitrary bit without relying on binary strings and parseInt as they are inefficient?
ANSWER
Answered 2017-Aug-10 at 18:53Read about Endianness. Java is big-endian. This means that your example is wrong. Instead of inserting the zero string (00000000) after position 3 in the target byte, your example demonstrates inserting the zero string either after position 6 or before position 5 (see bit numbering below).
The operation you are looking for is called "left shift". Here is a link discussing Bitwise and Bit Shift Operators.
Here is the strategy you want to use:
- Determine how many bits to shift from the target into the destination. I will call this the
initialShiftCount
. In your example, the initialShiftCount is 3 bits. - Left shift the initialShiftCount number of bits into the destination.
- Left shift all 8 bits from the insert string into the destination.
- Left shift the remaining bits from the target into the destination.
Terms:
destination - the location into which you want to place the combination of the bits in the insert string and the target. In your example, this is the variable that ends up holding the string 1110000000011111'.
00000000
*insert string* - the bits you want to insert into the target bits. In your example, the insert string is.
11111111`.
*target* - the bits into which you want to insert the insert string. In your example, the target is
Bit Numbering In a big-endian system, the bits are numbered as follows: 87654321
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install java-binary-block-parser
You can use java-binary-block-parser like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the java-binary-block-parser component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page