Comments (3)
I am not sure that correctly understand the problem
for example the code below reads 4 byte blocks from array and extract 15 bit from some of them and 7 bit from another
JBBPParser parser7bit = JBBPParser.prepare("bit:7 first;");
JBBPParser parser15bit = JBBPParser.prepare("byte first; bit:7 second;");
final byte [] testArray = new byte[1024];
new Random(1234).nextBytes(testArray);
final JBBPBitInputStream stream = new JBBPBitInputStream(new ByteArrayInputStream(testArray));
final byte [] buffer = new byte[4];
boolean parseAs7bit = true;
while(stream.hasAvailableData()){
stream.read(buffer);
if (parseAs7bit) {
final int value = parser7bit.parse(buffer).findFieldForType(JBBPFieldBit.class).getAsInt();
System.out.println("Value 7 bit : "+value);
} else {
final JBBPFieldStruct parsed = parser15bit.parse(buffer);
final int first = parsed.findFieldForPathAndType("first", JBBPFieldByte.class).getAsInt() & 0xFF;
final int second = parsed.findFieldForPathAndType("second", JBBPFieldBit.class).getAsInt();
System.out.println("Value 15 bit : "+((first<<7)|(second)));
}
parseAs7bit = !parseAs7bit;
}
from java-binary-block-parser.
Thanks for the code. I definitely understand a lot better what and how to accomplish my goal. Have one more question.
In the following code that you placed above:
JBBPParser parser15bit = JBBPParser.prepare("byte first; bit:7 second;");
This makes sense as 15bits. Meaning, prepare to parse the first byte (8-bits) + the second 7-bits.
But, what if I wanted to parse the first 17bits and then the following 15bits. How do I say a range of bytes/bits, etc...? For example I would like to prepare to parse bytes 1 - 9 and bits 1 -4 from byte 10 together. Hopefully this makes sense.
I guess what I am asking is this, what arguments are being passed in this case ("byte first; bit:7 second;") and what do they do? I would imagine that this single string would be split on the ";" character. Then, they would be used to do something. I just kind find for what or identify the acceptable values. Having this information would be helpful.
Thanks, this library is very helpful.
Wyatt
from java-binary-block-parser.
java represents all streams as sequence of bytes and JBBP just load next byte into inside buffer and reads neede number of bits and LSB or MSB mode can be defined among JBBPInputStream parameters
in case "byte first; bit:7 second;" as the first one 8 bits will be read from stream and then 7 bits
sometime there can be very strange bit structures which can't be processed by JBBP out of the box, such structures should be processed manually with new custom data type
from java-binary-block-parser.
Related Issues (20)
- NullPointerException when using new JBBPDslBuilder HOT 5
- "Expression is empty" error when using arrays HOT 8
- PatternSyntaxException when use on Android. HOT 2
- support multiple custom type processors? HOT 1
- Illegal reflective access reported when used with JDK 11 HOT 2
- Bug in parsing of stringj written in MSB0 HOT 5
- Strings in other codecs HOT 3
- JBBPByteOrder may add nativeOrder and inheritOrder HOT 3
- Processing Nullable fields exceptions HOT 8
- Issue with simple object parse HOT 2
- how to set JBBPByteOrder for JBBPParser ? HOT 3
- How to read/parse stringj when here is no '3' mark? HOT 3
- parse dns query data packge
- Filter fields for JBBPOut HOT 3
- Could you please add unsigned int32 support? HOT 4
- Error running gradle plugin task jbbpGenerate in gradle 7.4.2 HOT 3
- Really great project!
- Gradle plugin error: Cannot add extension with name 'jbbp', as there is an extension already registered with that name HOT 5
- Use child class for parsing will throw java.lang.IllegalStateException: There is not any opened struct HOT 4
- Unpack float with endian HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-binary-block-parser.