Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created two cmd line utilities for converting between hex and json #16

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ericpassmore
Copy link

Created two command line programs

  • generate_hex_from_json - creates hex given an ABI and JSON
  • generate_json_from_hex - creates json when provided an ABI and hex encoding

Used this for generating test data for eosjs

@ericpassmore ericpassmore self-assigned this Jan 21, 2023
@heifner
Copy link
Member

heifner commented Jan 21, 2023

I think something more like EOSIO/abieos#60 where the abi is provided as an abi file would be better.

@ericpassmore
Copy link
Author

I think something more like EOSIO/abieos#60 where the abi is provided as an abi file would be better.

Good example, I can switch to a file to ABI, and I move the executables to tools directory.

Ok to use c++ to read the file? Specifically using std::filesystem::file_size for the file size, preallocating a byte vector, std::ifstream::read to populate the vector, then converting to string? The C-style malloc/free isn't my favorite.

@heifner
Copy link
Member

heifner commented Jan 23, 2023

I think same location of executes as name is good.
Yes, please use C++ instead of C constructs for this including cout/cerr over fprintf.

@spoonincode
Copy link
Member

fwiw a small, simple, but inefficient way I've used to read in a small file to a string is something like

   std::string filename = "foo.file";
   std::ifstream ifs(filename);
   std::string string_of_file_contents((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());

(inefficiency doesn't really matter for simple stuff like this)

@ericpassmore
Copy link
Author

I think same location of executes as name is good. Yes, please use C++ instead of C constructs for this including cout/cerr over fprintf.

Got it, I will C++'ify the code. Thanks for the simple approach to reading a small file. I'll take it.

tools/test_utils.sh Outdated Show resolved Hide resolved
tools/util_generate_hex_from_json.cpp Outdated Show resolved Hide resolved
tools/CMakeLists.txt Outdated Show resolved Hide resolved
tools/util_generate_hex_from_json.cpp Outdated Show resolved Hide resolved
tools/util_generate_hex_from_json.cpp Outdated Show resolved Hide resolved
tools/util_generate_hex_from_json.cpp Outdated Show resolved Hide resolved
tools/util_generate_json_from_hex.cpp Show resolved Hide resolved

// prints usage
void help(const char* exec_name) {
std::cerr << "Usage " << exec_name << ": -f -j JSON -x type [-v]";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a missing \n on this line, which mangles the formatting of help output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants