How to build string for ethercard webpage, arduino - string

How do i build a suitable string from an array of data values, that the ethercard library will accept to serve as a webpage? From the examples i have the below thus far, but i want to use an variable number of array elements (up to the limit of the packet buffer size).
static word homePage() {
bfill= ether.tcpOffset();
bfill.emit_p(PSTR(
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/plain\r\n"
"Pragma: no-cache\r\n"
"\r\n"
"$D\n"
"$D\n"
"$D\n"
"$D\n"
),
data[0],data[1],data[2],data[3]
);
return bfill.position();
}
void loop() {
if (ether.packetLoop(ether.packetReceive())) {
ether.httpServerReply(homePage());
}
}
I guess a side question is where do i learn about c strings, duh. (php guy).

static char strbuf[STR_BUFFER_SIZE+1];
bfill.emit_raw(strbuf, strlen(strbuf));

Related

How to get TransactionUnspentOutput as a hex encoded bytes string programmatically

So basically I want to convert a normal UTxO hash like:
550665309dee7e2f64d13f999297f001763f65fe50bb05524afc0990c7dce0c3
to a TransactionUnspentOutput as a hex encoded bytes string like:
828258205537396d59c1b0546bb9cec5cb6b930238af2d8998d24ca1d47e89a3dd400a8701825839016af9a0d2c9b5bce8999bc6430eb48f424399b73f0ecc143f40e8cac89b130cc3198a8594862fe25df331cb79447304dcd49712c86834fdf1821a00150bd0a1581cb0df0ee7dbb96b18b682a1091514f250eb0ec1122e6c4bf3b4d45123a14b436f6e766963743033363701
This is how it is done with a nami wallet implementation:
cardano.getUtxos(amount?: Value, paginate?: {page: number, limit: number}) : [TransactionUnspentOutput]
I tried to pass a UTxO into the lucid utxoToCore() function:
export const utxoToCore = (utxo: UTxO): Core.TransactionUnspentOutput => {
const output = C.TransactionOutput.new(
C.Address.from_bech32(utxo.address),
assetsToValue(utxo.assets)
);
if (utxo.datumHash) {
output.set_datum(
C.Datum.new_data_hash(C.DataHash.from_bytes(fromHex(utxo.datumHash)))
);
}
return C.TransactionUnspentOutput.new(
C.TransactionInput.new(
C.TransactionHash.from_bytes(fromHex(utxo.txHash)),
C.BigNum.from_str(utxo.outputIndex.toString())
),
output
);
};
However the only output I get is:
TransactionUnspentOutput { ptr: 1247376 }
How to get the unpacked (?), or at least the right format I want, TransactionUnspentOutput?
It looks like you are trying to call an external library. Usually, in such cases, it will return you a memory address. Just like you have it in wasm calls through browser client. One way is to deserialize your object inside your node js code.
Maybe you can use some sorta utility function to get it as a string.
E.g. https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/metadata.md#json-conversion
Hope this helps

laravel excel export relation columns give array and arabic words is become like \u0633\u0627\u0645\u0633\u0648\u0646\u062c how to solve it

Laravel Excel export relation columns give array and Arabic words is become like \u0633\u0627\u0645\u0633\u0648\u0646\u062c how to solve it ? I tried to use json_encode($subcategory->name, JSON_UNESCAPED_UNICODE) and it is not working also and give same results. Does anyone have some suggestions to solve this?
Export file
class CategoriesExport implements FromQuery, WithMapping, WithHeadings
{
use Exportable;
protected $checked;
public function __construct($checked)
{
$this->checked = $checked;
}
public function map($category): array
{
return [
$category->id,
$category->name,
$category->status == 1 ? trans('applang.active') : trans('applang.suspended'),
$category->section->name,
$category->brands->map(function ($brand){ return $brand->name; }),
$category->subCategories->map(function ($subcategory){ return $subcategory->name; })
];
}
public function headings(): array
{
return [
'#ID',
trans('applang.the_category'),
trans('applang.status'),
trans('applang.the_section'),
trans('applang.the_brand'),
trans('applang.sub_cat'),
];
}
public function query()
{
return Category::with(['section', 'brands', 'subCategories', 'products'])->whereIn('id', $this->checked);
}
}
In your config/excel.php change the use_bom config to true and try with that.
from What's the difference between UTF-8 and UTF-8 without BOM?
The UTF-8 BOM is a sequence of bytes at the start of a text stream
(0xEF, 0xBB, 0xBF) that allows the reader to more reliably guess a
file as being encoded in UTF-8.

how to get null space in unitywebrequest and base64type

private IEnumerator GetData()
{
WWWForm form = new WWWForm();//php에 보낼 폼을 만듦
form.AddField("data", num);
UnityWebRequest request = new UnityWebRequest();
using (request =
UnityWebRequest.Post("http://localhost/LoadData.php", form))
{
yield return request.SendWebRequest();
if (request.isNetworkError)
{
Debug.Log(request.error);
}
else
{
Debug.Log(request.downloadHandler.text.Length);
Debug.Log(request.downloadHandler.text[request.downloadHandler.text.Length - 1]);
Debug.Log(request.downloadHandler.text[request.downloadHandler.text.Length - 2]);
Debug.Log(request.downloadHandler.text[request.downloadHandler.text.Length - 3]);
string str=request.downloadHandler.text;
str = str.Substring(0, str.Length - 2);
Debug.Log(str[str.Length - 1]);
results = request.downloadHandler.data;
byte[] by = Convert.FromBase64String(request.downloadHandler.text);
Debug.Log(by.Length);
Mesh mesh = MeshSerializer.ReadMesh(by);
transform.GetComponent<MeshFilter>().mesh = mesh;
}
}
I am sending a byte[] as a unity web request, but when sending and receiving, a space is added at the end. so at the beginning, I calculated this space, but it seems to be different for each character length.
The base64 type seems to end with == but I don't know if this is correct
If you use Unity Web Request, can you tell how many null are added?
Or is there a standard for how many null are there?
---added
After sending to Unity Web Request, Post-> Download, the length of the string increased by 2, so at the beginning, only 2 deleted.
As I keep using this method, I don't know what to do because each object has a different null length.
Is it correct to find and compare only the last blank column?
ZWSP: zero width space
https://en.wikipedia.org/wiki/Zero-width_space
ZWSP is created if it is not received in an unusual way.
but don't know that it was data end space add ZWSP

Deserialize json one record at a time

I am working with large json files and memory is a concern. I would like to read one object into memory at a time from file. Is this possible?
In ServiceStack.Text docs it says there is an API using reader/stream
But I can't see how to get that working. The files are too large to deserialize in one go. Is it possible to handle this scenario with SS?
Thanks
No you'll want to use a streaming JSON parser like System.Text.Json Utf8JsonReader, this is the example on System.Text.Json introductory page:
byte[] data = Encoding.UTF8.GetBytes(json);
Utf8JsonReader reader = new Utf8JsonReader(data, isFinalBlock: true, state: default);
while (reader.Read())
{
Console.Write(reader.TokenType);
switch (reader.TokenType)
{
case JsonTokenType.PropertyName:
case JsonTokenType.String:
{
string text = reader.GetString();
Console.Write(" ");
Console.Write(text);
break;
}
case JsonTokenType.Number:
{
int value = reader.GetInt32();
Console.Write(" ");
Console.Write(value);
break;
}
// Other token types elided for brevity
}
Console.WriteLine();
}

Difference between encodeBase64URLSafeString and encodeBase64URLSafe

I was wondering what the actual difference is between the following two functions :
encodeBase64URLSafeString
encodeBase64URLSafe
The apache documentation says the difference is that encodeBase64URLSafe does not chunk the output while encodeBase64URLSafeString does ! but what does that mean ?
Chunking is just adding a new-line after every ~74 characters (so it's acceptable for email)
The return type differs:
public static byte[] [More ...] encodeBase64URLSafe(byte[] binaryData) {
return encodeBase64(binaryData, false, true);
}
public static String [More ...] encodeBase64URLSafeString(byte[] binaryData) {
return StringUtils.newStringUtf8(encodeBase64(binaryData, false, true));
}
Did you mean what is the difference between chunked and non-chunked, your question is not very clear...

Resources