An alternative encoding/decoding scheme for IOTA trytes supporting UTF-8 and JSON
This package is available here https://www.npmjs.com/package/tryte-utf8-json-codec
And can be installed with this command
npm install tryte-utf8-json-codec
An alternative encoding/decoding scheme for IOTA trytes supporting UTF-8 and JSON
License: MIT License
An alternative encoding/decoding scheme for IOTA trytes supporting UTF-8 and JSON
This package is available here https://www.npmjs.com/package/tryte-utf8-json-codec
And can be installed with this command
npm install tryte-utf8-json-codec
🚨 You need to enable Continuous Integration on all branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.
Since we didn’t receive a CI status on the greenkeeper/initial
branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/
.
Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial
branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.
Hi:
It's good job for support utf-8 message in OPEN IOTA.(Better then thetangle.org haha^^)
I'm a java programer.
So try to create a java version.
Share here maybe someone need it.
/**ref>>https://github.com/pRizz/Tryte-UTF8-JSON-Codec
* for encode/decode utf-8 message in IOTA Tangle.
* @author Nick/[email protected]
*
*/
public class JavaTryteUTF8JSONCodec {
public static int[] byteToTryteArray= {65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80}; // A...P
public static String trytesFromUTF8String(String inputString) {
StringBuffer tryteBuffer = new StringBuffer();
for(byte aByte:inputString.getBytes()) {
tryteBuffer.append((char)byteToTryteArray[(aByte & 0xF0) >>> 4]);//hex
tryteBuffer.append((char)byteToTryteArray[aByte & 0x0F]);
}
return tryteBuffer.toString();
}
public static String stringFromTrytes(String inputTrytes) throws Exception {
if(inputTrytes==null) { throw new Exception("Invalid input");}
if(inputTrytes.length() <= 0) {
throw new Exception("Invalid trytes length. Should be > 0.");
}
if(inputTrytes.length() % 2 != 0) {
inputTrytes = inputTrytes.substring(0, inputTrytes.length()-1); // truncate last tryte
}
byte[] bytes=new byte[inputTrytes.length()/2];
for (int i = 0; i < inputTrytes.length(); i += 2) {
int hiTryte = inputTrytes.charAt(i);
if((i+1)>=inputTrytes.length())break;
int loTryte = inputTrytes.charAt(i + 1);
int hiIndex=getIndexOfByteToTryteArray(hiTryte);
int loIndex=getIndexOfByteToTryteArray(loTryte);
int ascii=hiIndex*16+loIndex;
bytes[i/2]=(byte)((char)ascii);
}
return new String(bytes,"UTF-8");
}
public static int getIndexOfByteToTryteArray(int tryte) {
for(int i=0;i<byteToTryteArray.length;i++) {
if(tryte==byteToTryteArray[i])return i;
}
return -1;
}
public static void main(String[] args) throws Exception {
//json test
String json="{\"app\":\"Chatangle\",\"apiVersion\":1,\"payload\":{\"name\":\"安安\",\"message\":\"測試\"}}";
String trytes=trytesFromUTF8String(json);
System.out.println(trytes);
String jsonString=stringFromTrytes(trytes);
System.out.println(jsonString);
//text test
String trytesString=trytesFromUTF8String("Taiwan台灣 no.1");
System.out.println(trytesString);
String stringString=stringFromTrytes(trytesString);
System.out.println(stringString);
}
}
🚨 You need to enable Continuous Integration on all branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.
Since we didn’t receive a CI status on the greenkeeper/initial
branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/
.
Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial
branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.