Questions tagged [construct]

Construct is a powerful declarative parser for binary data.

It is based on the concept of defining data structures in a declarative manner, rather than procedural code: Simple constructs can be combined hierarchically to form increasingly complex data structures. It's the first library that makes parsing fun, instead of the usual headache it is today. Official documentation: https://construct.readthedocs.io

239 questions
41
votes
3 answers

init function for structs

I realize that Go does not have classes but pushes the idea of structs instead. Do structs have any sort of initialization function that can be called similar to a __construct() function of a class? Example: type Console struct { X int Y…
Senica Gonzalez
  • 7,996
  • 16
  • 66
  • 108
40
votes
3 answers

How to make json.dumps in Python ignore a non-serializable field

I am trying to serialize the output of parsing some binary data with the Construct2.9 library. I want to serialize the result to JSON. packet is an instance of a Construct class Container. Apparently it contains a hidden _io of type BytesIO - see…
mz8i
  • 672
  • 1
  • 7
  • 11
26
votes
4 answers

What is the rationale behind this code block in java?

What is the rationale behind making this kind of code valid in java? Does it exist for some particular reason or is it just a byproduct of other Java language design decisions? Can't you just use the consructor to achieve the same effect? class…
user529141
17
votes
4 answers

What does the Javascript expression 'a = a || function() {...}' mean?

I'm not sure what this construct means but I've seen it a few times. The example below is from another Stack Overflow question. I'm not sure how to interpret the initial "or" construct itself: Object.keys = Object.keys || (function () { var…
Vangoe
  • 181
  • 4
9
votes
2 answers

Construct JPA query for a OneToMany relation

I've those 2 entities Class A { @OneToMany(mappedBy="a") private List bs; } Class B { @ManyToOne private A a; private String name; } 1) I would like to construct a query that says get all A's that have at least one B with…
mohamede1945
  • 7,092
  • 6
  • 47
  • 61
9
votes
6 answers

Java recreate string from hashcode

Is there any way that I can use a hashcode of a string in java, and recreate that string? e.g. something like this: String myNewstring = StringUtils.createFromHashCode("Hello World".hashCode()); if (!myNewstring.equals("Hello World")) …
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
9
votes
3 answers

free(): double free detected in tcache 2 in C++

Firstly, I really checked if there is a question already been asked but I could not find any. Error message should not deceive you my situation is a bit different I guess or I am just missing something. While I was dealing with a toy C++ code I…
9
votes
0 answers

Patterns for Python object transformation (encoding, decoding, deserialization, serialization)

I've been working with the parsing module construct and have found myself really enamored with the declarative nature of it's data structures. For those of you unfamiliar with it, you can write Python code that essentially looks like what you're…
synthesizerpatel
  • 27,321
  • 5
  • 74
  • 91
6
votes
5 answers

What is this Hash-like/Tree-like Construct Called?

I want to create a "Config" class that acts somewhere between a hash and a tree. It's just for storing global values, which can have a context. Here's how I use it: Config.get("root.parent.child_b") #=> "value" Here's what the class might look…
Lance
  • 75,200
  • 93
  • 289
  • 503
5
votes
1 answer

Call function inside __construct with php

A simple PHP problem I couldn't find the answer to. Is it possible to call a function from the "__construct()"? For example if I use the My_Controller solution here. If I add my own function below, like if I have a more advanced auth, can I call it…
Vejto
  • 1,264
  • 1
  • 10
  • 17
5
votes
7 answers

PHP: using $this in constructor

I have an idea of using this syntax in php. It illustrates that there are different fallback ways to create an object function __construct() { if(some_case()) $this = method1(); else $this = method2(); } Is this a nightmare? Or…
Dan
  • 55,715
  • 40
  • 116
  • 154
4
votes
2 answers

Construct parsing for unaligned int field?

I am using this nice little package "construct" for binary data parsing. However, I ran into a case where the format is defined as: 31 24 23 0 +-------------------------+ | status | an int number…
Oliver
  • 3,592
  • 8
  • 34
  • 37
4
votes
3 answers

How to implement Haskell *Maybe* construct in D?

I want to implement Maybe from Haskell in D, just for the hell of it. This is what I've got so far, but it's not that great. Any ideas how to improve it? class Maybe(a = int){ } //problem 1: works only with ints class Just(alias a) :…
Arlen
  • 6,641
  • 4
  • 29
  • 61
4
votes
3 answers

When is it more appropriate to assign a new list than to .Clear() an existing list?

Given a list: List myList = new List(); with the collection contents modified at runtime.... To clear the list, I have seem examples which suggest using myList = new List(); rather than myList.Clear(); I can think of a…
Matthew
  • 10,244
  • 5
  • 49
  • 104
4
votes
1 answer

Python's construct - .sizeof() for construct depending on its parent

This post is about Python's Construct library THE CODE These are the definitions of my constructs: from construct import * AttributeHandleValuePair = "attribute_handle_value_pair" / Struct( "handle" / Int16ul, "value" / Bytes(this._.length…
Dan Shemesh
  • 464
  • 3
  • 13
1
2 3
15 16